From: Aino on 24 Mar 2010 07:19 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hmll1o$8s9$1(a)fred.mathworks.com>... > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hmlfl9$n1g$1(a)fred.mathworks.com>... > > > Hi Aino, because the natural ordering of the wavelet packets as defined by the inductive process does not lead to wavelet packets with increasing zero crossings (analogous to frequency). For example, plot the first 7 (in natural ordering) Haar wavelet packets: > > > > > > [wfun,xgrid] = wpfun('haar',7,5); > > > for k=1:8 subplot(2,4,k); > > > plot(xgrid,wfun(k,:)); grid on; > > > title(['W ',num2str(k-1)]) > > > end > > > > > > Count the number of zero crossings in the Haar wavelet packets. See how the natural ordering does not correspond to an increasing number of zero crossings? > > > > > > If you are using the wavemenu GUI, you can view a frequency ordering. You can also do this via the command line with wpviewcf > > > > > > x = sin(8*pi*[0:0.005:1]); > > > T = wpdec(x,4,'db1'); > > > wpviewcf(T,1) > > > > > > Hope that helps, > > > Wayne > > > > Hi, > > > > thank you for your quick reply. I can see from your reply that I still have a lot to understand about wavelet packets.. The reason why I asked about the order of the nodes had to do with the way that I am used to plot them. Matlab has those plots that have only one column in the plot, like in your last example. I made a little code that plots the tree as it is structured: > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > %Original signal with two main frequencies > > t=1:128; > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > figure;plot(t,y) > > > > %WPT > > level=5; > > wpt = wpdec(y,level,'haar'); > > > > TheMatrix=nan(2^level, level+1); > > for i=0:level > > stop=2^i-1; > > parts=2^level/2^i; > > > > for j=0:stop > > > > first=i*2^level+1; > > start =parts*j+first; > > stop=parts*(j+1)+first-1; > > > > y=wpcoef(wpt, [i j]); > > > > %Average energy > > E=1/(length(y))*dot(y,y); > > TheMatrix(start:stop)=E; > > > > end > > end > > > > TheMatrix=TheMatrix'; > > figure;imagesc(TheMatrix) > > colormap(gray) > > colorbar > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > If the nodes would be organized as I suggested in my first post, the last row in the imagesc figure should have only two highlighted parts corresponding to the two frequencies of the original signal. Now the picture is a bit more scrambled. Is there any way of getting the two frequencies shown in the last row? > > > > -Aino > > Hi Aino, if you want to see the two sine waves that last the entire duration of your time interval clearly why not use wpviewcf? > > t=1:128; > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > wpt = wpdec(y,level,'haar'); > wpviewcf(wpt,1) > > Wayne Hi again, I believe that wpviewcf only shows the last row of the WPD. I need to see the whole tree in my application. What I am supposed to do is the same thing as in this link in Fig. 2: http://www.bearcave.com/misl/misl_tech/wavelets/packfreq/index.html I just can't figure out the right way of coding that. -Aino
From: Wayne King on 24 Mar 2010 07:33 "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hocsf9$637$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hmll1o$8s9$1(a)fred.mathworks.com>... > > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hmlfl9$n1g$1(a)fred.mathworks.com>... > > > > Hi Aino, because the natural ordering of the wavelet packets as defined by the inductive process does not lead to wavelet packets with increasing zero crossings (analogous to frequency). For example, plot the first 7 (in natural ordering) Haar wavelet packets: > > > > > > > > [wfun,xgrid] = wpfun('haar',7,5); > > > > for k=1:8 subplot(2,4,k); > > > > plot(xgrid,wfun(k,:)); grid on; > > > > title(['W ',num2str(k-1)]) > > > > end > > > > > > > > Count the number of zero crossings in the Haar wavelet packets. See how the natural ordering does not correspond to an increasing number of zero crossings? > > > > > > > > If you are using the wavemenu GUI, you can view a frequency ordering. You can also do this via the command line with wpviewcf > > > > > > > > x = sin(8*pi*[0:0.005:1]); > > > > T = wpdec(x,4,'db1'); > > > > wpviewcf(T,1) > > > > > > > > Hope that helps, > > > > Wayne > > > > > > Hi, > > > > > > thank you for your quick reply. I can see from your reply that I still have a lot to understand about wavelet packets.. The reason why I asked about the order of the nodes had to do with the way that I am used to plot them. Matlab has those plots that have only one column in the plot, like in your last example. I made a little code that plots the tree as it is structured: > > > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > %Original signal with two main frequencies > > > t=1:128; > > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > > figure;plot(t,y) > > > > > > %WPT > > > level=5; > > > wpt = wpdec(y,level,'haar'); > > > > > > TheMatrix=nan(2^level, level+1); > > > for i=0:level > > > stop=2^i-1; > > > parts=2^level/2^i; > > > > > > for j=0:stop > > > > > > first=i*2^level+1; > > > start =parts*j+first; > > > stop=parts*(j+1)+first-1; > > > > > > y=wpcoef(wpt, [i j]); > > > > > > %Average energy > > > E=1/(length(y))*dot(y,y); > > > TheMatrix(start:stop)=E; > > > > > > end > > > end > > > > > > TheMatrix=TheMatrix'; > > > figure;imagesc(TheMatrix) > > > colormap(gray) > > > colorbar > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > > > If the nodes would be organized as I suggested in my first post, the last row in the imagesc figure should have only two highlighted parts corresponding to the two frequencies of the original signal. Now the picture is a bit more scrambled. Is there any way of getting the two frequencies shown in the last row? > > > > > > -Aino > > > > Hi Aino, if you want to see the two sine waves that last the entire duration of your time interval clearly why not use wpviewcf? > > > > t=1:128; > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > wpt = wpdec(y,level,'haar'); > > wpviewcf(wpt,1) > > > > Wayne > > Hi again, > I believe that wpviewcf only shows the last row of the WPD. I need to see the whole tree in my application. What I am supposed to do is the same thing as in this link in Fig. 2: > > http://www.bearcave.com/misl/misl_tech/wavelets/packfreq/index.html > > I just can't figure out the right way of coding that. > > -Aino Hi Aino, You can certainly do those kinds of plots, but you're going to have to pull out the wavelet packet coefficients and store them in a matrix. The trickiest thing is that you have to remember that you are using a decimated wavelet packet transform, so you're going to have to correctly space the coefficients at the coarser scales. The reason wpviewcf() only plots the terminal nodes is because that is the finest frequency-based partition of the interval [0,Fs/2]. Just a question: if you are really looking to analyze the time-frequency behavior of a signal, why do you need anything but the terminal nodes of the tree? Wayne
From: Aino on 24 Mar 2010 09:28 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hmll1o$8s9$1(a)fred.mathworks.com>... > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hmlfl9$n1g$1(a)fred.mathworks.com>... > > > Hi Aino, because the natural ordering of the wavelet packets as defined by the inductive process does not lead to wavelet packets with increasing zero crossings (analogous to frequency). For example, plot the first 7 (in natural ordering) Haar wavelet packets: > > > > > > [wfun,xgrid] = wpfun('haar',7,5); > > > for k=1:8 subplot(2,4,k); > > > plot(xgrid,wfun(k,:)); grid on; > > > title(['W ',num2str(k-1)]) > > > end > > > > > > Count the number of zero crossings in the Haar wavelet packets. See how the natural ordering does not correspond to an increasing number of zero crossings? > > > > > > If you are using the wavemenu GUI, you can view a frequency ordering. You can also do this via the command line with wpviewcf > > > > > > x = sin(8*pi*[0:0.005:1]); > > > T = wpdec(x,4,'db1'); > > > wpviewcf(T,1) > > > > > > Hope that helps, > > > Wayne > > > > Hi, > > > > thank you for your quick reply. I can see from your reply that I still have a lot to understand about wavelet packets.. The reason why I asked about the order of the nodes had to do with the way that I am used to plot them. Matlab has those plots that have only one column in the plot, like in your last example. I made a little code that plots the tree as it is structured: > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > %Original signal with two main frequencies > > t=1:128; > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > figure;plot(t,y) > > > > %WPT > > level=5; > > wpt = wpdec(y,level,'haar'); > > > > TheMatrix=nan(2^level, level+1); > > for i=0:level > > stop=2^i-1; > > parts=2^level/2^i; > > > > for j=0:stop > > > > first=i*2^level+1; > > start =parts*j+first; > > stop=parts*(j+1)+first-1; > > > > y=wpcoef(wpt, [i j]); > > > > %Average energy > > E=1/(length(y))*dot(y,y); > > TheMatrix(start:stop)=E; > > > > end > > end > > > > TheMatrix=TheMatrix'; > > figure;imagesc(TheMatrix) > > colormap(gray) > > colorbar > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > If the nodes would be organized as I suggested in my first post, the last row in the imagesc figure should have only two highlighted parts corresponding to the two frequencies of the original signal. Now the picture is a bit more scrambled. Is there any way of getting the two frequencies shown in the last row? > > > > -Aino > > Hi Aino, if you want to see the two sine waves that last the entire duration of your time interval clearly why not use wpviewcf? > > t=1:128; > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > wpt = wpdec(y,level,'haar'); > wpviewcf(wpt,1) > > Wayne Hi again, I believe that wpviewcf only shows the last row of the WPD. I need to see the whole tree in my application. What I am supposed to do is the same thing as in this link in Fig. 2: http://www.bearcave.com/misl/misl_tech/wavelets/packfreq/index.html I just can't figure out the right way of coding that. -Aino
From: Wayne King on 24 Mar 2010 10:15 "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hod412$8q7$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hmll1o$8s9$1(a)fred.mathworks.com>... > > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hmlfl9$n1g$1(a)fred.mathworks.com>... > > > > Hi Aino, because the natural ordering of the wavelet packets as defined by the inductive process does not lead to wavelet packets with increasing zero crossings (analogous to frequency). For example, plot the first 7 (in natural ordering) Haar wavelet packets: > > > > > > > > [wfun,xgrid] = wpfun('haar',7,5); > > > > for k=1:8 subplot(2,4,k); > > > > plot(xgrid,wfun(k,:)); grid on; > > > > title(['W ',num2str(k-1)]) > > > > end > > > > > > > > Count the number of zero crossings in the Haar wavelet packets. See how the natural ordering does not correspond to an increasing number of zero crossings? > > > > > > > > If you are using the wavemenu GUI, you can view a frequency ordering. You can also do this via the command line with wpviewcf > > > > > > > > x = sin(8*pi*[0:0.005:1]); > > > > T = wpdec(x,4,'db1'); > > > > wpviewcf(T,1) > > > > > > > > Hope that helps, > > > > Wayne > > > > > > Hi, > > > > > > thank you for your quick reply. I can see from your reply that I still have a lot to understand about wavelet packets.. The reason why I asked about the order of the nodes had to do with the way that I am used to plot them. Matlab has those plots that have only one column in the plot, like in your last example. I made a little code that plots the tree as it is structured: > > > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > %Original signal with two main frequencies > > > t=1:128; > > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > > figure;plot(t,y) > > > > > > %WPT > > > level=5; > > > wpt = wpdec(y,level,'haar'); > > > > > > TheMatrix=nan(2^level, level+1); > > > for i=0:level > > > stop=2^i-1; > > > parts=2^level/2^i; > > > > > > for j=0:stop > > > > > > first=i*2^level+1; > > > start =parts*j+first; > > > stop=parts*(j+1)+first-1; > > > > > > y=wpcoef(wpt, [i j]); > > > > > > %Average energy > > > E=1/(length(y))*dot(y,y); > > > TheMatrix(start:stop)=E; > > > > > > end > > > end > > > > > > TheMatrix=TheMatrix'; > > > figure;imagesc(TheMatrix) > > > colormap(gray) > > > colorbar > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > > > If the nodes would be organized as I suggested in my first post, the last row in the imagesc figure should have only two highlighted parts corresponding to the two frequencies of the original signal. Now the picture is a bit more scrambled. Is there any way of getting the two frequencies shown in the last row? > > > > > > -Aino > > > > Hi Aino, if you want to see the two sine waves that last the entire duration of your time interval clearly why not use wpviewcf? > > > > t=1:128; > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > wpt = wpdec(y,level,'haar'); > > wpviewcf(wpt,1) > > > > Wayne > > Hi again, > I believe that wpviewcf only shows the last row of the WPD. I need to see the whole tree in my application. What I am supposed to do is the same thing as in this link in Fig. 2: > > http://www.bearcave.com/misl/misl_tech/wavelets/packfreq/index.html > > I just can't figure out the right way of coding that. > > -Aino Hi Aino, I can't see where you posted anything new. Did you see my earlier comment: %%%% Hi Aino, You can certainly do those kinds of plots, but you're going to have to pull out the wavelet packet coefficients and store them in a matrix. The trickiest thing is that you have to remember that you are using a decimated wavelet packet transform, so you're going to have to correctly space the coefficients at the coarser scales. The reason wpviewcf() only plots the terminal nodes is because that is the finest frequency-based partition of the interval [0,Fs/2]. Just a question: if you are really looking to analyze the time-frequency behavior of a signal, why do you need anything but the terminal nodes of the tree? Wayne
From: Aino on 24 Mar 2010 10:39
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hod6pp$rr7$1(a)fred.mathworks.com>... > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hod412$8q7$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hmll1o$8s9$1(a)fred.mathworks.com>... > > > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <hmlfl9$n1g$1(a)fred.mathworks.com>... > > > > > Hi Aino, because the natural ordering of the wavelet packets as defined by the inductive process does not lead to wavelet packets with increasing zero crossings (analogous to frequency). For example, plot the first 7 (in natural ordering) Haar wavelet packets: > > > > > > > > > > [wfun,xgrid] = wpfun('haar',7,5); > > > > > for k=1:8 subplot(2,4,k); > > > > > plot(xgrid,wfun(k,:)); grid on; > > > > > title(['W ',num2str(k-1)]) > > > > > end > > > > > > > > > > Count the number of zero crossings in the Haar wavelet packets. See how the natural ordering does not correspond to an increasing number of zero crossings? > > > > > > > > > > If you are using the wavemenu GUI, you can view a frequency ordering. You can also do this via the command line with wpviewcf > > > > > > > > > > x = sin(8*pi*[0:0.005:1]); > > > > > T = wpdec(x,4,'db1'); > > > > > wpviewcf(T,1) > > > > > > > > > > Hope that helps, > > > > > Wayne > > > > > > > > Hi, > > > > > > > > thank you for your quick reply. I can see from your reply that I still have a lot to understand about wavelet packets.. The reason why I asked about the order of the nodes had to do with the way that I am used to plot them. Matlab has those plots that have only one column in the plot, like in your last example. I made a little code that plots the tree as it is structured: > > > > > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > %Original signal with two main frequencies > > > > t=1:128; > > > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > > > figure;plot(t,y) > > > > > > > > %WPT > > > > level=5; > > > > wpt = wpdec(y,level,'haar'); > > > > > > > > TheMatrix=nan(2^level, level+1); > > > > for i=0:level > > > > stop=2^i-1; > > > > parts=2^level/2^i; > > > > > > > > for j=0:stop > > > > > > > > first=i*2^level+1; > > > > start =parts*j+first; > > > > stop=parts*(j+1)+first-1; > > > > > > > > y=wpcoef(wpt, [i j]); > > > > > > > > %Average energy > > > > E=1/(length(y))*dot(y,y); > > > > TheMatrix(start:stop)=E; > > > > > > > > end > > > > end > > > > > > > > TheMatrix=TheMatrix'; > > > > figure;imagesc(TheMatrix) > > > > colormap(gray) > > > > colorbar > > > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > > > > > > > If the nodes would be organized as I suggested in my first post, the last row in the imagesc figure should have only two highlighted parts corresponding to the two frequencies of the original signal. Now the picture is a bit more scrambled. Is there any way of getting the two frequencies shown in the last row? > > > > > > > > -Aino > > > > > > Hi Aino, if you want to see the two sine waves that last the entire duration of your time interval clearly why not use wpviewcf? > > > > > > t=1:128; > > > y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t); > > > wpt = wpdec(y,level,'haar'); > > > wpviewcf(wpt,1) > > > > > > Wayne > > > > Hi again, > > I believe that wpviewcf only shows the last row of the WPD. I need to see the whole tree in my application. What I am supposed to do is the same thing as in this link in Fig. 2: > > > > http://www.bearcave.com/misl/misl_tech/wavelets/packfreq/index.html > > > > I just can't figure out the right way of coding that. > > > > -Aino > > Hi Aino, I can't see where you posted anything new. Did you see my earlier comment: > %%%% > Hi Aino, You can certainly do those kinds of plots, but you're going to have to pull out the wavelet packet coefficients and store them in a matrix. The trickiest thing is that you have to remember that you are using a decimated wavelet packet transform, so you're going to have to correctly space the coefficients at the coarser scales. The reason wpviewcf() only plots the terminal nodes is because that is the finest frequency-based partition of the interval [0,Fs/2]. > > Just a question: if you are really looking to analyze the time-frequency behavior of a signal, why do you need anything but the terminal nodes of the tree? > > Wayne Hi, I am doing classification between different signals and I am trying to find a feature vector that would best separate the signals. I am using some of the terminal nodes (all is a bit too much) as a feature vector and also trying to find out if there would be other set of nodes (perhaps not the terminal ones) best separating the signals. Also, I have a presentation about the subject and I would need the figure there. I made a little (not too sophisticated ;)) piece of code that should do the trick. The signal with only one frequency seems to do fine, but I can't figure out why the second signal with two frequencies has kind of a third frequency seen in the figure. Is this normal, or is there an error in my code? I have a model picture of how the figure should look like, but it is so bad that I can't tell.. Here is the code: _________________________________________________________________ %Original signal t=1:128; % y=sin(2*pi*1/4*t)+sin(2*pi*1/8*t);%with two frequencies.. y=sin(2*pi*1/4*t);%and with one frequency. figure;subplot(2,1,1);plot(t,y); %WPT level=7; wpt = wpdec(y,level,'haar'); FreqOrder=1; TheMatrix=nan(2^level, level+1); for i=0:level stop=2^i-1; parts=2^level/2^i; for j=0:stop first=i*2^level+1; start =parts*j+first; stop=parts*(j+1)+first-1; y=wpcoef(wpt, [i j]); %Average energy (makes the job a bit easier..) E=1/(length(y))*dot(y,y); TheMatrix(start:stop)=E; end end TheMatrix=TheMatrix'; Matrix=TheMatrix; if FreqOrder==1 cols=length(TheMatrix(1,:)); for i=3:level+1 parts=2^(i-1);%How many parts in that level part_length=cols/parts;%How many columns in one part first=-2*part_length+1; for j=1:parts/4%This many section pairs need to be converted first=first+4*part_length; second=first+part_length; Matrix(i:end,first:first+part_length-1)=TheMatrix(i:end,second:second+part_length-1); Matrix(i:end,second:second+part_length-1)=TheMatrix(i:end,first:first+part_length-1); end TheMatrix=Matrix; % figure;imagesc(TheMatrix) end else Matrix=TheMatrix; end subplot(2,1,2);imagesc(Matrix) colorbar __________________________________________________________________ -Aino |