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 Commento

Jon
Jon il 9 Ago 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Fourier Analysis and Filtering in Centro assistenza e File Exchange

Tag

Richiesto:

il 9 Ago 2023

Commentato:

Jon
il 9 Ago 2023

Community Treasure Hunt

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

Start Hunting!

Translated by