 clear all;
 close all;
  load S;                     %Definir Señal
  L=length(S);                  %tamaño Señal
% ETAPA 1 DESCOMPOSICION
% determinar filtros de descomposicion LD y HD
  [LD,HD]=wfilters('db8','d');
% calcular coeficientes de la aproximacion a1
  con_LD=conv(S,LD);
  a1=con_LD(2:2:length(con_LD)); %Downsampling
% calcular coeficientes del detalle d1
  con_HD=conv(S,HD);
  d1=con_HD(2:2:length(con_HD)); %Downsampling
%
% ETAPA 2 RECONSTRUCCION
% determinar filtros de reconstruccion LR y HR
  [LR,HR]=wfilters('db8','r');
% calcular la aproximacion a1 (ar1)
  ups = [zeros(1,length(a1));a1]; 
  ups = ups(:).';
  ups = ups(1:2*length(a1));     %Upsampling
  con_LR=conv(ups,LR);
  ar1=con_LR((length(HR)):(L+length(HR))-1);
% calcular el detalle d1 (dr1)
  ups = [zeros(1,length(d1));d1];
  ups = ups(:).';
  ups = ups(1:2*length(d1));     %Upsampling
  con_HR=conv(ups,HR);
  dr1=con_HR((length(HR)):(L+length(HR))-1);
%
% IDWT de la Señal S
  sr=ar1+dr1;


% ESTO NO VA
% TOOLBOX WAVELETS

[mod1,mod11]=wavedec(S,1,'db8');
ac=wrcoef('a',mod1,mod11,'db8',1);

[mod1,mod11]=wavedec(S,1,'db8');
dc=wrcoef('d',mod1,mod11,'db8',1);


% PLOTEO


plot(ar1);
hold;
plot(ac,'r');

