0
$\begingroup$

I'm having a little trouble plotting the DFT of a signal in dB. I can get the picture up nicely when using the magnitude but when I try converting the magnitude to decibels it all goes south. I've been using this for help: http://dadorran.wordpress.com/2014/02/20/plotting-frequency-spectrum-using-matlab/

Here is the code I'm running: (y is the signal obtained from a .mat file and L is the length of the signal)

Y = fft(y);
MAG = abs(Y);
MAGshift = abs(fftshift(Y));
bin_vals = [0:L-1];
L2 = L/2;
f = Fs*(bin_vals - L2)/L;

figure(1);
plot(f,MAGshift);
axis([-1000 1000 0 45000]);
grid on;

With this I managed to get this lovely picture:enter image description here

But when I convert the magnitude to decibels with mag2db(MAG) or 10*log10(MAG) and plot it, it does not look anything like this.

enter image description here

Any help?

$\endgroup$
  • $\begingroup$ "it does not look anything like this" It's not supposed to. What does it look like and what do you think it should look like? $\endgroup$ – endolith Oct 22 '14 at 14:01
3
$\begingroup$

I would suggest you to normalize the amplitude by the maximum if you don't know the exact reference or scaling:

MAG_dB = 20*log10(MAG/max(MAG));
plot(MAG_dB);

This will yield a logarithmic plot normamalised to 0 dBFS.

Small example for two sinusoids with difference in amplitude of 3dB is below:

clc, clear, close

fs = 1000;
t = (0:1/fs:10-1/fs);
N = length(t)
% Two sinusoids, second one (@200Hz) has amplitude of -3dB.
s = sin(2*pi*100*t) + 1/sqrt(2)*sin(2*pi*200*t);
s = hamming(N)'.*s;

X = abs(fft(s))/N;
X_db = 20*log10(X/max(X));

plot(X_db)
grid on

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for your comment, I have attached a picture of how that looks. Doesn't look quite right to me. i.imgur.com/NFnQctF.png $\endgroup$ – dingari Oct 22 '14 at 8:49
  • $\begingroup$ @user2750354: It looks perfectly OK for me. Answer updated. $\endgroup$ – jojek Oct 22 '14 at 9:11
  • $\begingroup$ Ok thank you, I think I'm starting to get a better understanding of the plot I got. In the assignment there is a questing about a "significant drop in energy" above a certain frequency. That would be at the point where it drops down to ca. -40dB, right? (in the picture linked in previous comment) $\endgroup$ – dingari Oct 22 '14 at 14:18
  • $\begingroup$ @user2750354: I believe that there are two correct answers. One you mentioned above (centered around 0 Hz), and a second one around 15000 Hz. $\endgroup$ – jojek Oct 22 '14 at 14:29
  • $\begingroup$ Ok thanks :) I'm wondering what the effective bandwidth of the signal would be. The power drops to about -40dB at 500Hz, so would the effective bandwidth be 1000Hz? $\endgroup$ – dingari Oct 22 '14 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.