Performing Fourier Transform with csv file; "error using csvread"

조회 수: 4 (최근 30일)
Snow
Snow 2023년 6월 27일
답변: Rahul 2023년 6월 27일
I am trying to find the wavelength of a laser. The data I have is the time and the voltage. I have a 33607 x 2 matrix as I recorded the data using 1kHz. My lab manual states:
"Your goal is to find the frequency induced by the mirror’s movement, which will tell you time between peaks and therefore the light wavelength. The vibrations physically must be oscillatory – they can’t produce a net shift over long periods of time. Therefore they can be avoided in the analysis by averaging them out, which decreases the error in frequency linearly. The 1st way to do this is simply count the peaks (or zero crossings) and average that over the time. The 2nd way (more accurate and can be faster) is to take the real discrete fourier transform (FFT) of the signal, cut off the spurious high frequencies (these come from the detector, not the system) and calculate the weighted average over the remaining frequencies"
So I am attempting to perform a FFT on the data using matlab.
I imported the data through a csv file. But when I type : t = csvread('filename.csv'), matlab says " error using csvread, file not found".
I followed the steps to this video https://www.youtube.com/watch?v=cw9eoSzln_k&ab_channel=Study%26Tutor as well the following code taken from another post :
data = csvread('myfile.csv') ; % also have a look on readtable, xlsread
a = data(:,1) ; % acceleration
f = data(:,2) ; % frequency
t = ifft(f) ;
But am still getting the same error.
Any idea why I am getting this error?
  댓글 수: 1
Kautuk Raj
Kautuk Raj 2023년 6월 27일
If the file is located in a different folder than the one you are currently working in, you can change the current working directory in MATLAB to the folder where the file is located.

댓글을 달려면 로그인하십시오.

채택된 답변

Rahul
Rahul 2023년 6월 27일
Hey Snow,
It seems like the currently open folder in your Matlab session is not the one containing the file that you're trying to read, try changing the your currently open folder by browsing to the correct one by either typing the folder path onto the path directory or using the right-most (green-arrow) button on the Current Folder Toolstrip on the left side of your matlab session.
Hope that helped!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by