in reply to Measuring the sound level (dB(A)) with PERL

What you are computing is not the amplitude, but the wrong mean value. The "wrong" in mean value is because a sound signal is supposed to be variations around 0, which is not possible with your signed byte values. You'll have to find out how your values are actually coded, either with an offset (eg: substract 128 to every value), or as signed values. It's even possible that the values are not linear representations of the data, but rather logarithmic, as in A-law encoding. AFAIK, you can indeed expect one sample per byte. To see if you're decoding your input correctly, you should try to play a sinusoid beside your microphone (I'm sure you can find somewhere on the internet to have the reference A 440), and see if you manage to plot something that looks like a sinusoid centered on 0.

Now, as I've already told you, the mean value is supposed to be 0 and is therefore useless. The power of a signal ("sound level" if you will) is only a function of its amplitude when the signal is periodic, preferably a sinusoid (a continuous beep). Otherwise you want to compute:

my $sum = 0; my $length = @input; # number of samples in the array @input for my $value (@input) # assuming @input are samples that have already + been converted to the correct unit { my $sum += $value*value; # sum of the squares } my $dba = 10 * log10($sum/$length);

Note that the factor before the log10 is now 10 and not 20, because the input is squared. Besides, unless you have some way of calibrating your microphone to be able to tell exactly the power of its input, you'll only be able to use the values relative to each other. Like saying "this sound is 3dB higher than that one" but not "that sound is at 50dB".