Butterworth filter c language code

The Butterworth filter is a type of electronic filter. The Butterworth filter is characterized by the smoothest frequency response curve of the passband. This filter was first proposed by a British engineer, Stephen Butterworth, in a paper published in the British Journal of Radio Engineering in 1930.

Number of Butterworth filters

The method of designing an analog filter according to a given parameter, and then performing a variable transformation to obtain a digital filter is called an indirect design of the filter. An analog filter that is the basis of the design of a digital filter is called a prototype filter. Here, we first introduce the simplest and most basic prototype filter, Butterworth low-pass filter. Since the IIR filter does not have linear phase characteristics, it is not necessary to consider the phase characteristics and directly consider its amplitude characteristics.

Butterworth filter c language code

Here, N is the number of times the filter, and Ωc is the cutoff frequency. As can be seen from the amplitude characteristics of the above equation, this is a monotonically decreasing function whose amplitude characteristic is that there is no ripple. When designing, it is generally necessary to first calculate the number N that matches the required design parameters. First, you need to calculate the stopband attenuation from the stopband frequency first.

Butterworth filter c language code

Bring the amplitude characteristics of the Butterworth low-pass filter directly into the upper form, then

Butterworth filter c language code

Finally, the number of times N can be solved is

Butterworth filter c language code

Of course, N here can only be a positive number, so if the result is a decimal, discard the decimal and round up.

Transfer function of Butterworth filter

The transfer function of the Butterworth low-pass filter can be obtained from the denominator polynomial of its amplitude characteristic. Denominator polynomial

Butterworth filter c language code

According to S, the pole can be obtained. Here, in order to facilitate the processing, we divide the equation into two cases. When N is even,

Butterworth filter c language code

Here, the Euler formula is used. Similarly, when N is odd,

Butterworth filter c language code

Similarly, the Euler formula is also used here. Inductive above, the solution of the pole is

Butterworth filter c language code

The poles obtained by the above equation are points equally spaced on a circle having a radius of Ωc in the s-plane, and the number is 2N. In order to stabilize its IIR filter, only the points whose poles are in the left half plane of the S plane can be selected. After the stable pole is selected, the transfer function of the analog filter can be obtained by the following equation.

Butterworth filter c language code

The implementation of Butterworth filter (C language)

First of all, it is the calculation of the number of times. The calculation of the number of times can be obtained by the following formula.

Butterworth filter c language code

Its corresponding C language program is

N = Ceil(0.5*( log10 ( pow (10, Stopband_attenuaTIon/10) - 1) /

Log10 (Stopband/Cotoff) ));

Then there is the choice of the pole. Here we have to declare a complex structure because of the complex operations involved. Most importantly, the calculation of the pole contains a natural exponential function, which is not very convenient for computers, so we replace it with a trigonometric function.

Butterworth filter c language code

In this case, the real part and the imaginary part can also be calculated separately. Its code is implemented as

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;

}

}

Solar Pump Systems

Submersible Pump,Solar Pump Series,48V Dc Solar Pump,Submersible Dc Solar Water Pumps

Wuxi Doton Power , http://www.dotonpower.com

Posted on