GithubHelp home page GithubHelp logo

ankitemb / iir-filter-coefficient-for-cmsis-dsp Goto Github PK

View Code? Open in Web Editor NEW
19.0 1.0 5.0 31 KB

IIR filters coefficient generation for ARM CMSIS DSP library using GNU Octave Script.

License: GNU General Public License v3.0

MATLAB 100.00%
iir iir-filters iir-filter signal-processing digital-signal-processing digital-signal-filtering dsp cmsis-dsp cmsis dsp-library

iir-filter-coefficient-for-cmsis-dsp's Introduction

IIR Filter Coefficient for CMSIS DSP

IIR filter implementation on ARM Cortex cores requires coefficient while using CMSIS DSP Library. A GNU Octave script is use to compute coefficient for IIR filter which runs on ARM Cortex core.

The script compute coefficients for IIR filter implemented as Biquad Cascade IIR Filters Using Direct Form I Structure and Biquad Cascade IIR Filters Using a Direct Form II Transposed Structure. ARM's CMSIS DSP library IIR filter implementation can run efficiently and optimally on ARM Coretx cores with floating point data.

Supporting IIR Filters

  1. Butterworth Filter (Lowpass, Highpass, Bandpass and Bandstop)
  2. Chebyshev-1 Filter (Lowpass, Highpass, Bandpass and Bandstop)
  3. Bessel Filter (Lowpass and Highpass)
  4. Elliptic Filter (Lowpass, Highpass, Bandpass and Bandstop)

Example Usage

See the iir coefficient generator examples for use of example. After running example, you will get coefficient in form which is required in CMSIS DSP library.

CMSIS DSP Library expects coefficient in second order section digital filter manner:

   {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...}

Ouput of example:

coeffs =

   0.00032   0.00063   0.00032   1.84850  -0.86742
   1.00000   1.00001  -0.00000   0.86679  -0.00000

The generated coefficient can be directly used in ARM's filter code like following:

#define TEST_LENGTH_SAMPLES 128
#define BLOCK_SIZE 32
#define NUM_BLOCKS (TEST_LENGTH_SAMPLES / BLOCK_SIZE)

#define NUM_STAGE_IIR 2
#define NUM_ORDER_IIR (NUM_STAGE_IIR * 2)
#define NUM_STD_COEFFS 5 // b0, b1, b2, a1, a2

static float32_t iirState[NUM_ORDER_IIR];
static float32_t iirCoeffs[NUM_STAGE_IIR * NUM_STD_COEFFS] = 
{
    0.96452, -1.92904, 0.96452, 1.94945, -0.95020,
    1.00000, -2.00000, 1.00000, 1.97831, -0.97906
}

float32_t OutputValues[TEST_LENGTH_SAMPLES];
float32_t InputValues[TEST_LENGTH_SAMPLES];

float32_t *InputValuesf32_ptr = &InputValues[0];  // declare Input pointer 
float32_t *OutputValuesf32_ptr = &OutputValues[0]; // declare Output pointer

arm_biquad_cascade_df2T_instance_f32 S;

int main()
{
    uint32_t k;
    
    for (k = 0; k < TEST_LENGTH_SAMPLES; n++)
    {
  	    InputValues[n]= arm_sin_f32(2*PI*50.0*n/500.0);
    }
    
    arm_biquad_cascade_df2T_init_f32(&S, NUM_STAGE_IIR, &iirCoeffs[0], &iirState[0]);
    
    for (k = 0; k < NUMBLOCKS; k++)
    {
	arm_biquad_cascade_df2T_f32 (&S, InputValuesf32_ptr + (k*BLOCKSIZE), OutputValuesf32_ptr + (k*BLOCKSIZE), BLOCKSIZE);    // perform filtering
    }
    
    while(1);
}

Note: Above examples is not written for particular filter design but aim is to shown full example of IIR filter using ARM's CMSIS DSP library.

iir-filter-coefficient-for-cmsis-dsp's People

Contributors

ankitemb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

iir-filter-coefficient-for-cmsis-dsp's Issues

Accuracy of coefficients

Hi!
I checked the operation of filters with the obtained coefficients. Everything works well. But there is one problem:
By default in the console, I get a precision for coefficients of 7 symbols after point. But this accuracy is not enough in my case, and the error accumulates.
I solved this problem in the following way:
increased the precision by typing "output_precision(15)" into the console.
Full example:
pkg load signal
iir_filter = "butter"
order=3
fs=500
fc = 8.1
ft = 'low'
plot_on = 1
output_precision(15)
iir_coeffs_cmsis(iir_filter, order, fs, fc, ft, plot_on)

Maybe you can add this line to iir_coeffs_cmsis.m script?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.