Plotting SPL(dBA) from an audio WAV file?

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

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

Thank you Mathieu~,for your patience and for being able to help me (a beginner .
Because my recordings are measured with a smartphone, but this smartphone has been calibrated (to class 1 sound level meter accuracy). So I can assume that my recording has been "calibrated". I took a 1kHz, 94dB source yesterday, can this determine the factor between the amplitude in the av file and the actual sound pressure?
Do you mean: "sensor_spectrum_dB" is the log of the fft amplitude?
Can I convert "sensor_spectrum_dB" to dBA next?
2.Sorry Mathieu, I just checked, but Figure 1 is just an image of a sound sample, and Figure 2 is a graph from someone else's paper. Figure 2 is a spectrum graph from a calibrated smartphone recording, just like me, but I don't know how he did it, so that's what has been confusing me lately.
You are a kind man, best wishes~
hello @ZHU z
beware that class quality refer to accuracy and frequency range of acoustic meters ,
but that does not mean the sensivity factor is known - this has to be measured with a calibrated sound source (calibrator in short)
now that you have recorded a 94 dB SPL tone , look at the FFT plot (and yes sensor_spectrum_dB is expressed in dB as the variable name suggests)
the code let you choose to add the (A) weighting factor by selecting the appropriate value for option_w
if option_w = 0 => no weighting - also results as dB(L)
if option_w = 1 => (A) weighting - also results as dB(A)
(refer to the other post where I put the code) :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if you are dealing with acoustics, you may wish to have A weighted
% spectrums
% option_w = 0 : linear spectrum (no weighting dB (L) )
% option_w = 1 : A weighted spectrum (dB (A) )
option_w = 1;
thanks Mathieu~
Thank you for your patience.
I have two questions to confirm with you~
1. Do I really need 94dB of calibrated audio if I want to achieve my goal? Or the code you gave me before is enough? The code you provided can calculate the sound pressure without the need for the phone's microphone sensitivity?
2. Do you mean that adding (A) weighting factor to "sensor_spectrum_dB" will be enough (via option_w)?
best wishes~
hello @ZHU z
1 somehow you have to record a "calibration" sound ok know SPL (a calibrator are usually designed for 94 dB output). Then you do a record of that know SPL sound and you look at which amplitude comes the FFT spectrum in dB. Then you compute the difference and that becomes your sensivity (or shift factor in dB).
2. yes
all the best
@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.
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 Fourier Analysis and Filtering in Help Center and File Exchange

Products

Release

R2017a

Asked:

on 5 Apr 2022

Commented:

on 25 Aug 2022

Community Treasure Hunt

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

Start Hunting!