I've got some signed audio data (16 bit so -32768-32767) and I'd like to calculate a dynamic range figure for it, but obviously taking the logarithm of a negative number is a no-no, but neither shifting the scale so everything's positive or absolute value seem right to me. Is there a 'correct' way to do this?
Calculating dynamic range on signed data?
Started by ●December 12, 2009
Reply by ●December 12, 20092009-12-12
gct <smcallis@gmail.com> wrote:>I've got some signed audio data (16 bit so -32768-32767) and I'd like to >calculate a dynamic range figure for it, but obviously taking the logarithm >of a negative number is a no-no, but neither shifting the scale so >everything's positive or absolute value seem right to me. Is there a >'correct' way to do this?Like any estimation problem you must use some form of filtering or ensemble averaging to get a meaningful result. So what you want is a sliding window operation followed by a RMS calculation. The maximum and minimum values thus exhibited as you slide the window over your data will be its dynamic range. The characteristics of the window/filter must "make sense" with respect to your data. Hope this helps. Steve
Reply by ●December 12, 20092009-12-12
>So what you want is a sliding window operation followed by a RMS >calculation. The maximum and minimum values thus exhibited as >you slide the window over your data will be its dynamic range. >The characteristics of the window/filter must "make sense" with >respect to your data. > >Hope this helps. > >Steve >OK so I slide a window over the data finding RMS values for each location, then find the max/min RMS values to get the dynamic range?
Reply by ●December 12, 20092009-12-12
gct <smcallis@gmail.com> replies to my post,>>So what you want is a sliding window operation followed by a RMS >>calculation. The maximum and minimum values thus exhibited as >>you slide the window over your data will be its dynamic range. >>The characteristics of the window/filter must "make sense" with >>respect to your data.>OK so I slide a window over the data finding RMS values for each location, >then find the max/min RMS values to get the dynamic range?Correct. To get dynamic range in dB, take 20 * log10 * max(RMS)/min(RMS) . But beware you will not get a meaningful number if your window is either too short or too long. This is why one cannot usually speak of "the" dynamic range of a signal. (Or, "the" power spectral density of a signal, but we've had that discussion before.) Steve
Reply by ●December 12, 20092009-12-12
gct wrote:> I've got some signed audio data (16 bit so -32768-32767) and I'd like to > calculate a dynamic range figure for it, but obviously taking the logarithm > of a negative number is a no-no, but neither shifting the scale so > everything's positive or absolute value seem right to me. Is there a > 'correct' way to do this?The dynamic range in bits is just the largest magnitude -- + or - -- contained in the file. Remember: you can't take the log of zero, either. It is customary to take the lowest value as 1 for just that reason. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●December 12, 20092009-12-12
Steve Pope wrote:> gct <smcallis@gmail.com> replies to my post, > >>> So what you want is a sliding window operation followed by a RMS >>> calculation. The maximum and minimum values thus exhibited as >>> you slide the window over your data will be its dynamic range. >>> The characteristics of the window/filter must "make sense" with >>> respect to your data. > >> OK so I slide a window over the data finding RMS values for each location, >> then find the max/min RMS values to get the dynamic range? > > Correct. To get dynamic range in dB, take 20 * log10 * max(RMS)/min(RMS) . > > But beware you will not get a meaningful number if your window > is either too short or too long. This is why one cannot usually speak > of "the" dynamic range of a signal. (Or, "the" power spectral density > of a signal, but we've had that discussion before.)My prescription accounts for the dynamic range of the system needed to reproduce the entire file. Other requirements will dictate different approaches. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●December 12, 20092009-12-12
Jerry Avins <jya@ieee.org> wrote:>gct wrote:>> I've got some signed audio data (16 bit so -32768-32767) and I'd like to >> calculate a dynamic range figure for it, but obviously taking the logarithm >> of a negative number is a no-no, but neither shifting the scale so >> everything's positive or absolute value seem right to me. Is there a >> 'correct' way to do this?>The dynamic range in bits is just the largest magnitude -- + or - -- >contained in the file. Remember: you can't take the log of zero, either. >It is customary to take the lowest value as 1 for just that reason.We might need to ask the OP what he means by dynamic range. Your approach has some interesting outcomes, such as a steady sine wave nonetheless having a huge dynamic range.... Steve
Reply by ●December 12, 20092009-12-12
Jerry Avins <jya@ieee.org> wrote: (snip)> The dynamic range in bits is just the largest magnitude -- + or - -- > contained in the file. Remember: you can't take the log of zero, either. > It is customary to take the lowest value as 1 for just that reason.I have thought about recording on a digital recorder with the input shorted and considering that the low end of the dynamic range. In 24 bits it seems unlikely that it will be zero most of the time, but maybe in 16 bits. Instead of dynamic range I have computed the peak (positive and negative), and RMS for recorded data as 16 and 24 bit WAV files. With 24 bit data, I can then scale up such that all the bits are used before converting to 16 bits. Less worry about getting the record level exactly right, though I try not to be too low. -- glen
Reply by ●December 12, 20092009-12-12
Steve Pope wrote:> Jerry Avins <jya@ieee.org> wrote: > >> gct wrote: > >>> I've got some signed audio data (16 bit so -32768-32767) and I'd like to >>> calculate a dynamic range figure for it, but obviously taking the logarithm >>> of a negative number is a no-no, but neither shifting the scale so >>> everything's positive or absolute value seem right to me. Is there a >>> 'correct' way to do this? > >> The dynamic range in bits is just the largest magnitude -- + or - -- >> contained in the file. Remember: you can't take the log of zero, either. >> It is customary to take the lowest value as 1 for just that reason. > > We might need to ask the OP what he means by dynamic range. > > Your approach has some interesting outcomes, such as a steady > sine wave nonetheless having a huge dynamic range....Indeed. But since the reproducer needs to handle the peak and everything down to zero output, it makes sense for reproducers. There are systems that become unstable if the gain becomes to small. I suppose there are some systems that go to pot is the signal becomes too small. Class B amplifiers usually exhibit a bit of center clipping, and so the distortion with sinewave input decreases as the signal rises to moderate levels. It is often said that the dynamic range of CDs is 20*log(2^15) dB. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●December 12, 20092009-12-12
>We might need to ask the OP what he means by dynamic range. > >Your approach has some interesting outcomes, such as a steady >sine wave nonetheless having a huge dynamic range.... > >Steve >I originally wanted the textbook definition (or an approximation thereof), until I realized the data was signed. I'm mainly interested in picking out spots where the dynamic range get's compressed, ie the audio volume stays the same but they're trying to make it sound louder by reducing dynamic range.






