... my $sse = 0; # sum of squared error ("error" = distance from the average) while(1) { if ($cnt == 8000) { # the amplitude >= 0 <= 1 ### my $amplitude=$value / $cnt / 255; my $mse = $sse / $cnt; # MSE = mean squared error = average of the sum-of-square-distances my $rms = sqrt($mse); # RMS = root mean squared error = a kind of "average power" measurement for the whole wave my $scaled_rms = $rms / 255; # convert from codes to fraction of fullscale # calculated dbFS,rms = 20 * log10($rms) my $dbFSrms = 20 * log10($scaled_rms); # this is the number of dB_RMS from the fullscale of your mic+ADC my $dba = $dbFSrms - $DBA_MIC_FS; # you will need to find out your mic+ADC's fullscale capability, in dBa or dBv or dBmW print "Calculated dB(FS)_rms and dB(A)_rms: $dbFSrms dBFS, $dba dBa\n"; # reset the count and SSE for the next 8k samples $cnt = 0; $sse = 0; } my $buffer; # read one byte read($fh, $buffer, 1); if(defined($buffer)) { # get an unsigned char my $v = unpack("C", $buffer); # print "Byte read: $v\n"; # sum the squared distance from the theoretical mean $sse += ($v-127.5)**2; $cnt++; } }