没有内置功能的小波分解和心电信号重构

时间:2018-10-11 07:43:47

标签: matlab windowing dwt

我已经完成了一维DWT分解,并计算出每个系数的能量和总能量。我应该使用滑动窗口并考虑256的二进位长度来执行DWT。窗口化应针对每个250ms数据点,我会收到一些错误消息,因为:下标索引必须为实数正整数或逻辑。

小波错误(第41行)     x2(1i)= Ya(k)

为方便起见,我在这里共享我的代码。关于其是否正确的任何建议?

clc;
data= importdata('215_5.txt');
x = data(:, 1);
y = data(:, 2);
plot(x, y, 'b-', 'LineWidth', 2);
N= length(y);
FreqS=360;  %sampling frequency
nyqfreq=FreqS/2;  %nyquist frequency
fft_signal= abs(fft(y));
figure(1); %plot single sided magnitude spectrum
x1=0:1/(N/2-1):1;
y1=fft_signal(1:N/2);
p1=line(x1,y1);
grid on;
ax1=gca; %current axis
axis([0 1 0 1]);
xlabel('Normalised frequency[\pi rads/sample]');
ylabel('magnitude');
fc=70;
fs=1000;
[b, a]= butter(4,fc/(fs/2));
H= freqz(b,a,N/2);
hold on;
x2=linspace(0,nyqfreq,100);
y2=abs(H);
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none');
ax2.XLabel.String = 'Frequency [Hz]';
title('Magnitude spectrum of signal and frequency response of filter');
x_filtered = filter(b,a,y);
hold off;
[Xa,Ya]= alignsignals(y,x_filtered);

V=[];
n= length (x_filtered);
n1= n/256;
%%wavelet decomposition
for i= 1:1:n1

    k=(i-1)+1i;
    x2(1i)=Ya(k);
    [c,l]=wavedec(x2,5,'db4');
    [cd1,cd2,cd3,cd4,cd5] = detcoef(c,l,[1 2 3 4 5]);
    A=appcoef(c,l,'db4');
    V1=[V;cd1];
    V2=[V;cd2];
    V3=[V;cd3];
    V4=[V;cd4];
    V5=[V;cd5];
    V6=[V;A];
    m1= sum(abs(V1).^2);
    m2= sum(abs(V2).^2);
    m3= sum(abs(V3).^2);
    m4= sum(abs(V4).^2);
    m5= sum(abs(V5).^2);
    m6= sum(abs(V6).^2);

    E= m1+m2+m3+m4+m5+m6;

end 

0 个答案:

没有答案