# Calculating Filter Coefficients to Store in a Microcontroller

Document created by BrettG on May 12, 2011Last modified by BrettG on Nov 11, 2011
Version 2Show Document

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.

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.

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

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.

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.

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).

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).

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