Matlab Fast Fourier Transform / fft for time and speed

后端 未结 2 2044
失恋的感觉
失恋的感觉 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:31

    I would recommend that you back up and think about what you are trying to accomplish, and whether an FFT is an appropriate tool for your situation. You say that you "want to ... get a frequency", but what exactly do you mean by that? Do you know that this data has exactly one frequency component, and want to know what the frequency is? Do you want to know both the frequency and phase of the component? Do you just want to get a rough idea of how many discrete frequency components are present? Are you interested in the spectrum of the noise in your measurement? There are many questions you can ask about "frequencies" in a data set, and whether or not an FFT and/or power spectrum is the best approach to getting an answer depends on the question.

    In a comment above you asked "Is there some way to correlate the power spectrum to the time values?" This strikes me as a confused question, but also makes me think that maybe the question you are really trying to answer is "I have a signal whose frequency varies with time, and I want to get an estimate of the frequency vs time". I'm sure I've seen a question along those lines within the past few months here on SO, so I would search for that.

    0 讨论(0)
  • 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))
    
    0 讨论(0)
提交回复
热议问题