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