0
votes

I am trying to obtain dB levels of a pure signal and a noisy signal in MATLAB. Part of my program is as shown below:

Fs= 3000;
t = 0:1/Fs:3*(Fs-1)/Fs;
y = 10^(40/20)*sin(2*pi*500*t);
x = 10^(60/20)*randn(size(y));
rmsx = rms(x);
rmsy = rms(y);
ydb = mag2db(rmsy)
xdb  = mag2db(rmsx)

The result I get from this is x(noise) = 60dB, but y(signal) = 36dB instead of 40dB.

However, if I instead use max value of y instead of rms value, I obtain the 40dB. And for the noise using max value instead of rms value gives me a dB of 70.

Which is the better way? Using rms value or max value in the calculations or does it even matter?

Also, when I play the signal as a sound, @0dB I am still getting a tone.

I understand dB is a ratio between a value and a reference value. But what modifications can I make to the code such that 0dB = No tone

1
You can't make any modifications such that 0 dB is /exactly/ no tone, you can only get really close. If 0 dB was no tone, then 40 dB would be 10000 x no tone, which is also no tone. So we call -infinity to be no tone and 0 dB is simply whatever (nonzero) reference level you want. - Dan
Just to add to Dan's comments - it's a common convention to use 0 dB as a full scale reference, and then anything less than full scale is a negative dB value relative to full scale, i.e. full scale = 0 dB, 50% = -6 dB, 25% = -12 dB, 10% = -20 dB, etc. - Paul R
Hi thanks for your reply. @PaulR so the intensity of the sound is reduced by 50% if the db goes to -6? - Ali P
Yes, 20*log10(0.5) = -6 dB (approx) and 20*log10(2.0) = +6 dB (approx). Also 20*log10(0.1) = -20 dB (exactly) and 20*log10(10.0) = +20 dB (exactly). - Paul R
I see. Okay but now I am trying to measure the actual sound level on a sound level meter which uses dBSPL. The sound that is being generated in matlab is in terms of dB full scale but the recorded sound in the dB meter is in dBSPL. So if I go down by -6dB full scale the dBSPL goes down by -10dB. Is there some kind of relationship between those two? - Ali P

1 Answers

2
votes

The usual way is to attach a meaning of average power to the dB value. So use rms.

For the noise you get 60 dB because randn has average power 1.

For sin the theoretical rms value is 3 dB below the peak value, so you should get 37 dB, not 36 dB. Depending on the number of cycles of the sinusoid, your computed value might deviate slightly.

Using max with the noise is not meaningful. Since the nornal distribution is unbounded, you can get arbitrarily high values.

As for the reference, 0 dB does not imply that there is no tone. In audio, 0 dB usually represents the "full scale" value, so all values are usually below that.