Monday, May 13, 2019

matlab - system response: time vs frequency. Why do I get different magnitudes?



I am simulating a linear system described by the following equation


$m \ddot{x} + c \dot{x} + k x = A \sin(\omega t)$


Fs = 1000;      % sampling frequency
tspan = 0:1/Fs:10;
m = 25;
c = 15;
k = 330000;
A = 100; % forcing amplitude
omega = 114.89; % forcing frequency


% State space function
odefun = @(t,u)[u(2); 1/m*(-k*u(1)-c*u(2)+A*sin(omega*t))];

[time,u] = ode45(odefun,tspan,[0 0]);

spost = u(:,1); % displacement
vel = u(:,2); % velocity

Then I compute the FFT of the displacement:


L = length(spost);

NFFT = 2^nextpow2(L);
SPOST = fft(spost,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

And this is what I get:




As you can see the maximum value of the displacement is different in the 2 cases, but this does not look right to me. In fact, if I run a structural analysis in the time or in the frequency domain I would expect to obtain the same maximum displacement (since the excitation frequency is equal to the resonance frequency).


How can this be explained?


EDIT



I forgot to say I tried also increasing the simulation time, but still the 2 values do not match



Answer



What you are trying to do is to compare the amplitude of your signal with an amplitude of FFT peak, expecting it is the same. The thing is that amplitude of your signal is varying and FFT is taking the "average" over whole duration.


In such case you should use time-frequency representation of your signal, such us spectrogram. It will allow you to observe how amplitude of particular frequency is changing over time. Since you work in MATLAB you can try following code:


win = hamming(256)
noverlap = 0
nfft = 512
X = abs(spectrogram(spost, win, noverlap, nfft))
% Scale by window and multiply by 2 to restore energy from negative freqs
X = 2*X/sum(win)

surf(X)

It will produce something like: enter image description here


The maximum value of displacement is around $0.053$. Results can be tweaked even further by tweaking even more and using other methods.


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...