MATLAB: When i run the code, it generates error of type …………??? Index exceeds matrix dimensions. Error in ==> Dabachie at 42 a1=h0*s(2*​m)+h1*s(2*​m+1)+h2*s(​2*m+2)+h3*​s(2*m+3);.​……….​……….​i don’t know how to fix it. plz help me

clear all close all
t=0:1/1023:1; s = 20*t.^(2).*((1-t).^(4)).*(cos(12*pi*t)); plot(t,s); title('Origional Signal') %plot of first trend after haar wavelet transform ylabel('Amplitude') xlabel('Time')
if mod(length(s),2)~=0 s=[s 0]; end
d=length(s); m=1:d/2;
h0= (1+sqrt(3))/(4*(sqrt(2))); h1= (3+sqrt(3))/(4*(sqrt(2))); h2= (3-sqrt(3))/(4*(sqrt(2))); h3= (1-sqrt(3))/(4*(sqrt(2)));
g0=h3; g1=-h2; g2=h1; g3=-h0;
% %Daubechies Scaling Function a1=h0*s(2*m)+h1*s(2*m+1)+h2*s(2*m+2)+h3*s(2*m+3);
% %Daubechies Wavelet Function d1=g0*s(2*m)+g1*s(2*m+1)+g2*s(2*m+2)+g3*s(2*m+3);
figure() subplot(2,1,1) plot(t,s) title('Original Signal') %plot of the original signal ylabel('Amplitude') xlabel('Time') axis tight
subplot(2,1,2) plot(t,[a1 d1]) title('Transformed Signal') %plot of the final signal obtained after the transformation xlabel('Amplitude') ylabel('Time') axis tight

Best Answer

s has 1024 elements and m is a vector with a max value of 512. You're trying to get the 2*m+1 and when m = 512, this will refer to the 1025th element of s. But s doesn't have that many elements.