function y=sinc_wavelet(x, dir)

S=size(x,1);
N=log2(S);
if (dir==1)
    %L=[1:S/4,3*S/4+1:S]; H=[S/4+1:3*S/4];
    L=[1:S/2]; H=[1:S/2]+S/2;
    X=dct2(x);
    X0=X(L,L); X1=X(L,H); X2=X(H,L); X3=X(H,H);
    x0=(idct2(X0)); 
    x1=(idct2(X1)); 
    x2=(idct2(X2)); 
    x3=(idct2(X3));
    
    y=[x0,x1;x2,x3];
    %y=X0;
else
    %L=[1:S/4,3*S/4+1:S]; H=[S/4+1:3*S/4];
    L=[1:S/2]; H=[1:S/2]+S/2;
    A=[1:S/2]; B=[1:S/2]+S/2;
    x=x;
    X0=dct2(x(A,A));
    X1=dct2(x(A,B));
    X2=dct2(x(B,A));
    X3=dct2(x(B,B));
    Y=zeros(S);
    Y(L,L)=X0;
    Y(L,H)=X1;
    Y(H,L)=X2;
    Y(H,H)=X3;
    y=real(idct2(Y));
end
