0% found this document useful (0 votes)
64 views12 pages

DSP Report 1230969

The document describes using a Butterworth bandpass filter to remove noise from an ECG signal. It discusses the types of digital filters and why an IIR Butterworth filter was chosen. The author applies a 4th order Butterworth bandpass filter with cutoffs of 0.0005-0.08 Hz to the ECG data, and analyzes the filtered signal compared to the raw and clean signals by examining their amplitude spectra and time signals. The filtered signal is similar to but not identical to the clean signal, with a root-mean-square error of 0.543.

Uploaded by

mm hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views12 pages

DSP Report 1230969

The document describes using a Butterworth bandpass filter to remove noise from an ECG signal. It discusses the types of digital filters and why an IIR Butterworth filter was chosen. The author applies a 4th order Butterworth bandpass filter with cutoffs of 0.0005-0.08 Hz to the ECG data, and analyzes the filtered signal compared to the raw and clean signals by examining their amplitude spectra and time signals. The filtered signal is similar to but not identical to the clean signal, with a root-mean-square error of 0.543.

Uploaded by

mm hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Spring

2019

Introduction to Digital
Processing
ECR305

Project Report

NAME: MD. Sakibul Hasan Abir


ID: 1230969
Introduction:
Filter is a generic name that means a linear time invariant system designed for a specific job
of frequency selection or frequency discrimination.

Hence discrete-time LTI systems are also called digital filters.

Type of digital filters:

There are two types of digital filters.

FIR (Finite-duration Impulse Response) IIR

(Infinite-duration Impulse Response)

Why IIR filters? :


For noisy ECG signal I am using IIR filter. FIR uses standard windows whereas IIR does not need to.
Designing IIR filters has fewer constraints and therefore is flexible for designing and implementation. In
FIR a new window will have to be designed which will not be required in IIR filters .Thus I choose IIR
digital filters to suppress noise from the input ECG data.

IIR (Infinite-duration Impulse Response):


The following general equation also describes an IIR filter.

It has two parts: an autoregressive (AR) part (LHS of equation) and a moving average (MA) part (RHS of
equation). Such an IIR filter is called an autoregressive moving average (ARMA) filter.

IIR filters have infinite-duration impulse responses, hence they can be matched to analog filters, all of
which generally have infinitely long impulse responses. Therefore, the basic technique of IIR filter design
is to transform analog filters into digital filters using complex-valued mappings, which is called the
analog-to-digital (A/D) filter transformation. We need to apply frequency-band transformations to low
pass filters in order to design other frequency-selective filters (high pass, band pass, band stop, etc.).

There are three widely used prototype analog filters:

Butterworth filters

Chebyshev filters-

Chebyshev type-I
Chebychev type-II

Elliptic filters.

For this project I’m using Butterworth filter.

Butterworth filter:
The Butterworth filter is a type of filter for signal processing designed to have a flat frequency response
in the passband. It is also referred to as a maximally flat magnitude filter. It was first described in 1930
by the British engineer and physicist Stephen Butterworth in his paper entitled "On the Theory of Filter
Amplifiers".

butterworth does not have any ripples in the passband and even in the stopband .They have a more
linear phase response in the pass-band than Chebyshev Type I/Type II Filters. The gain of an n-order
Butterworth low pass filter is given in terms of the transfer function H(s) as

Where n = order of filter, ωc = cutoff frequency

Matlab code:
load('ECG_raw.mat');
load('ECG_clean.mat');
figure(1)
subplot(3,1,1)
plot(ECG_raw)
title('Noisy ECG signal');
[b,a] = butter(4,[0.0005 0.08],'bandpass'); %fc1/(fs/2)\=0.0005 &
fc2/(fs/2)=0.08
filtered_signal=filter(b,a,ECG_raw);
subplot(3,1,2)
plot(filtered_signal)
title('Filtered signal')
subplot(3,1,3)
plot(ECG_clean);
title('Clean ECG signal')
%Single-sided amplitude spectrum
Fs=5000;
L=length(ECG_raw);
P2=abs(ECG_raw/L);
P1=P2(1:L/2+1);
P1(2:end-1)=2*P1(2:end-1);
f=Fs*(0:(L/2))/L;
% hold on
figure(2)
subplot(3,1,1)
plot(f,P1)
title('Single-sided amplitude spectrum of ECG_raw')
xlabel('f(Hz)')
ylabel('|P1(f)|')
L1=length(ECG_clean);
P22=abs(ECG_clean/L1);
P11=P22(1:L1/2+1);
P11(2:end-1)=2*P11(2:end-1);
f=Fs*(0:(L1/2))/L1;
subplot(3,1,2)
plot(f,P11)
title('Single-sided amplitude spectrum of ECG_clean')
xlabel('f(Hz)')
ylabel('|P11(f)|')
L2=length(filtered_signal);
P23=abs(filtered_signal/L);
P13=P23(1:L2/2+1);
P13(2:end-1)=2*P13(2:end-1);
f=Fs*(0:(L2/2))/L2;
subplot(3,1,3)
plot(f,P13)
title('Single-sided amplitude spectrum of filtered_signal')
xlabel('f(Hz)')
ylabel('|P13(f)|')
%time domain plot
t=[0:L-1]/Fs;
figure (3)
subplot(3,1,1)
plot(t(1:50),ECG_raw(1:50))
title('Time domain plot of ECG_raw')
xlabel('Time(s)')
ylabel('Amplitude')
t1=[0:L1-1]/Fs;
subplot(3,1,2)
plot(t(1:50),ECG_clean(1:50))
title('Time domain plot of ECG_clean')
xlabel('Time(s)')
ylabel('Amplitude')
t2=[0:L2-1]/Fs;
subplot(3,1,3)
plot(t2(1:50),filtered_signal(1:50))
title('Time domain plot of filtered_signal')
xlabel('Time(s)')
ylabel('Amplitude')
freqz(b,a)

