Fast Fourier Transform with discrete data
49 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
HyunDong Lee
il 20 Mag 2020
Commentato: Star Strider
il 22 Mag 2020
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
x=sin(2*pi*40*t)+sin(2*pi*80*t);
X=fft(x);
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]
y=data;
x=fft(y);
X=abs(x);
plot(X);
0 Commenti
Risposta accettata
Star Strider
il 20 Mag 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
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
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 Commenti
Star Strider
il 22 Mag 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!
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spectral Measurements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!