Calculating Filter Coefficients to Store in a Microcontroller

Document created by BrettG Employee on May 12, 2011Last modified by BrettG Employee on Nov 11, 2011
Version 2Show Document
  • View in full screen mode

Recently there have been some email support requests regarding the calculation of filter coefficients (and other types of parameters) for storage in a microcontroller. The basic idea is to store a table of parameters in the microcontroller and download them to the appropriate addresses in the SigmaDSP's parameter RAM when required. SigmaStudio includes a few tools to help make this possible.

 

Method 1: Direct coefficient calculation

This method is not really preferred because it takes time and effort compared to the other methods, and doesn't offer any real benefits. In the help file, equations used for calculating first-order and second-order (biquad) IIR filter coefficients are given.

 

For example, here are the first-order filter calculations:

 

/--------------------------------/

 

First order filters
frequency = Cutoff frequency
gain = Linear Gain
fs = Sample Rate

PI = π

 

For lowpass filters,

 

A1 = Pow(2.7,(-2 * PI * frequency/fs))
B0 = gain * (1.0 - A1)
B1 = 0

 

For highpass filters,

 

A1 = Pow(2.7,(-2 * PI * frequency/fs))
B1 = (1.0 + A1) * 0.5 * gain
B0 = -B1

 

For allpass filters,

 

A1 = Pow(2.7,(-2 * PI * frequency/fs))
B0 = -gain * A1
B1 = gain

 

/--------------------------------/

 

The equations for second order filters are in the attached PDF.

 

These equations can be used to calculate parameters directly, but are a bit cumbersome.

 

Attached below is an XLS file that shows an example of how to calculate filter coefficients for parameteric EQ cells.

 

Method 2: Fixed Point Filter Table Generator

Open the fixed point filter table generator under the Tools menu.

ScreenHunter_03 Nov. 20 14.54.jpg

Here you can enter in parameters for a number of filter curves that you desire, then hit the generate button to see the generated curves on the graph.

ScreenHunter_04 Nov. 20 14.55.jpg

Click the value table tab to see the biquad filter coefficients to be stored in RAM (5 coefficients are listed for each filter generated).

ScreenHunter_05 Nov. 20 14.56.jpg

Click the Show Values button and then Generate again to show the decimal values and parameter names for each filter, along with the associated boost.

ScreenHunter_06 Nov. 20 14.56.jpg

These values can be loaded directly into a 2nd-order general filter, set to IIR Coefficient mode in SigmaStudio. Important: Because of the way the values are stored in RAM, the coefficients for a1 and a2 must be inverted from what is shown in the filter table generator. The filter table generator shows coefficients as they are stored in RAM, whereas the IIR Coefficient filter box shows their true values as calculated by the equations.

ScreenHunter_09 Nov. 20 15.09.jpg

The filter table generator allows a large number of coefficients to be calculated and stored in RAM for applications such as a user-controllable tone control.

 

Method 3:Use the capture window

Start a project and make sure the SigmaDSP is connected to a USBi communication channel in the Hardware Configuration tab. Insert any filter into your project and compile. Then change the filter values. The values written to the SigmaDSP's RAM are shown in the capture window (open by default, toggle by pressing Ctrl+5).

ScreenHunter_07 Nov. 20 14.59.jpg

This allows you to simply generate the parameters for one filter curve.

 

Figuring out parameters for any SigmaStudio algorithm control using the Capture Window

You can insert any cell into the project, compile, then change its parameters to see what should be stored in RAM in the capture window. If, for example, I wanted to to a sine tone sweep that is manually controlled by a microcontroller, I could enter in a range of values into a sine tone generator and make note of the frequency parameter in the capture window (in this example, the parameter name is sin_lookupAlg19401increment).

ScreenHunter_08 Nov. 20 15.00.jpg

 

This FAQ was generated from the following discussion: Calculating Filter Coefficients to Store in a Microcontroller

Outcomes