Signal levels


One thing that you might have noticed from the passthrough example is that the output signal is not very loud. To correct this, we can add a gain factor to the processfunction that multiplies each signal sample by a constant.

In order to take advantage of the architecture of the microcontroller's internal multiplier, it is recommended to use factors that are a power of 2 since in this case a multiplication corresponds to a simple binary shift of the integer values to the left. We measured1μs1\mu sdifference in processing time when tested with the first voice transformer algorithm.

Removing the DC offset

In general, in DSP applications we assume that input signals are zero mean. This is no different in the case of our microphone, so that, if there is no sound, we expect a sequence of zeros. If you actually look at the input samples, however, you will almost certainly find out that this is not so. In fact, the internal circuitry in the microphone almost always adds a voltage offset, and sometimes different microphones (of the same manufacturer) will have different offsets. We typically call this shift in the waveform a DC offset/noise/bias.

DC offsets are highly undesirable since they limit the dynamic range of our system; in other words, we are "wasting" binary digits on a constant that serves no purpose.

TASK 1: From your passthrough implementation, determine the value of the offset. Is it significant compared to the range of the microphone?

Hint: put a breakpoint in the process function while being quiet; then with the debug tool, check the content of the input buffer.

We have talked about DC offset removal in Lecture 2.2.3 in the second DSP course. Recall that a DC component corresponds to a nonzero frequency value at ω=0\omega=0so the idea is to use a filter with a zero in ω=0.\omega = 0.A very simple example is the so-called FIR "DC notch" whose CCDE is simply

y[n]=x[n]x[n1].y[n] = x[n] - x[n-1].

Unfortunately this filter has the very poor frequency response shown here and, while good as a first approximation, it is not really recommended if audio quality is important to you.

A better filter is obtained by using a an IIR DC notch which, while marginally more expensive computationally, provides a much flatter frequency response over the audio frequency band:

y[n]=λy[n1]+x[n]x[n1]y[n] = \lambda y[n − 1] + x[n] − x[n − 1]

When λ\lambdais close to (but less than) one, we can get a magnitude response like this:

TASK 2: Assume that our input samples are between -1 and +1 and are encoded as signed 16-bit integers. Write a C function that implements an IIR DC notch with λ=0.9\lambda = 0.9using integer arithmetic.

Tasks solutions

Are you sure you are ready to see the solution? ;)

Last updated