Các phương pháp thích nghi trong lọc nhiễu tín hiệu điện tim - 16


Phụ lục

Mã chương trình thực nghiệm

Ngôn ngữ: Matlab


Chương trình so sánh, đánh giá thuật toán LMS kích thước bước cố định và thay đổi

clear all;close all; [ecg]=ecg_generator; L=length(ecg);sigma=0.15;ms=2; mu_002=0.05;

mu_05=0.5; [Noise_sin,Noise_cos]=gnoise(sigma,L,ms); N=Noise_sin+normrnd(0,0.01,1,L); NOISY_ECG=ecg+N;


[denoised_ecg_FS_002,dieukien_002]=LMS_fixed_stepsize(NOISY_ECG,Noise_s in,Noise_cos,mu_002);

Có thể bạn quan tâm!

Xem toàn bộ 130 trang tài liệu này.

for k=0:(L/4-1)

mse_mu_002(k+1)=((ecg(4*k+1)-denoised_ecg_FS_002(4*k+1))^2 + (ecg(4*k+2)-denoised_ecg_FS_002(4*k+2))^2 +(ecg(4*k+3)- denoised_ecg_FS_002(4*k+3))^2 +(ecg(4*k+4)- denoised_ecg_FS_002(4*k+4))^2)/4;

Các phương pháp thích nghi trong lọc nhiễu tín hiệu điện tim - 16

end;


[denoised_ecg_FS_05,dieukien_05]=LMS_fixed_stepsize(NOISY_ECG,Noise_sin, Noise_cos,mu_05);

for k=0:(L/4-1)

mse_mu_05(k+1)=((ecg(4*k+1)-denoised_ecg_FS_05(4*k+1))^2 + (ecg(4*k+2)- denoised_ecg_FS_05(4*k+2))^2 +(ecg(4*k+3)-denoised_ecg_FS_05(4*k+3))^2

+(ecg(4*k+4)-denoised_ecg_FS_05(4*k+4))^2)/4; end;


[denoised_ecg_VS]=LMS_variable_stepsize(NOISY_ECG,Noise_sin,Noise_cos,ec g);

for k=0:(L/4-1)

mse_mu_vs(k+1)=((ecg(4*k+1)-denoised_ecg_VS(4*k+1))^2 + (ecg(4*k+2)- denoised_ecg_VS(4*k+2))^2 +(ecg(4*k+3)-denoised_ecg_VS(4*k+3))^2

+(ecg(4*k+4)-denoised_ecg_VS(4*k+4))^2)/4; end;


nn = 4:4:L;


plot(nn,mse_mu_002,'b',nn,mse_mu_05,'r',nn,mse_mu_vs,'y');axis([0 2000 0 0.014]);ylabel('MSE');xlabel('i');title('Sai so trung binh binh phuong truong hop kich thuoc buoc thich nghi co dinh va thay doi');pause;

%subplot(2,3,4);

%subplot(2,3,5);

%subplot(2,3,6);

subplot(1,3,1);plot(nn,mse_mu_002,'b');title('Truong hop kich thuoc buoc thich nghi co dinh =0.05');ylabel('MSE');xlabel('t'); subplot(1,3,2);plot(nn,mse_mu_05,'r');title('Truong hop kich thuoc buoc thich nghi co dinh =0.5');ylabel('MSE');xlabel('t'); subplot(1,3,3);plot(nn,mse_mu_vs,'y');title('Truong hop kich thuoc buoc thich nghi thay doi');ylabel('MSE');xlabel('t');

pause;

plot(nn,mse_mu_002,'b');title('Sai so trung binh binh phuong truong hop kich thuoc buoc thich nghi co dinh =0.05');ylabel('MSE');xlabel('t');%axis([-50 1860 -0.01 0.57]);


pause;

plot(nn,mse_mu_05,'r');title('Sai so trung binh binh phuong truong hop kich thuoc buoc thich nghi co dinh =0.5');ylabel('MSE');xlabel('t');%axis([-50 1860 -0.01 0.57]);


pause;

plot(nn,mse_mu_vs,'y');title('Sai so trung binh binh phuong truong hop kich thuoc buoc thich nghi thay doi');ylabel('MSE');xlabel('t');%axis([-50 1860 -0.01 0.57]); pause;


% in ra tin hieu sau loc, truong hop KT buoc thich nghi co dinh = 0.05 subplot(3,1,1);plot(denoised_ecg_FS_002(1:L/4));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.05');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(1:L/4));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]); subplot(3,1,3);plot(NOISY_ECG(1:L/4));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);

pause;


subplot(3,1,1);plot(denoised_ecg_FS_002(L/4+1:L/2));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.05 (Tiep theo)');axis([1 L/4 -3 1]);

subplot(3,1,2);plot(ecg(L/4+1:L/2));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/4+1:L/2));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_FS_002(L/2+1:0.75*L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.05 (Tiep theo)');axis([1 L/4 -3 1]);

subplot(3,1,2);plot(ecg(L/2:0.75*L));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/2+1:0.75*L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_FS_002(0.75*L+1:L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.05 (Tiep theo)');axis([1 L/4 -3 1]);

subplot(3,1,2);plot(ecg(0.75*L+1:L));title('Tin hieu dien tam do sach');axis([1 L/4 - 3 1]);

subplot(3,1,3);plot(NOISY_ECG(0.75*L+1:L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


% in ra tin hieu sau loc, truong hop KT buoc thich nghi co dinh = 0.5 subplot(3,1,1);plot(denoised_ecg_FS_05(1:L/4));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.5');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(1:L/4));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]); subplot(3,1,3);plot(NOISY_ECG(1:L/4));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);

pause;


subplot(3,1,1);plot(denoised_ecg_FS_05(L/4+1:L/2));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.5 (Tiep theo)');axis([1 L/4 -3 1]);

subplot(3,1,2);plot(ecg(L/4+1:L/2));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/4+1:L/2));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_FS_05(L/2+1:0.75*L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.5 (Tiep theo)');axis([1 L/4

-3 1]);

subplot(3,1,2);plot(ecg(L/2:0.75*L));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/2+1:0.75*L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_FS_05(0.75*L+1:L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi co dinh =0.5 (Tiep theo)');axis([1 L/4

-3 1]);


