You are on page 1of 12

RAHULGANHT E N

21BEE0092
DIGITAL SIGNAL PROSESSING DATE:29/6/2023

DIGITAL ASSIGNMENT 2 Name: Rahulganth E N

Roll no:21BEE0092

ECG signal processing

Data: Segment of paediatric sleep ECG with Fs of 500 Hz

Order 4, cutoff frequency of 40 Hz:

1)Design of Low Pass IIR Butterworth filter:

plot(x)
xlim([1000 2000]);
ylim([-1 1]);
title('input signal');
figure(1)
signal1=x;
Fs=500;
[b,a]=butter(4,[40]*2/500);
filter_res=filter(b,a,signal1);
freq_ana=fft(filter_res,N);
magnitude=abs(freq_ana);
plot(magnitude);
title('frequence response of filter');
figure(2)
plot(filter_res);
xlim([10000 11000])
title('BW Filter 40 Hz');
figure(3)

OUTPUT:
RAHULGANHT E N
21BEE0092

2)Design of FIR Low Pass Filter:

plot(x)
xlim([1000 2000]);
ylim([-1 1]);
title('input signal');
figure(1)
signal1=x;
rp = input('Enter the pass band ripple=');
rs = input('Enter the stop band ripple=');
fpb = input('Enter the pass band frequency=');
fsb = input('Enter the stop band frequency=');
fs = input('Enter the sampling frequency=');
wp = 2*fpb/fs;
ws = 2*fsb/fs;
num = 20*log10(sqrt(rp*rs))-13;
den = 14.6*(fsb-fpb)/fs;
n = abs(ceil(num/den));
n1 = n+1;
RAHULGANHT E N
21BEE0092
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
w = hamming(n1);
%LOW PASS FILTER
b = fir1(n,wp,w);
[h,o] = freqz(b,1,256);
m = 20*log10(abs(h));
figure(3)
plot(o/pi,m);
ylabel('Gain (dB)');
xlabel('(a)Normalized frequency---->');
title('Magnitude response of FIR low pass filter');
Y_filtered = filtfilt(b,1,signal1);
plot(Y_filtered)
xlim([10000 11000])
figure(4)
frequ_filt_noise = fft(Y_filtered,N);
figure(5)
magnitude = abs(frequ_filt_noise);
plot(f,magnitude);
title('Frequency Response of Input');

OUTPUT:
RAHULGANHT E N
21BEE0092

FIR has equal delay at all frequencies while the IIR filter time delay varies with
frequency ,IIR filter has less noise than FIR filter.

3)filtered signal with markers indicating the R peaks.

Code:

wt = modwt(signal1,5);
wtrec = zeros(size(wt));
wtrec(4:5,:) = wt(4:5,:);
y = imodwt(wtrec,'sym4');
y = abs(y).^2;
[qrspeaks,locs] = findpeaks(y,'MinPeakHeight',0.35,...
'MinPeakDistance',0.150);
figure(4)
RAHULGANHT E N
21BEE0092
plot(y)
hold on
plot(locs,qrspeaks,'ro')
xlim([10000 11000])
xlabel('Seconds')
title('R Peaks')
figure(5)

OUTPUT:

Average R to R:

disp(qrspeaks);
avg_RtoR=mean(qrspeaks);
fprintf("Average R to R is")
disp(avg_RtoR);
RAHULGANHT E N
21BEE0092

Time aligned synchronous averaging:

t = 0:1/Fs:20-1/Fs;
tPulse = 0:1/10:max(t);
tsa(x,Fs,tPulse)
xlim([10000 11000])
figure(6)
OUTPUT:

Power spectrum:

[p,e] = pspectrum(x);
plot(e/pi,p)
xlim([0 0.2])
figure(7)

SPECTRAL DENSITY:

pxx = pwelch(x)
plot(pxx)
xlim([0 1000])
title('psd')
figure(8)
RAHULGANHT E N
21BEE0092

OUTPUT:

EEG signal processing


Butterworth Bandpass Filter:

Zero-phase filtering using BPF Pass band between 0.1 to 30 Hz:

EEG while Awake:

plot(eega);
xlim([0 400])
title("EEG awake signal")
figure(1);
Fs=512;
Fn = Fs/2;
wp = [1 30]/Fn;
[b,a] = butter(1,wp);
[sos,g] = tf2sos(b,a);
figure(1);
freqz(sos, 240, Fs);
ppf = eega;
for i = 1:size(x,2);
tmp = ppf(:,i); tmp(tmp==0)=NaN;
tmp(isfinite(tmp)) = detrend(tmp(isfinite(tmp)));
ppf(:,i) = filter(b,a,tmp);
end
plot(ppf)
xlim([0 400])
title("Bandpass filter between 0.1 to 30 Hz")
figure(2)

pxx = pwelch(eega)
plot(pxx)
xlim([0 400])
title('psd')
figure(3)
RAHULGANHT E N
21BEE0092

OUTPUT:

EEG Asleep Signal:

plot(eegs);
xlim([0 400])
title("EEG sleep signal")
figure(1);
Fs=250;
Fn = Fs/2;
wp = [1 30]/Fn;
[b,a] = butter(1,wp);
[sos,g] = tf2sos(b,a);
freqz(sos, 240, Fs);
ppf = eegs;
for i = 1:size(x,2);
tmp = ppf(:,i); tmp(tmp==0)=NaN;
RAHULGANHT E N
21BEE0092
tmp(isfinite(tmp)) = detrend(tmp(isfinite(tmp)));
ppf(:,i) = filter(b,a,tmp);
end
plot(ppf)
xlim([0 400])
title("Bandpass filter between 0.1 to 30 Hz")
figure(2)

OUTPUT:
RAHULGANHT E N
21BEE0092

PSD using Welch estimate:

Power Spectral density for EEG Awake signal:

pxx = pwelch(eega)
plot(pxx)
xlim([0 400])
title('psd')
figure(3)

OUTPUT:
RAHULGANHT E N
21BEE0092

Power Spectral density for EEG Asleep signal:

pxx = pwelch(eegs)
plot(pxx)
xlim([0 300])
title('psd')
figure(8)

OUTPUT:
RAHULGANHT E N
21BEE0092

RESULT:

ECG and EEG signals have been processed.

You might also like