Plotting SPL(dBA) from an audio WAV file?

69 views (last 30 days)
hi Mathieu NOE,thanks alot, again~
Please forgive me for posting a separate post in accordance with rik's comments.
I reviewed the code you gave me last time and the graph I obtained is shown in Figure 1.
and my questions is:
The vertical axis is all negative,and there is still a difference with the graph I want (Figure 2).and i notice the "sensor_spectrum_dB" in this code .Do you know what this means? can I generate SPL(dBA) by this "sensor_spectrum_dB"?
Please forgive me for asking a lot of questions, I found myself really not very good at this,
thanks a lot.
Looking forward to your reply~
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% display 2 : averaged FFT spectrum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[freq, sensor_spectrum] = myfft_peak(signal,Fs,NFFT,OVERLAP);
% convert to dB scale (ref = 1)
sensor_spectrum_dB = 20*log10(sensor_spectrum);
% apply A weigthing if needed
if option_w == 1
pondA_dB = pondA_function(freq);
sensor_spectrum_dB = sensor_spectrum_dB+pondA_dB;
sensor_spectrum_dB=abs(sensor_spectrum_dB);
my_ylabel = ('Amplitude (dB (A))');
else
my_ylabel = ('Amplitude (dB (L))');
end
figure(2),semilogx(freq,sensor_spectrum_dB);grid on
df = freq(2)-freq(1); % frequency resolution
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(df,3) ' Hz ']);
xlabel('Frequency (Hz)');ylabel(my_ylabel);
legend(leg_str);
figure 1
figure 2

Accepted Answer

Mathieu NOE
Mathieu NOE on 6 Apr 2022
hello Zhu
no problem, I'll try to answer as precisely as possible
the amplitude is negative because the dB scale is the log of the fft amplitude .
wav signals are by definition limited to +/- 1 amplitude (otherwise the signal is clipped) , so a max amplitude wav signal would never exceed 0 dB in the fft plot (because log(1) = 0)
so you need a "calibration" wav file that let you know by how much dB you must shift the vertical axis.
An example : in acoustics , the 0 dB reference level corresponds to 20 micro pascal acoustic pressure.
that is the 0 dB level in your figure 1 plot
Assuming you have "calibrated" your recorder and it says that a 60 dB ( = 1000 x 20 micro pascal) pressure sinus wave (for example at 100 or 1000 Hz) will be recorded as wav file with amplitude = 1 , so the dB level we computed must be shifted by + 60 dB (and that is the reason for the difference between the two plots).
so what we need now is another wav file that tells us waht is the factor between the amplitude in the wav file vs the real acoustic pressure
for the shape or spectral content of the file you provided, I can only say that it's really different from the plot you show in fig 1 , but what we get is truly what is inside the file - are you shure that the provided audio file should have a spectrum shape like fig 1 ?
all the best
  8 Comments
APRAMEYAN V
APRAMEYAN V on 25 Aug 2022
@Mathieu NOE How will you calculate the rms of a spectrum in frewuency domain? i referred to the siemens manual where it says rms = sqrt( a(i-1)/2 + sumsqr(a(i):a(k-1) + a(k)/2).
but it hasnt worked for me.
Mathieu NOE
Mathieu NOE on 25 Aug 2022
I don't understand what the "siemens" formula means especially as it should be a sum (which dosn't appear in what you posted)
I would say that the RMS is (as usual) :
RMS_value = sqrt(sum(values²)/N)
here value = SPL (il linear units (Pa for instance) not in dB )
if you want the RMS in dB than its :
RMS_dB = 20*log10(RMS_value) = 10*log10(RMS_value²) = 10*log10(sum(values²)/N)

Sign in to comment.

More Answers (0)

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!