MATLAB Answers

Fast Fourier Transform with discrete data

조회 수: 4(최근 30일)
i measured vibration with oscilloscope and get 1000 points of (time, voltage)
i have seen many example with input function x is known like below 2 sentence
but in case of me, i have discrete data and cannot find example
how can i build the code?
i have tried like below 4 sentence but i cannot make it
[data 1000x2 double]

  댓글 수: 0

Sign in to comment.

채택된 답변

Star Strider
Star Strider 20 May 2020
I suspect the first column of ‘data’ is a time vector and the second column is the signal vector.
If that is correct, try this:
t = data(:,1); % Time Vector
s = data(:,2); % Signal Vector
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(t); % Signal Length (Number Of Samples)
FTs = fft(s - mean(s))/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
plot(Fv, abs(FTs(Iv))*2)
This calculates the Fourier transform, and displays a one-sided Fourier transform (0 Hz to the Nyquist frequency).
This code subtracts the mean of ‘s’ from ‘s’ to remove a constant (d-c) offset (that could obscure other peaks), before taking the Fourier transform.
The sampling interval must be constant, or this code will not give correct results. You can determine that by taking the standard deviation of the time intervals:
Ts_sd = std(mean(diff(t)));
It should be close to 0 (usually less than 1E-12).

  댓글 수: 2

HyunDong Lee
HyunDong Lee 22 May 2020
im so happy that your code works
but i have questions
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
we already use the function 'fix(L/2)', why +1 is added?
plot(Fv, abs(FTs(Iv))*2)
why *2 on abs() value? what does it means?
Star Strider
Star Strider 22 May 2020
1. The ‘1’ is added because the vector begins at 0 and adding the ‘1’ will then include the Nyquist frequency, with the correct number of elements.
2. The fft function returns a vector equal to the size of the input vector, with half of the symmetric Fourier transform vector being the complex conjugate of the other half. (This can be seen most easily after using the fftshift function.) The result is that the signal energy is divided equally between the ‘positive’ and ‘negative’ frequencies. Multiplying by 2 approximately restores the original amplitudes of the signal peaks in a plot of only the ‘positive’ half frequencies in a one-sided Fourier transform, as is done here.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

추가 답변(0개)


Translated by