Obtaining result in Frequency Domain using FFT in Matlab
1 次查看(过去 30 天)
显示 更早的评论
Attached here are the two vectors: Time and Displacement
Vector displ.mat is the displacement vector obtained after running a dynamic response analysis under a load.
I want to obtain the fundamental frequency which can be easily picked up by plotting the two vectors using `plot(Time,displ)`. In this plot, one can easily see a sine wave with a frequency of roughly 0.5 Hz. So, I expect to see this peak of 0.5 Hz using `fft` function of Matlab.
I am using the following code and but not getting the expected peak at 0.5 Hz:
load Time.mat
load displ.mat
t = Time;
Fs = 149;
x = displ;
x = detrend(x,0);
xdft = fft(x);
freq = 0:Fs/length(x):Fs/2;
xdft = xdft(1:length(x)/2+1);
plot(freq,abs(xdft));
[~,I] = max(abs(xdft));
fprintf('Maximum occurs at %d Hz.\n',freq(I));
plot(Time,displ)
0 个评论
采纳的回答
Star Strider
2016-5-5
Here you go:
T = load('Rehan Rehan Time.mat');
D = load('Rehan Rehan displ.mat');
t = T.Time;
d = D.displ;
L = length(t); % Signal Length (samples)
Ts = mean(diff(t)); % Sampling Interval (seconde)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
dm = d-mean(d);
ft_d = fft(dm)/L; % Normalised Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
[pks,idx] = findpeaks(abs(ft_d(Iv))*2);
lbl = sprintf('Frequency = %.3f\nAmplitude = %.3f', Fv(idx), pks);
figure(1)
plot(Fv, abs(ft_d(Iv))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude (m)')
text(Fv(idx)+0.1, pks, lbl, 'HorizontalAlignment','left', 'VerticalAlignment','top')
2 个评论
Star Strider
2016-5-5
My pleasure!
The findpeaks function is in the Signal Processing Toolbox. Since you have only one peak, you can get the same result with the max function (I verified that the results are the same):
[pks,idx] = max(abs(ft_d(Iv))*2);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!