From: FAISAL PEER MOAHMED on
Hi

I am analyzing a data using discrete wavelet transform with the following code.

[C,L] = WAVEDEC(X,N,'wname')

Approximation coefficients are extracted from the above using the following function



A = APPCOEF(C,L,'wname',N)

I have read the "appcoef" code. In that I found that reconstruction filter is used to

get the approximation coefficient.

why is this so ?

Please help

Regards

Faisal
From: Wayne King on
"FAISAL PEER MOAHMED" <pfaisalbe(a)gmail.com> wrote in message <hrpi4b$6jq$1(a)fred.mathworks.com>...
> Hi
>
> I am analyzing a data using discrete wavelet transform with the following code.
>
> [C,L] = WAVEDEC(X,N,'wname')
>
> Approximation coefficients are extracted from the above using the following function
>
>
>
> A = APPCOEF(C,L,'wname',N)
>
> I have read the "appcoef" code. In that I found that reconstruction filter is used to
>
> get the approximation coefficient.
>
> why is this so ?
>
> Please help
>
> Regards
>

Hi Faisal, The reason is that when you perform a decimated wavelet transform on an input, all you end up with in terms of approximation coefficients are those at the terminal level. For example:

reset(RandStream.getDefaultStream);
x = randn(8,1);
dwtmode('per','nodisplay');
[C,L] = wavedec(x,3,'db1');

You have only a single approximation coefficient at level 3 in the output vector C and that is C(1). If you want the approximation coefficients at level 2, then you have to reconstruct to obtain those.

Hope that helps,
Wayne
From: FAISAL PEER MOAHMED on



Thanks , it is really appreciated.

So could I say it is a limitation of the function wavedec. I have a code for wavedec where i can get the appcoef directly from one function. It does not require any reconstruction filter. please see the code below


x = randn(1,100);
% x = x(:)';
wname ='db5'
[LPF HPF]= wfilters(wname,'d');
n=5 % No of decomposition level


lf = length(LPF);
lx = length(x);

% Extension and shifting of raw data before convolving with filter kernel

DWT_Attribute = getappdata(0,'DWT_Attribute');


if isempty(DWT_Attribute)
DWT_Attribute = dwtmode('get')
end

dwtEXTM = DWT_Attribute.extMode; % Default: Extension.
dwtshift = DWT_Attribute.shift1D; % Default: Shift.

% Extend the Raw data , Decompose & Extract coefficients.

first = 2-dwtshift;

if (dwtEXTM == 'per')

lenEXT = lf/2; last = 2*ceil(lx/2) % Defines the length of extension
else

lenEXT = lf-1; last = lx+lf-1 % Defines the length of extension

end


% Decomposition at multilevel starts here

for decomp = 1: n

% Signal (raw data) Extension
y= wextend('1D',dwtEXTM,x,lenEXT);

% Compute approximation and detail computation for the extended signal y

z1 = wconv1(y,LPF,'valid'); % Approximation Coefficient , Convoultion with filter kernel Low Pass filter
APP = z1(first:2:last); % Down sampling here(first:2:last) to get First Approximation Coefficient

x = size(APP);
x=APP; % Current approximation coefficient is the raw data
z2 = wconv1(y,HPF,'valid'); % Detail Coefficient , Convoultion with filter kernel High Pass filter
DET = z2(first:2:last); % Down sampling here(first:2:last) to get final DET Coefficient



lx=length(x);
if (dwtEXTM == 'per')
lenEXT = lf/2; last = 2*ceil(lx/2) % Defines the length of extension
else

lenEXT = lf-1; last = lx+lf-1 % Defines the length of extension

end



eval(['APP' num2str(decomp) ' = APP;']);
eval(['DET' num2str(decomp) ' = DET;']);

end
%##########################################################################



figure(2);
subplot(3,2,1), plot(DET1,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,2),plot(DET2,'r','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,3), plot(DET3,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,4),plot(DET4,'r','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,5), plot(DET5,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,6),plot(APP5,'r','Linewidth',2),title('Approximation Coefficient'),grid on


% Verification from Matlab Function

[C, L] =wavedec(corrupted,n,'db5');
% Approximate coefficients
cA5 = appcoef(C,L,'db1',5);
%Five detail co-efficients
cD5 = detcoef(C,L,5);
cD4 = detcoef(C,L,4);
cD3 = detcoef(C,L,3);
cD2 = detcoef(C,L,2);
cD1 = detcoef(C,L,1);


figure(3);
subplot(3,2,1), plot(cD1,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,2),plot(cD2,'r','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,3), plot(cD3,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,4),plot(cD4,'r','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,5), plot(cD5,'k','Linewidth',2),title('Detail Coefficient'),grid on
subplot(3,2,6),plot(cA5,'r','Linewidth',2),title('Approximation Coefficient'),grid on








Both gives exactly same results. This code is faster tham matlab's inbuilt

Please comment













"Wayne King" <wmkingty(a)gmail.com> wrote in message <hrpm1s$quj$1(a)fred.mathworks.com>...
> "FAISAL PEER MOAHMED" <pfaisalbe(a)gmail.com> wrote in message <hrpi4b$6jq$1(a)fred.mathworks.com>...
> > Hi
> >
> > I am analyzing a data using discrete wavelet transform with the following code.
> >
> > [C,L] = WAVEDEC(X,N,'wname')
> >
> > Approximation coefficients are extracted from the above using the following function
> >
> >
> >
> > A = APPCOEF(C,L,'wname',N)
> >
> > I have read the "appcoef" code. In that I found that reconstruction filter is used to
> >
> > get the approximation coefficient.
> >
> > why is this so ?
> >
> > Please help
> >
> > Regards
> >
>
> Hi Faisal, The reason is that when you perform a decimated wavelet transform on an input, all you end up with in terms of approximation coefficients are those at the terminal level. For example:
>
> reset(RandStream.getDefaultStream);
> x = randn(8,1);
> dwtmode('per','nodisplay');
> [C,L] = wavedec(x,3,'db1');
>
> You have only a single approximation coefficient at level 3 in the output vector C and that is C(1). If you want the approximation coefficients at level 2, then you have to reconstruct to obtain those.
>
> Hope that helps,
> Wayne