classdef symm

methods(Static)

    function qmf = quad_mirror_filter(num_vanishing_moments)
        % Generates orthonormal quadrature mirror filter for Symmlets
        switch num_vanishing_moments
            case 4
                qmf = [   -.107148901418  -.041910965125  .703739068656   ...
                1.136658243408  .421234534204   -.140317624179  ...
                -.017824701442  .045570345896                   ];
            case 5
                qmf = [   .038654795955   .041746864422   -.055344186117  ...
                .281990696854   1.023052966894  .896581648380   ...
                .023478923136   -.247951362613  -.029842499869  ...
                .027632152958                                   ];
            case 6
                qmf = [   .021784700327   .004936612372   -.166863215412  ...
                -.068323121587  .694457972958   1.113892783926  ...
                .477904371333   -.102724969862  -.029783751299  ...
                .063250562660   .002499922093   -.011031867509  ];
            case 7
                qmf = [   .003792658534   -.001481225915  -.017870431651  ...
                .043155452582   .096014767936   -.070078291222  ...
                .024665659489   .758162601964   1.085782709814  ...
                .408183939725   -.198056706807  -.152463871896  ...
                .005671342686   .014521394762                   ];
            case 8
                qmf = [   .002672793393   -.000428394300  -.021145686528  ...
                .005386388754   .069490465911   -.038493521263  ...
                -.073462508761  .515398670374   1.099106630537  ...
                .680745347190   -.086653615406  -.202648655286  ...
                .010758611751   .044823623042   -.000766690896  ... 
                -.004783458512                                  ];
            case 9
                qmf = [   .001512487309   -.000669141509  -.014515578553  ...
                .012528896242   .087791251554   -.025786445930  ...
                -.270893783503  .049882830959   .873048407349   ...
                1.015259790832  .337658923602   -.077172161097  ...
                .000825140929   .042744433602   -.016303351226  ...
                -.018769396836  .000876502539   .001981193736   ];
            case 10
                qmf = [   .001089170447   .000135245020   -.012220642630  ...
                -.002072363923  .064950924579   .016418869426   ...
                -.225558972234  -.100240215031  .667071338154   ...
                1.088251530500  .542813011213   -.050256540092  ...
                -.045240772218  .070703567550   .008152816799   ...
                -.028786231926  -.001137535314  .006495728375   ...
                .000080661204   -.000649589896                  ];
            otherwise
                error('Unsupported number of vanishing moments');
        end
        % Normalize the coefficients
        qmf = qmf ./ sqrt(2);
    end

    function wave = wavelet_function(j, k, n, num_vanishing_moments)
        % Makes an orthogonal wavelet function
        %
        % Inputs: 
        %  j, k - scale and location indices
        %  n - signal length (dyadic)
        qmf = spx.wavelet.symm.quad_mirror_filter(num_vanishing_moments);
        w = zeros(1, n);
        % identify the index of the j-th scale at k-th translation
        index = spx.wavelet.dyad_to_index(j, k);
        w(index) = 1;         
        wave = spx.wavelet.transform.inverse_periodized_orthogonal(qmf, w, j);
    end

    function wave = scaling_function(j, k, n, num_vanishing_moments)
        % Makes an orthogonal scaling function
        %
        % Inputs: 
        %  j, k - scale and location indices
        %  n - signal length (dyadic)
        qmf = spx.wavelet.symm.quad_mirror_filter(num_vanishing_moments);
        w = zeros(1, n);
        % k-th translate in the coarsest part of the wavelet coefficients
        w(k) = 1;
        wave = spx.wavelet.transform.inverse_periodized_orthogonal(qmf, w, j);
    end
    
end


end
