Obtaining result in Frequency Domain using FFT in Matlab
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Rehan Rehan
el 5 de Mayo de 2016
Comentada: Star Strider
el 5 de Mayo de 2016
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 comentarios
Respuesta aceptada
Star Strider
el 5 de Mayo de 2016
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 comentarios
Star Strider
el 5 de Mayo de 2016
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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!