wavelet matlab plotting error

I have a simple signal x(t)=2*cos(2*pi*500*t); I use wavelet wavedec(x,9,'db4') ; when I plot "ap9 = [0- 9.76]Hz" I must found zero because my signal is 500 Hz ; but the first and last second dnot equal to zero; why?
clear all;clc;
t(1)=0; va(1)=0; vb(1)=0; vc(1)=0; x(1)=0;
for i=2:100000
t(i)=t(i-1)+1e-4; %fs=10000
x(i)=2*cos(2*pi*500*t(i));
end
%wavelet
fs=10000;
[c,l]=wavedec(x,9,'db4');
ap9=appcoef(c,l,'db4',9);
L=max(size(x));
sized=max(size(ap9));
Ts=1/10000;
timemax=Ts*L;
ta=linspace(0,timemax,sized);
figure(3)
plot(ta,abs(ap9))

4 Comments

Could you explain the connection between ap9 and 0 to 9.76 Hz ? I see you asking for level 9 in the code, but I do not understand how you get the 9.76 from your code?
help me Sir
please help me
I do not have enough experience with wavelets to know what you are encountering this problem.

Sign in to comment.

Answers (1)

Rodney Tan
Rodney Tan on 12 Oct 2016
Edited: Rodney Tan on 12 Oct 2016
The spike appeared at the start and end is the wavelet boundary effect of any given signal. It is cause by zero padding that taken into account at the start and end of the signal where wavelet decomposition computation took place. This is because wavelet is effective to pick up any abrupt changes for a given signal. You need to mirror your signal by using padarray command, then perform your wavelet decomposition, this eliminate the boundary effect.
padarray example
signal = 1:10
mirrorpadsignal = padarray(signal,[0 3],'symmetric','both')
Please be inform your padding size may need to be long [0 10] or more depend on the type of mother wavelet you use.
Hope I answer your question.

3 Comments

thank you Sir for your answer but I found same error this is my new program
clear all;clc;
t(1)=0; va(1)=0; vb(1)=0; vc(1)=0; x(1)=0;
for i=2:100000
t(i)=t(i-1)+1e-4; %fs=10000
x(i)=2*cos(2*pi*500*t(i));
end
%My signal is x
mirrorpadsignal = padarray(x,[0 3],'symmetric','both');
figure(1)
plot (mirrorpadsignal)
xx=mirrorpadsignal;
%wavelet
fs=10000;
[c,l]=wavedec(xx,9,'db4');
ap9=appcoef(c,l,'db4',9);
L=max(size(xx));
sized=max(size(ap9));
Ts=1/10000;
timemax=Ts*L;
ta=linspace(0,timemax,sized);
figure(2)
plot(ta,abs(ap9))
help me
You could click on http://www.mathworks.com/matlabcentral/profile/contact/6664770-rodney-tan to send email to Rodney Tan to ask Rodney to return to the question.
I do not know nearly enough about wavelets to be able to answer the question. It would probably take me several days of studying, perhaps a couple of weeks of studying, to answer your question. That is not something I have the resources for.

Sign in to comment.

Categories

Find more on Get Started with Wavelet Toolbox in Help Center and File Exchange

Asked:

on 10 Oct 2016

Commented:

on 15 Oct 2016

Community Treasure Hunt

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

Start Hunting!