資源簡介
利用matlab對心電信號進行分析,具體為:讀取,插值,濾波,時域波形和頻域波形分析
代碼片段和文件信息
%4.1.1?提取txt格式心電信號
fid=fopen(‘122.txt‘);?
C=textscan(fid‘%8c?%f?%*f‘‘headerlines‘2);?
fclose(fid);?
a=C{1};?
y=C{2};?
?k=length(a)?
for?i=1:k?
c(i)=strread(a(i:)‘%*s?%f‘‘delimiter‘‘:‘);?
end?
x=c‘;?
plot(xy)?
%4.1.2對原始信號進行線性插值
t=0:0.001:2.5;?
F=interp1(xyt);?
F=F‘;?
t=t‘;?
plot(tF)
%4.1.3把數據讀到txt中?fid?=?fopen(‘t.txt‘‘wt‘);?
fid?=?fopen(‘t.txt‘‘wt‘);
fprintf(fid‘%g\n‘t);????????
fclose(fid);?
fid?=?fopen(‘F.txt‘‘wt‘);?
fprintf(fid‘%g\n‘F);????????
fclose(fid);?
%4.1.4插值前后波形比較?
subplot(221)?
plot(xy)?
title(‘初始信號時域波形‘)?
axis([0?2.5?-2?1])?
subplot(222)?
fs=1000;?
N=length(y)?
n=1:N;?
f1=n*fs/N;?
Y1=fft(y);?
plot(f1abs(Y1))?
title(‘初始信號頻譜‘)?
axis([0?1000?0?200])?
subplot(223)?
plot(tF)?
title(‘差值后信號時域波形‘)?
axis([0?2.5?-2?1])?
M=length(F);?
m=1:M;?
f2=m*fs/M;?
Y2=fft(F);?
subplot(224)?
plot(f2abs(Y2))?
title(‘插值后信號頻譜‘)?
axis([0?1000?0?200])?
%4.1.5模擬低通濾波器?
wp=60*2*pi;ws=99*2*pi;Rp=1;As=40;?
[Nwc]=buttord(wpwsRpAs‘s‘)?
[BA]=butter(Nwc‘s‘)?
k=0:511;fk=0:1000/512:1000;wk=2*pi*fk;?
Hk=freqs(BAwk);?
plot(fk20*log10(abs(Hk)));?
%4.1.6模擬高通濾波器?
wp=0.7*2*pi;ws=0.25*2*pi;Rp=0.1;As=40;?
[Nwc]=buttord(wpwsRpAs‘s‘)?
[B0A0]=butter(Nwc‘s‘);?
wph=2*pi*0.25;hk=freqs(B0A0wph);?
[BHAH]=lp2hp(BAwph);?
[hw]=freqs(BHAH);?
plot(w20*log10(abs(h)));?
axis([01-805]);?
%4.1.7濾波前后圖形對比?
t=0:0.001:9.997;?
F=interp1(xyt);?
F=F‘;?
t=t‘;?
figure(1)?
subplot(311);?
plot(1000*tF);?
wp=0.7*2*pi;ws=0.25*2*pi;Rp=0.1;As=40;T=1;?
[Nwc]=buttord(wpwsRpAs‘s‘)?
[BA]=butter(Nwc‘s‘);?
[ba]=imp_invr(BAT)?
[dbmagphaw]=freqz_m(ba);?
y1=filter(baF);?
subplot(312);plot(y1);?
title(‘高通濾波后‘)?
wp1=2*pi*60;ws1=2*pi*99;Rp1=0.1;As1=40;T1=1000;?
OmegaP1=wp1/T1;OmegaS1=ws1/T1;?
[cs1ds1]=afd_butt(OmegaP1OmegaS1Rp1As1);?
[b1a1]=imp_invr(cs1ds1T)?
[db1mag1pha1w1]=freqz_m(b1a1);?
y2=filter(b1a1y1);?
subplot(313);plot(y2);?
title(‘低通濾波后‘)?
M=length(F);?
m=1:M;?
fs=1000;?
f2=m*fs/M;?
F1=fft(F);?
Y1=fft(y1);?
Y2=fft(y2)?
figure(2)?
subplot(311)?
plot(f2abs(F1))?
axis([010000200])?
title(‘原始信號頻譜_{9.997}‘)?
subplot(312)?
plot(f2abs(Y1))?
axis([010000200])?
title(‘高通濾波后
評論
共有 條評論