subplot(3,1,2);plot(ecg(0.75*L+1:L));title('Tin hieu dien tam do sach');axis([1 L/4 - 3 1]);

subplot(3,1,3);plot(NOISY_ECG(0.75*L+1:L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


% in ra tin hieu sau loc, truong hop KT buoc thich nghi thay doi subplot(3,1,1);plot(denoised_ecg_VS(1:L/4));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi thay doi');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(1:L/4));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]); subplot(3,1,3);plot(NOISY_ECG(1:L/4));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);

pause;


subplot(3,1,1);plot(denoised_ecg_VS(L/4+1:L/2));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi thay doi');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(L/4+1:L/2));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/4+1:L/2));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_VS(L/2+1:0.75*L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi thay doi');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(L/2:0.75*L));title('Tin hieu dien tam do sach');axis([1 L/4 -3 1]);

subplot(3,1,3);plot(NOISY_ECG(L/2+1:0.75*L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


subplot(3,1,1);plot(denoised_ecg_VS(0.75*L+1:L));title('Tin hieu dien tam do sau loc, truong hop kich thuoc buoc thich nghi thay doi');axis([1 L/4 -3 1]); subplot(3,1,2);plot(ecg(0.75*L+1:L));title('Tin hieu dien tam do sach');axis([1 L/4 - 3 1]);

subplot(3,1,3);plot(NOISY_ECG(0.75*L+1:L));title('Tin hieu dien tam do nhiem nhieu');axis([1 L/4 -3 1]);pause;


close all; plot(dieukien_002); pause; plot(dieukien_05);

[denoised_ecg_VS_Daniel]=LMS_variable_stepsize_Daniel(NOISY_ECG,Noise_s in,Noise_cos,ecg);

for k=0:(L/4-1)

mse_mu_vs_Daniel(k+1)=((ecg(4*k+1)-denoised_ecg_VS_Daniel(4*k+1))^2 + (ecg(4*k+2)-denoised_ecg_VS_Daniel(4*k+2))^2 +(ecg(4*k+3)-


denoised_ecg_VS_Daniel(4*k+3))^2 +(ecg(4*k+4)- denoised_ecg_VS_Daniel(4*k+4))^2)/4;

end; plot(mse_mu_vs_Daniel); pause;

plot(nn,mse_mu_002,'b',nn,mse_mu_05,'r',nn,mse_mu_vs,'y',nn,mse_mu_vs_Danie l,'k');axis([-50 1860 -0.01 0.57]);title('Sai so trung binh binh phuong cua 4 truong hop');

ylabel('MSE');xlabel('t');


Hàm thực hiện bộ lọc bằng thuật toán LMS với kích thước bước

thích nghi cố định


function [denoised_ecg,dieukien]=LMS_fixed_stepsize(NOISY_ECG,Noise_sin,Noise_cos, mu)

w1=0;w2=0;

l=length(NOISY_ECG); y(1)=0.15;

for k=2:l y(k)=(Noise_sin(k)*w1+Noise_cos(k)*w2); denoised_ecg(k)=NOISY_ECG(k)-y(k); w1=w1+2*mu*Noise_sin(k)*denoised_ecg(k); w2=w2+2*mu*Noise_cos(k)*denoised_ecg(k);

dieukien(k)=((NOISY_ECG(k)*(Noise_sin(k)-y(k)))+(NOISY_ECG(k- 1)*(Noise_sin(k-1)-y(k-1))))/2;

end;


Hàm thực hiện bộ lọc bằng thuật toán LMS với kích thước bước thích nghi thay đổi theo đề xuất của chúng tôi

function [denoised_ecg,mu_dem]=LMS_variable_stepsize_14_4(NOISY_ECG,Noise_sin,N oise_cos,ecg)

w1=0;w2=0;mu=2.9;

l=length(NOISY_ECG); mu_dem=zeros(1,l); alpha=25.5;

%alpha=2; for k=1:l

denoised_ecg(k)=NOISY_ECG(k)-(Noise_sin(k)*w1+Noise_cos(k)*w2);


mu=alpha*abs(denoised_ecg(k)*Noise_sin(k)); w1=w1+mu*Noise_sin(k)*denoised_ecg(k); w2=w2+mu*Noise_cos(k)*denoised_ecg(k); mu_dem(k)=mu;

end;


Hàm thực hiện bộ lọc bằng thuật toán LMS với kích thước bước thích nghi thay đổi theo đề xuất của Daniel trong [29]

function [denoised_ecg]=LMS_variable_stepsize_daniel(NOISY_ECG,Noise_sin,Noise_cos

,ecg) w1=0;w2=0;mu=0.5;

l=length(NOISY_ECG); for k=1:l

denoised_ecg(k)=NOISY_ECG(k)-(Noise_sin(k)*w1+Noise_cos(k)*w2); mu=0.9*mu+0.9*denoised_ecg(k)^2; w1=w1+mu*Noise_sin(k)*denoised_ecg(k); w2=w2+mu*Noise_cos(k)*denoised_ecg(k);

end;

..... Xem trang tiếp theo?
⇦ Trang trước - Trang tiếp theo ⇨

Ngày đăng: 21/11/2022