# Digital signal processing_ Butterworth low pass filter experiment

## Experimental purpose

1. Familiar with the principle and method of designing IIR digital filter by bilinear transformation method
2. Master the computer simulation method of digital filter
3. The perceptual knowledge of digital filtering is obtained by observing the filtering effect on the actual ECG signal

## Test content

1. A Butterworth low-pass IIR digital filter is designed by bilinear transformation method. The design index parameters are: the frequency in the passband is lower than 0.2 π 0.2\pi At 0.2 π, the maximum attenuation is less than 1dB; In stopband [ 0.3 π , π ] [0.3\pi,\pi] In the frequency range of [0.3 π, π], the minimum attenuation is greater than 15dB.
2. Taking 0.02 π as the sampling interval, print out the frequency range of the digital filter [ 0 , π 2 ] [0,\frac{\pi}{2}] Amplitude frequency response characteristic curve on [0,2 π].
3. The designed filter is used to simulate and filter the actual ECG signal sampling sequence, print the ECG signal waveform before and after filtering, and observe and summarize the filtering function and effect.

## requirement

• Printed by ∣ H ( e j ω ) ∣ |H(e^{jω})| ∣H(ej ω) ∣ characteristic curve and design process briefly describe the characteristics of bilinear transformation method.
• The ECG signal waveforms before and after filtering are compared to illustrate the filtering process and function of the digital filter.

Attachment: ECG signal sampling sequence x(n)
Human ECG signal is often disturbed by industrial high frequency in the measurement process, so it must be processed by low-pass filtering before it can be used as useful information to judge cardiac function. The following is an actual ECG signal sampling sequence sample x(n), in which there is high-frequency interference. In the experiment, x(n) is used as the input sequence to filter out the interference components.

x(n)={-4，  -2，   0，  -4，  -6，  -4， -2， -4， -6，  -6，
-4，  -4，  -6，  -6，  -2，   6， 12，  8，  0， -16，
-38，-60， -84， -90， -66， -32， -4， -2， -4，   8，
12，  12，  10，   6，   6，   6，  4，  0，  0，   0，
0，    0，  -2，  -4，   0，   0，  0， -2， -2，   0，
0，   -2，  -2，  -2，  -2，   0}


## MATLAB implementation

### principle

• bilinear transformation

from s s Mapping s field to tangent t a n tan tan, from t a n tan tan mapping to z z z domain
s = 2 T ⋅ 1 − z − 1 1 + z − 1 j Ω = 2 T j t a n ω 2    ( s = j Ω ) z = 1 + s T / 2 1 − s T / 2    ( s = δ + j Ω ) s=\frac{2}{T}\cdot\frac{1-z^{-1}}{1+z^{-1}}\\ j\Omega=\frac{2}{T}jtan\frac{\omega}{2}~~(s=j\Omega)\\ z=\frac{1+sT/2}{1-sT/2}~~(s=\delta+j\Omega) s=T2​⋅1+z−11−z−1​jΩ=T2​jtan2ω​  (s=jΩ)z=1−sT/21+sT/2​  (s=δ+jΩ)

• Working principle of digital filter

x 0 ( t ) → H 1 ( s ) → x ( t ) → Draw kind / amount turn → x ( n ) → H ( z ) → y ( n ) → y s ( t ) → H 2 ( s ) → y ( t ) x_0(t)\rightarrow H_1(s)\rightarrow x(t)\rightarrow sampling / quantization \ rightarrow \ x(n)\rightarrow H(z)\rightarrow y(n)\rightarrow y_s(t)\rightarrow \ H_2(s)\rightarrow y(t) x0 (t) → H1 (s) → x(t) → sampling / quantification → x(n) → H(z) → y(n) → ys (t) → H2 (s) → y(t)

### code implementation

x=[-4 -2 0 -4 -6 -4 -2 -4 -6 -6 -4 -4 -6 -6 -2 6 12 8 0 -16 -38 -60 -84 -90 -66 -32 -4 -2 -4 8 12 12 10 6 6 6 4 0 0 0 0 0 -2 4 0 0 0 -2 -2 0 0 -2 -2 -2 -2 0];
n=length(x);
xk=fft(x);
plot(0:n-1,abs(xk));
title('Frequency domain signal'); • Bilinear transformation Butterworth IIR
%Digital filter index
wp = 0.2*pi;ws = 0.3*pi;rp = 1;rs = 15;Fs = 1;
%Convert to analog domain
wp1=2*Fs*tan(wp/2);
ws1=2*Fs*tan(ws/2);
[N,Wn] = buttord(wp1,ws1,rp,rs,'s');
[Z,P,K] = buttap(N);
[Bap,Aap] = zp2tf(Z,P,K);
[b,a] = lp2lp(Bap,Aap,Wn);
[bz,az] = bilinear(b,a,Fs);
[H,W] = freqz(bz,az);
disp(bz);
disp(az);
plot(W*Fs/pi,abs(H));
grid on;
xlabel('frequency/Hz');
ylabel('range');
title('Frequency response of digital filter'); clear;
% Read the original data, here is n * 1 Data
Signal = [-4 -2 0 -4 -6 -4 -2 -4 -6 -6 -4 -4 -6 -6 -2 6 12 8 0 -16 -38 -60 -84 -90 -66 -32 -4 -2 -4 8 12 12 10 6 6 6 4 0 0 0 0 0 -2 4 0 0 0 -2 -2 0 0 -2 -2 -2 -2 0];
%index
wp = 0.2*pi;ws = 0.3*pi;rp = 1;rs = 15;Fs = 1;
%calculation
wp1=2*Fs*tan(wp/2);
ws1=2*Fs*tan(ws/2);
[N,Wn] = buttord(wp1,ws1,rp,rs,'s');
[Z,P,K] = buttap(N);
[Bap,Aap] = zp2tf(Z,P,K);
[b,a] = lp2lp(Bap,Aap,Wn);
[bz,az] = bilinear(b,a,Fs);
% wave filtering
Signal_Filter = filter(bz, az, Signal);
subplot(2, 1, 1);
plot(Signal);
title('original image ');
subplot(2,1,2);
plot(Signal_Filter);
title('Butterworth low pass filtered image'); Tags: MATLAB

Posted by nloding on Sat, 16 Apr 2022 18:59:57 +0930