Matlab Fast Fourier Transform / fft for time and speed

后端 未结 2 2055
失恋的感觉
失恋的感觉 2020-12-20 09:12

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 tr

2条回答
  •  执笔经年
    2020-12-20 09:42

    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))
    

提交回复
热议问题