Effacer les filtres
Effacer les filtres

How to deal with this error ??

1 vue (au cours des 30 derniers jours)
Good mind
Good mind le 20 Mai 2017
Commenté : Walter Roberson le 21 Mai 2017
Error using + Matrix dimensions must agree. *Error in (line 77) y= d1w + d2w + aa2;
d1 and d2 are details coefficients at level 1 and 2 respectively. aa2 is the approximate coefficient at level 2
ech is an ecg signal
%wavelet decomposition
[C, L] = wavedec(ech, 2,'haar');
%extraction of approximate and detail coefficients of signal ech
aa2 = appcoef(C, L, 'haar', 2);
dd2 = detcoef(C, L, 2);
dd1= detcoef(C, L, 1);
%Wiener computations
s1=median(abs(d1))/.6745;
g1=((dd1).^2)/((dd1).^2)+((s1).^2);
d1w=repmat(d1(:), 1, size(d1)) .*g1;
s2=median(abs(d2))/.6745;
g2=((dd2).^2)/((dd2).^2)+((s2).^2);
d2w=repmat(d2(:), 1, size(d2)) .*g2;
%reconstruct the signal
subplot(3,2,5);
y= d1w + d2w + aa2;
plot(y,'k');
  2 commentaires
Walter Roberson
Walter Roberson le 20 Mai 2017
"ech is an ecg signal"
ecg signals are multiple channel, typically either 5 or 12. The code you are using requires that ech is a vector.
Your d1 is not defined in the code. Did you possibly intend to code dd1 instead of d1 ?
Good mind
Good mind le 21 Mai 2017
Modifié(e) : Good mind le 21 Mai 2017
clear all;
subplot(3,2,1);
load ecg.m;
plot(ecg); title ('ECG');
xlabel('samples'); ylabel('magnitude');
%wavelet decomposition
[C1, L1] = wavedec(ecg, 2,'haar');
%extraction of approximate and detail coefficients of signal
a2 = appcoef(C1, L1, 'haar', 2);
d2= detcoef(C1, L1,2);
d1= detcoef(C1, L1, 1);
% hard (h) thresholding
TM=1;
n2=length(d2);
s2=median(abs(d2))/.6745;
t2= TM*s2;
d2thard = wthresh(d2,'h',t2);
n1=length(d1);
s1=median(abs(d1))/.6745;
t1= TM*s1;
d1thard = wthresh(d1,'h',t1);
%wavelet coefficients after hard thresholding
hard_ua2 = upcoef('a',a2,'haar',2, 2000);
hard_ud2 = upcoef('d',d2thard,'haar',2, 2000);
hard_ud1 = upcoef('d',d1thard,'haar',1, 2000);
subplot(3,2,3);
ech= (hard_ud1 + hard_ud2 + hard_ua2);
plot(ech);title('ech the signal after hard thre');
%wavelet decomposition 2
[C, L] = wavedec(ech, 2,'haar');
%extraction of approximate and detail coefficients of signal ech
aa2 = appcoef(C, L, 'haar', 2);
dd2 = detcoef(C, L, 2);
dd1= detcoef(C, L, 1);
%Wiener computations
g1=((dd1).^2)/((dd1).^2)+((s1).^2);
d1w=repmat(d1(:), 1, size(d1)) .*g1;
g2=((dd2).^2)/((dd2).^2)+((s2).^2);
d2w=repmat(d2(:), 1, size(d2)) .*g2;
%reconstruct the signal
subplot(3,2,5);
y= d1w + d2w + a2;
plot(y,'k');

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 21 Mai 2017
You have
d1w=repmat(d1(:), 1, size(d1)) .*g1;
g2=((dd2).^2)/((dd2).^2)+((s2).^2);
d2w=repmat(d2(:), 1, size(d2)) .*g2;
size(d1) is a vector, so your repmat is working as if you had used repmat(d1(:), [1 1 500]) when you wanted repmat(d1(:), [1 500]) I guess. Same problem with your repmat for d2w. (Ah, I just realized that 500 is length(ecg)/2 )
When you get down to
y= d1w + d2w + a2
you run into the fundamental problem that arrays derived from d1 are length(x)/2 on a side, but arrays derived from d2 are length(x)/4 on a side. You will not be able to add them.
  4 commentaires
Good mind
Good mind le 21 Mai 2017
i used it (length instead size) before, but i got the same problem Error using + Matrix dimensions must agree.
Error in y= d1w + d2w+a2;
Walter Roberson
Walter Roberson le 21 Mai 2017
You are attempting to add matrices that are inherently differently sizes, one half the size of the other. You need to go back and figure out what you are trying to do there.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Discrete Multiresolution Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by