Code covered by the BSD License
-
initDisplay(AI,x,X,dBA,Fs,C)
INITDISPLAY Initializes SLM figure window.
-
SLM
SLM Implements a basic sound level meter.
-
analyzeSignal(x,Fs)
ANALYZESIGNAL Evaluates dBA level of input signal.
-
estimateLevel(x,Fs,C)
ESTIMATELEVEL Estimates signal level in dBA.
-
filterA(f,plotFilter)
FILTERA Generates an A-weighting filter.
-
initSoundCard(Fs,responseType...
INITSOUNDCARD Initializes the sound card.
-
runCalibration
RUNCALIBRATION Estimates the calibration constant.
-
stopSoundCard(obj,event)
STOPSOUNDCARD Closes sound card device.
-
updateDisplay(obj,event)
UPDATEDISPLAY Updates the SLM display.
-
View all files
from
Sound Level Meter
by Douglas Lanman
Implements real-time spectrum analyzer and displays decibel level.
|
| estimateLevel(x,Fs,C)
|
function [X,dBA] = estimateLevel(x,Fs,C)
% ESTIMATELEVEL Estimates signal level in dBA.
% ESTIMATELEVEL Implements an A-weighted signal
% level meter. The FFT is used to compute the
% frequency spectrum.
%
% Author: Douglas R. Lanman, 11/21/05
% Calculate magnitude of FFT.
X = abs(fft(x));
% Add offset to prevent taking the log of zero.
X(find(X == 0)) = 1e-17;
% Retain frequencies below Nyquist rate.
f = (Fs/length(X))*[0:(length(X)-1)];
ind = find(f<Fs/2); f = f(ind); X = X(ind);
% Apply A-weighting filter.
A = filterA(f);
X = A'.*X;
% Estimate dBA value using Parseval's relation.
totalEnergy = sum(X.^2)/length(X);
meanEnergy = totalEnergy/((1/Fs)*length(x));
dBA = 10*log10(meanEnergy)+C;
% Estimate decibel level (for visualization).
X = 20*log10(X);
|
|
Contact us at files@mathworks.com