Is this code for fft correct

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 个评论

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.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by