Is this code for fft correct
Show older comments
I have the following code for FFT. But I can't tell if its correct or not. Is the code correct?
%: Read the excel file using readtable function
rawTable = readtable('DS0009A.CSV','PreserveVariableNames',true);
X=rawTable{:,1};
Y=rawTable{:,2};
figure
plot(X,Y)
Fs=1000;
y= rawTable{:,2};
F=fft(y);
l=length(y);
p2=abs(F/l);
p1 = p2(1:l/2+1);
p1(2:end-1) = 2*p1(2:end-1);
f = Fs*(0:(l/2))/l;
figure
plot(f,p1)
xlim([0 5])
1 Comment
Jon
on 9 Aug 2023
You will need to attach your data file if you want someone to be able to try running your code.
There are very complete examples for using fft in the MATLAB documentation, type doc fft on your command line or Google matlab fft
If you are not confident using the fft, I suggest making a signal where you know what the expected results are. For example make a signal that is a sum of a few sin waves at different frequencies and amplitudes, and then try fft on that signal.
Answers (0)
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!