Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
982 views
in Technique[技术] by (71.8m points)

arrays - Matlab Fast Fourier Transform / fft for time and speed

I have a 2 column vector with times and speeds of a subset of data, like so:

5 40
10 37
15 34
20 39

And so on. I want to get the fourier transform of speeds to get a frequency. How would I go about doing this with a fast fourier transform (fft)?

If my vector name is sampleData, I have tried

fft(sampleData);

but that gives me a vector of real and imaginary numbers. To be able to get sensible data to plot, how would I go about doing this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Fourier Transform will yield a complex vector, when you fft you get a vector of frequencies, each has a spectral phase. These phases can be extremely important! (they contain most of the information of the time-domain signal, you won't see interference effects without them etc...). If you want to plot the power spectrum, you can

plot(abs(fft(sampleData)));

To complete the story, you'll probably need to fftshift, and also produce a frequency vector. Here's a more elaborate code:

% Assuming 'time' is the 1st col, and 'sampleData' is the 2nd col: 
N=length(sampleData);  
f=window(@hamming,N)';
dt=mean(diff(time)); 
df=1/(N*dt); % the frequency resolution (df=1/max_T)
if mod(N,2)==0
    f_vec= df*((1:N)-1-N/2); % frequency vector for EVEN length vector
    else
    f_vec= df*((1:N)-0.5-N/2); 
end

fft_data= fftshift(fft(fftshift(sampleData.*f))) ;

plot(f_vec,abs(fft_data))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...