why my dB plot doesn't seem right?
Mostrar comentarios más antiguos
Dear, I have a very simple signal, now I want to plot it. It seems all make sense when I plot it use linear scale. But I got very strange plot when I plot in log scale. code below:
%% test data
fs = 1000;
t = 0:1/fs:5-1/fs;
x = cos(2*pi*50*t)+cos(2*pi*100*t);
%plot(t,x)
%plotChannelSpectral(x);
[psd,f] = pwelch(x,500,200,500,1000);
plot(f,(psd)); % this one makes sense
figure;
plot(f,10*log10(psd)); %this just doesn't make sense

Should it be strght line?
And I don't know when should I use log scale and when should I use linear. For this instance, linear is very good, but log is not.
Thanks in advance.
5 comentarios
Mathieu NOE
el 24 de Nov. de 2020
hello
in theory, the sinus would be displayed as vertical lines in frequency domain
but numerical fft will introduce several leakages :
1/ for continuous signals, the fourier transform impose to apply a window to each buffer so that the signal start and stops with zero amplitude . This window will generate "side lobes" efffects in the frequency plot , so what you see in your graph is that side lobe effect on the vertical lines.
There are many type of windows depending of what precision you need on amplitude and frequency resolution / selectivity (minimization of the side lobe). it's all about trade offs.
2/ the f (frequency) vector is discrete , not continuous. As the frequency of your input signal will probably never match exactly the (nearest) frequency bin of the f vector. To reduce that , reduce the frequency resolution => you should increase the length of the fft buffer; but at the best you can only do one fft computation with a buffer (= nfft length) equal to the entire signal length. We we split a longer signal in smaller buffers and do averaging, it will increase the signal to noise ratio but decrease the frequency resolution by the same amount.
3/ now log vs lin scale.
usually, everybody doing spectral analysis use log (dB) vertical scale. That allows to see tiny amplitudes beside larger / dominant peaks. A graph with a vertical scale of 120 dB allows you to see two sine waves with a huge amplitude ratio of 1 to 10^6 (so for example 1 V and 1 microV can be seen together)
if you would use a linear scale, you would have trouble to see anything that is lower than 1% of your dominant signal.
so it's all about what you are looking for / or wanting to show / hide in your graphs.
Xiaolong wu
el 24 de Nov. de 2020
Mathieu NOE
el 24 de Nov. de 2020
hello again
to evluate your filter you draw the bode plot (as in my example)
this will show you the dB reduction you should see
lin or log scale, I cannot make a decision for you , it's a question of personnal choice
but if I were you, I would keep the dB scale and put a y axis limit to only show a range of 80 to 100 dB
so the tiny peak at -150 dB would not appear
Xiaolong wu
el 24 de Nov. de 2020
Mathieu NOE
el 24 de Nov. de 2020
Make sure you are logged in.
If the question has already been closed you will see "Accepted Answer by ____" to the right of your profile picture where the question is asked. If not, then look next to the profile picture of the answerer(s). To the right of each person's answer, in green, you should see a box that says "Accept this answer." Push that button
Respuestas (0)
Categorías
Más información sobre Scopes and Data Logging en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!