Error:
>> r=rmse(ECG_clean,filtered_signal)

r=

0.5430
>> corrcoef(ECG_clean,filtered_signal)

ans =

1.0000 0.2006

0.2006 1.0000
Graphs

Figure 1: Noisy, Filtered and Clean signal graph


-3 Single-sided amplitude spectrum of ECG raw
x 10
2

|P1(f)| 1

0
0 500 1000 1500 2000 2500
f(Hz)
-4 Single-sided amplitude spectrum of ECG c lean
x 10
4
|P11(f)|

0
0 500 1000 1500 2000 2500
f(Hz)
-4 Single-sided amplitude spectrum of filtereds ignal
x 10
5
|P13(f)|

0
0 500 1000 1500 2000 2500
f(Hz)

Figure 2: Single-sided amplitude spectrum of three signals


Figure 3: Time domain plot of three signals
Magnitude (dB) 100

-100

-200

-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

-300

-400
Phase (degrees)

-500

-600

-700

-800
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

Figure 4: Frequency Response (Magnitude & Phase)


Discussion:
As the the desired ECG signal's bandwidth is 0.5-80 Hz so I have use low pass filter. If we butterworth
band pass filter the mathlab[1] code is-

>> [A,B,C,D] = butter(10,[0.05 80]/1000);

>> d = designfilt('bandpassiir','FilterOrder',20, ...

'HalfPowerFrequency1',0.05,'HalfPowerFrequency2',80, ...

'SampleRate',2000);

>> sos = ss2sos(A,B,C,D);

>> fvt = fvtool(sos,d,'Fs',2000);

>> legend(fvt,'butter','designfilt')
Its magnitude response is same as the low pass filter. From the 3 signal graph we can observe that the
filtered signal is almost like the clean signal but it oscillates like sine wave. The error is measured by
rmse(Root Mean Square Error) of clean signal and filtered signal. The error is 0.5430. so we can
say that the raw signal is not fully clean there is still noises. To find the similarity between clean and
filtered signal we use corrcoef (correlation coefficient). The correlation coefficient of two random
variables is a measure of their linear dependence. If each variable has N scalar observations, then the
Pearson correlation coefficient is defined as

where μA and σA are the mean and standard deviation of A, respectively, and μB and σB

are the mean and standard deviation of B. Alternatively, you can define the correlation coefficient in
terms of the covariance of A and B:

The correlation coefficient matrix of two random variables is the matrix of correlation coefficients
for each pairwise variable combination.

Since A and B are always directly correlated to themselves, the diagonal entries are just 1, that is,
Conclusion:
Butterworth had a reputation for solving "impossible" mathematical problems. We get maximally flat
magnitude filter. And it does not have any ripples in the passband and even in the stopband. And for
FRI filter we need to design standard window. So it is efficient to use IIR Butterworth filter.

References:
1. “Butterworth filter”

https://www.mathworks.com/help/signal/ref/butter.html#buct3_m

2. “Single-sided amplitude spectrum”

https://www.mathworks.com/help/matlab/ref/fft.html?searchHighlight=Single-
sided%20Amplitude%20Spectrum&s_tid=doc_srchtitle

(also learn in EEE308L)

3. Aishwarya Acharya, Ruhi M. Lambe, Sweety Zodge,Prof. Jayshree Chaudhari, ‘Implementation of


Digital Filters for ECG analysis’, Department of Computer, JSPM’s BSIOTR(W),Wagholi, Pune-412207,
Maharashtra,India.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.642.3710&rep=rep1&type=pdf

4. https://en.wikipedia.org/wiki/Butterworth_filter

5.” Correlation coefficient”

https://www.mathworks.com/help/matlab/ref/corrcoef.html

You might also like