R/E/P Community

Please login or register.

Login with username, password and session length
Advanced search  

Pages: [1]   Go Down

Author Topic: Full Scale with signed integers ?  (Read 3659 times)

Andrew H

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Full Scale with signed integers ?
« on: February 15, 2006, 07:30:23 PM »

I have a question about the concept of 'full scale' when using signed integers.

If I have an audio file (say 16 bit WAV), the  values describing the amplitude of the waveform can range from -32768 to +32767.

If I had a peak value at +32767, would this be:

       20*log10(32767/32767) = 0 dBFS

or

       20*log10(32767/32768) = -0.0002651 dBFS


Similarly, does a negative peak value of -32768 give:

       20*log10(-32768/-32768) = 0 dBFS ?

Is this a purely mathematical concern (with a simple accepted definition) or should there be some consideration of the way an ADC works if we want to be technically correct?

Thanks,

Andrew
Logged

bobkatz

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2926
Re: Full Scale with signed integers ?
« Reply #1 on: February 22, 2006, 01:39:02 PM »

Dear Andrew: John Watkinson covers this in his book. Full scale is a compromise by one Q unit in either the positive or negative direction  because of the need to have a 0 point on the sine wave. In practice it's inconsequential. A DSP expert could tell you if it has any practical consequences other than simply being aware of it.

Us mastering engineers certainly don't care about it, we play the audio and it works.


I'm sorry if this answer is ambiguous, I'm surprised Dan Lavry didn't help you on this question.


Bob





Andrew H wrote on Wed, 15 February 2006 19:30

I have a question about the concept of 'full scale' when using signed integers.

If I have an audio file (say 16 bit WAV), the  values describing the amplitude of the waveform can range from -32768 to +32767.

If I had a peak value at +32767, would this be:

       20*log10(32767/32767) = 0 dBFS

or

       20*log10(32767/32768) = -0.0002651 dBFS


Similarly, does a negative peak value of -32768 give:

       20*log10(-32768/-32768) = 0 dBFS ?

Is this a purely mathematical concern (with a simple accepted definition) or should there be some consideration of the way an ADC works if we want to be technically correct?

Thanks,

Andrew

Logged
There are two kinds of fools,
One says-this is old and therefore good.
The other says-this is new and therefore better."

No trees were killed in the sending of this message. However a large number of
electrons were terribly inconvenienced.

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Full Scale with signed integers ?
« Reply #2 on: February 22, 2006, 03:20:50 PM »

Andrew H wrote on Thu, 16 February 2006 00:30

I have a question about the concept of 'full scale' when using signed integers.

If I have an audio file (say 16 bit WAV), the  values describing the amplitude of the waveform can range from -32768 to +32767.

If I had a peak value at +32767, would this be:

       20*log10(32767/32767) = 0 dBFS

or

       20*log10(32767/32768) = -0.0002651 dBFS


Similarly, does a negative peak value of -32768 give:

       20*log10(-32768/-32768) = 0 dBFS ?

Is this a purely mathematical concern (with a simple accepted definition) or should there be some consideration of the way an ADC works if we want to be technically correct?

Thanks,

Andrew


It would be
       20*log10(32767/32768) = -0.0002651 dBFS
Similarly, does a negative peak value of -32768 give:
       20*log10(-32768/-32768) = 0 dBFS


The reason for the lack of symetry is that adding one more quantization level at the positive peak would require adding a bit (17 bit word). Look at a 3 bit binary for example:

decimal 0 is binary 000
decimal 1 is binary 001
decimal 2 is binary 010
decimal 3 is binary 011
decimal 4 is binary 100
decimal 5 is binary 101
decimal 6 is binary 110
decimal 7 is binary 111

if you want decimal 8 it becomes binary 1000 thus 4 bits (not 3)

So now we want to "split" our bianry code into "2 sections", one is for positive and the other is for negative numbers.

