errors appear when doing FFT on data imported from text file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
trying to determine the frequency estimate after doing FFT on data imported from a text file.
load spot_num.txt
ssn = spot_num(:,3);
ssn = ssn-mean(ssn);
x=ssn;
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
freq = 0:Fs/length(x):Fs/2;
[maxval,idx] = max(abs(xdft));
freq(idx)
it returns:
Error in ==> Untitled3 at 7
freq = 0:Fs/length(x):Fs/2;
so whats wrong with that?
0 Kommentare
Akzeptierte Antwort
Wayne King
am 24 Okt. 2012
Bearbeitet: Wayne King
am 24 Okt. 2012
Your sampling interval is 1 month, so your DFT bins will be in cycles/month. So you can just set Fs = 1, but then keep in mind that the frequencies will be in cycles per month, so your highest frequency of 1/2 is 1 cycle/2 months.
Also, the code I had given you earlier was assuming you have an even number of samples. If your signal length is odd, you have to make a small adjustment.
Fs = 1;
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
freq = 0:Fs/length(x):Fs/2;
[maxval,idx] = max(abs(xdft));
freq(idx)
1 Kommentar
Weitere Antworten (1)
Wayne King
am 24 Okt. 2012
What error message does it produce?
What is the value of Fs? Nothing in the code you've shown us gives us the value of Fs.
Fs should be the reciprocal of the time interval between each sample in spot_num
1 Kommentar
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!