IIR Digital Filter C language

Source: Internet
Author: User
Tags cos
1. Analog Filter Design 1.1 Number of Butterworth filtersAccording to the given parameters, the analog filter is designed, then the variable transformation is used to obtain the digital filter, which is called the indirect design of the filter. The analog filter, which is the basis of the design of the digital filter, is called the prototype filter. Here, we first introduce the simplest and most basic prototype filter, Butterworth Low-pass filter. Because IIR filter does not have linear phase characteristics, it is not necessary to consider the phase characteristics, and directly consider its amplitude characteristics.
Here, N is the number of filters, ωc is the cutoff frequency. It can be seen from the amplitude characteristic of the upper-form that this is a function of monotonically decreasing, and its amplitude characteristic is that there is no ripple. When designing, it is generally necessary to calculate the number of times that the required design parameters correspond to n. First of all, it is necessary to first by the resistance band frequency, calculate the resistance band attenuation will Butterworth Low-pass filter amplitude characteristics, directly into the upper-type, there are
Finally, we can solve the number of n
Of course, the n here can only be positive, so if the result is a decimal, the decimal is discarded and rounded up. transfer function of 1.2 Butterworth filterThe transfer function of Butterworth Low-pass filter can be obtained by the denominator polynomial of its amplitude characteristic. The denominator polynomial of the

According to S untie, can get pole. Here, in order to facilitate the processing, we are divided into two cases to solve this equation. When n is an even number,

Here, the Euler formula is used. Similarly, when n is an odd number,


In the same way, Euler's formula is also used here. Summed up above, the Jiewei of the Poles


The pole obtained in the upper formula is the point in the S plane, the ωc of the circle with the radius of the first, the number of which is 2N. In order to make its IIR filter stable, we can only select the point of the pole in the left half plane of the s plane. After a stable pole is selected, the transfer function of the analog filter can be obtained from the following formula.


the implementation of the 1.3 Butterworth filter (C language) First, is the calculation of the number of times.           The calculation of the number of times, we can be derived from the next formula.                Its corresponding C language program is [CPP] view plain Copy N = ceil (0.5* (log10 (POW, STOPBAND_ATTENUATION/10)-1)/ LOG10 (Stopband/cotoff)));

Then there is the choice of Poles, and because of the complex operations involved, we declare a complex structure. Most importantly, the calculation of the poles contains the natural exponential function, which is not so convenient for the computer, so we replace it with trigonometric functions,


In this case, the real part and the imaginary part can be calculated separately. Its code is implemented as[CPP]  View plain copy typedef struct    {       double real_ part;       double Imag_Part;  } complex;          complex poles[n];      for (k = 0;k <=  (2*n)-1 )  ; k++    {       if (Cotoff*cos (K+DK) * (pi/n))  <  0)        {           poles [Count]. Real_part = -cotoff*cos ((K+DK) * (pi/n));        Poles[count]. Imag_part= -cotoff*sin ((K+DK) * (pi/n));                  count++;           if  ( count == n)  break;       }  }   
After calculating the stable poles, we can calculate the transfer function. The calculation of the passed function, just like the next


Here, in order to get the coefficients of the analog filter, we need to multiply the denominator. It is clear that the poles here are not necessarily integers, or that the multiplication here requires complex operations. The multiplication code for its plural is as follows, [CPP] view plain copy int complex_multiple (Complex A,complex B, double *res_real,          Double *res_imag) {* (res_real) = (a.real_part) * (B.real_part)-(A.imag_part) * (B.imag_part);            * (Res_imag) = (a.imag_part) * (B.real_part) + (a.real_part) * (B.imag_part);    return (int) 1; With the multiplication code, we now have a simple case to see how it calculates its filter coefficients. We make the following assumption that this time, its transfer function is

Multiply it, and its approximate relationship is as shown in the following figure.


Calculation of the relationship at a glance, so that the implementation is much simpler. Higher-order cases are the same, repeat this calculation is OK. Its code is [CPP] view plain copy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.