There are a couple of ways to do that, beyond the scope of this post. There is a convention for using the MSB as 0 to note positive and 1 no note negative number, but that is not the best from "ease of artithmmetics" standpoint therefore there  is a first complement and also one called 2nd complement which is very practical code.

But for any code, given that 2^n is always even, and given that one code value needs to be assigned to zero value, we end up with a lack of symetry of 1 quantization.

Of course, in the case of 3 bits, 1 quantization is huge imbalance, in the case of 16 bits it is relativly tiny, as your calculation shows.

Regards
Dan Lavry
www.lavryengineering.com
Logged

Andrew H

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: Full Scale with signed integers ?
« Reply #3 on: February 23, 2006, 06:02:50 AM »

Thanks both for your answers.

The reason for the positive/negative asymmetry all makes sense (a zero value, 2's complement etc).

The main thing I'm interested in is whether there is some convention when doing these calculations.
Say I write some analysis software that calculates the peak value (for the purposes of producing exact numbers rather than something more coarse like metering).
If I then have a 16 bit WAV file with a maximum value of +32767, is it more correct to return:

20*log10(32767/32767) = 0 dBFS
or
20*log10(32767/32768) = -0.0002651 dBFS

Or is there no real standard here ?

Thanks again,

Andrew
Logged

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Full Scale with signed integers ?
« Reply #4 on: February 23, 2006, 06:46:14 PM »

Andrew H wrote on Thu, 23 February 2006 11:02

Thanks both for your answers.

The reason for the positive/negative asymmetry all makes sense (a zero value, 2's complement etc).

The main thing I'm interested in is whether there is some convention when doing these calculations.
Say I write some analysis software that calculates the peak value (for the purposes of producing exact numbers rather than something more coarse like metering).
If I then have a 16 bit WAV file with a maximum value of +32767, is it more correct to return:

20*log10(32767/32767) = 0 dBFS
or
20*log10(32767/32768) = -0.0002651 dBFS

Or is there no real standard here ?

Thanks again,

Andrew


I still do not know what your goal is, so I can not answer the question "is there no real standard here?"

All I can say at this point is:

A "ideal real life DA converter", when presented with a code value, will generate a voltage that corresponds to that code value. So if you have 16 bits (not 17), you can not really make a signal that is 32768. You can make a signal that is 32767.

There is an inherent lack of symmetry here between positive and negative. One can add a 1/2 LSB DC offset to gain symmetry and "spread the error".

For audio, in most applications, a 1/2LSB DC offset has negligible impact.  

Regards
Dan Lavry
www.lavryengineering.com
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Full Scale with signed integers ?
« Reply #5 on: February 23, 2006, 07:09:22 PM »

I think the question is, given a 16 bit signed representation, is full scale (0dB) +/-32767, or +/-32768?

Makes no real difference when it comes to sound, or how you work with it... but if you're writing a program and want to display the magnitude of the signal to a high degree of accuracy, then it's worth knowing if there is a standard.

Logged

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Full Scale with signed integers ?
« Reply #6 on: February 23, 2006, 07:38:49 PM »

Jon Hodgson wrote on Fri, 24 February 2006 00:09

I think the question is, given a 16 bit signed representation, is full scale (0dB) +/-32767, or +/-32768?

Makes no real difference when it comes to sound, or how you work with it... but if you're writing a program and want to display the magnitude of the signal to a high degree of accuracy, then it's worth knowing if there is a standard.




Again, tt does depend on the goal. Examples:

If you are writing a program to display the magnitude of a signal in terms of loudness, I would add 1/2 lsb because a DC oftest is not the issue (it caries no sound, air is a great DC removal tool), the AC value is the issue.

If you write software for a digital meter, I would stay true to the code because there is no 32768 code, thus you can not display it. For metering when you hit 32767, you hit the maximum code, and you want to indicate that condition.

Regards
Dan Lavry
www.lavryengineering.com  
Logged
Pages: [1]   Go Up
 

Site Hosted By Ashdown Technologies, Inc.

Page created in 0.068 seconds with 19 queries.