errors appear when doing FFT on data imported from text file

조회 수: 5 (최근 30일)
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?

채택된 답변

Wayne King
Wayne King 2012년 10월 24일
편집: Wayne King 2012년 10월 24일
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
modified covariance
modified covariance 2012년 10월 24일
편집: modified covariance 2012년 10월 24일
thx again for ur response. let me change fs to 1 now.
sorry to bother you again. how to make the adjustment since my signal lenght is odd.

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

추가 답변 (1개)

Wayne King
Wayne King 2012년 10월 24일
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
modified covariance
modified covariance 2012년 10월 24일
편집: modified covariance 2012년 10월 24일
thanks for ur help to tell the problem lis in Fs. the spot_num.txt file contains the data as follows with thrid column extracted onto matlab.
thrid column is SSN/monthly averages. i guess Fs is therefore 1/(24*31*60*60)??

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

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by