How to get the input unit back with the spectrogram function

4 vues (au cours des 30 derniers jours)
Tanguy Cléton
Tanguy Cléton le 11 Mai 2021
Commenté : Tanguy Cléton le 11 Mai 2021
Hello,
I have a signal (acceleration) in witch I want to know how much of a certain frequency is excited. For that I use spectrogram and I want to extract, at a point in time and frequency, the level of excitation in acceleration unit.
If I take sig as a signal then abs( fft(sig) )*2/window gives me the rigth amplitude (window is the size of the window). I tested it with sig = 300*cos(2*pi*f*t) and it indeed gave me 300 at the frequency f. So it works fine with fft.
But when I use it on the 's' output of spectrogram it dont give me that at all.
Any ideas to recover my acceleration unit from the spectrogram ?
Thx
  2 commentaires
Mathieu NOE
Mathieu NOE le 11 Mai 2021
hello
sometimes it's not so easy to understand how things are scaled inside matlab's functions
that's why I ended up rebuilding the spectrogram with fft so I know the amplitude of the spectrum matches the input signal
FYI I use hanning window and the corresponding corrrection factor
Tanguy Cléton
Tanguy Cléton le 11 Mai 2021
Thanks,
I did end up to start my own spectrogram function but my knowledge wasn't deep enougth in signal analysis.
I also tried the formula : A = abs(s)*4/window and it gave me a relative error of about -17% (for my set of widow, noverlap etc and for any amplitude) that I could correct afterward.
It is actually working so I'll stick with that but I do know the interest of writing a new spectrograam function on witch one can know any unit changes.
I explain here what I did in case someone read it later :
first I noticed that A = abs(s)*4/window is relatively close to the right value but an error still exist.
Then I wrote a piece of code that calulate the relative error of the estimated amplitude :
L = 1:10:1000;
j=0;
for k = L
j=j+1;
signal = k*cos(2*pi*BF(1)*t_1);
spec = spectrogram(signal,blackman(window),Overlap,BF,fs,'yaxis');
Amp = max(max(abs(spec)))*4/window;
err_rel(j) = (Amp-k)/k;
end
err = mean(err_rel);
IMPORTANT : You must put the axact same intputs than the spectrogram on witch you want to extract the value bc the relative error actually depend on all of that.
I took t_1 as the same time vector of my original signal.
Finally I can correct my values using this formula : A = abs(s)*4/window/(error+1) ;
If I plot the relative error against the amplitude I get about -17% (with my sittings) but with this correction I get a relative error of about 10^-14%.
We can see that the relative error is not dependent on the amplitude so taking the mean is not a problem and we don't have to put I=1:10:1000 bc the first values are already acurate.
Good luck !

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur AI for Signals dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by