function [PN, df] = fft_fun(fs, input_signal)
n = detrend(input_signal);
N = fft(n);
spect = 2*abs(N)/length(N);
PN = spect.^2;
df = fs/length(n);
f = 0:df:fs-df;
indf = (1:floor(length(f)/2));
figure
plot(f(indf),PN(indf));
xlabel('Hz')
ylabel('(Input Units)^2 / Hz')
end
Appendix 2b - Power-line Nose & High-Frequency Noise Removal (notch_fun.m)
function [signal] = notch_fun(input_signal)
fc = 1000;
fQf = 35;
NOf0 = 0;
bw = 0;
signal = input_signal;
while NOf0<fc/2-50,
NOf0 = NOf0+50;
wNO = NOf0/(fc/2);
bw = wNO/fQf;
[bNO,aNO] = iirnotch(wNO,bw);
signal = filter(bNO,aNO,signal);
end;
order = 50;
NOf0 = 40;
wNO = NOf0/(fc/2);
bNO = fir1(order,wNO);
signal = filter(bNO,1,signal);
order = 50;
NOf0 = 1;
wNO = NOf0/(fc/2);
bNO = fir1(order,wNO,'high');
signal = filtfilt(bNO,1,signal);
figure
subplot(2,1,1)
plot(input_signal)
title('Input ECG Signal')
subplot(2,1,2)
plot(signal)
title('Notch Filtered Signal')
end
Appendix 2c - Baseline Wandering Removal (blw_fun.m)
function [filtsignal] = blw_fun(tm,input_signal)
lamda = 0.98;
b = [1 -1];
a = [1 -lamda];
figure
freqz(b,a);
title('Filter Frequency Response')
filtsignal = filtfilt(b,a,input_signal);
figure
subplot(2,1,2)
plot(tm,filtsignal);
title('Baseline Wandering Corrected ECG Signal')
subplot(2,1,1)
plot(tm,input_signal);
title('Input ECG Signal')
end
Appendix 2d - Calculate SNR (snr_fun.m)
function [Pnoise, Psignal, SNR] = snr_fun(PN,df)
Pnoise = sum(PN(1:round(5/df)))/round(5/df) + sum(PN(1+round(15/df):end))/(round(500/df)-(1+round(15/df))) + PN(round(50/df));
Psignal = sum(PN(1+round(5/df):round(15/df)));
SNR = 10*log10(Psignal/Pnoise);
end
0 Comments
Sign in to comment.