ivan@78: function [h_0,h_1] = daubcqf(N,TYPE) ivan@78: % [h_0,h_1] = daubcqf(N,TYPE); ivan@78: % ivan@78: % Function computes the Daubechies' scaling and wavelet filters ivan@78: % (normalized to sqrt(2)). ivan@78: % ivan@78: % Input: ivan@78: % N : Length of filter (must be even) ivan@78: % TYPE : Optional parameter that distinguishes the minimum phase, ivan@78: % maximum phase and mid-phase solutions ('min', 'max', or ivan@78: % 'mid'). If no argument is specified, the minimum phase ivan@78: % solution is used. ivan@78: % ivan@78: % Output: ivan@78: % h_0 : Minimal phase Daubechies' scaling filter ivan@78: % h_1 : Minimal phase Daubechies' wavelet filter ivan@78: % ivan@78: % Example: ivan@78: % N = 4; ivan@78: % TYPE = 'min'; ivan@78: % [h_0,h_1] = daubcqf(N,TYPE) ivan@78: % h_0 = 0.4830 0.8365 0.2241 -0.1294 ivan@78: % h_1 = 0.1294 0.2241 -0.8365 0.4830 ivan@78: % ivan@78: % Reference: "Orthonormal Bases of Compactly Supported Wavelets", ivan@78: % CPAM, Oct.89 ivan@78: % ivan@78: ivan@78: %File Name: daubcqf.m ivan@78: %Last Modification Date: 01/02/96 15:12:57 ivan@78: %Current Version: daubcqf.m 2.4 ivan@78: %File Creation Date: 10/10/88 ivan@78: %Author: Ramesh Gopinath ivan@78: % ivan@78: %Copyright (c) 2000 RICE UNIVERSITY. All rights reserved. ivan@78: %Created by Ramesh Gopinath, Department of ECE, Rice University. ivan@78: % ivan@78: %This software is distributed and licensed to you on a non-exclusive ivan@78: %basis, free-of-charge. Redistribution and use in source and binary forms, ivan@78: %with or without modification, are permitted provided that the following ivan@78: %conditions are met: ivan@78: % ivan@78: %1. Redistribution of source code must retain the above copyright notice, ivan@78: % this list of conditions and the following disclaimer. ivan@78: %2. Redistribution in binary form must reproduce the above copyright notice, ivan@78: % this list of conditions and the following disclaimer in the ivan@78: % documentation and/or other materials provided with the distribution. ivan@78: %3. All advertising materials mentioning features or use of this software ivan@78: % must display the following acknowledgment: This product includes ivan@78: % software developed by Rice University, Houston, Texas and its contributors. ivan@78: %4. Neither the name of the University nor the names of its contributors ivan@78: % may be used to endorse or promote products derived from this software ivan@78: % without specific prior written permission. ivan@78: % ivan@78: %THIS SOFTWARE IS PROVIDED BY WILLIAM MARSH RICE UNIVERSITY, HOUSTON, TEXAS, ivan@78: %AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ivan@78: %BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ivan@78: %FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RICE UNIVERSITY ivan@78: %OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ivan@78: %EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ivan@78: %PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ivan@78: %OR BUSINESS INTERRUPTIONS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ivan@78: %WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR ivan@78: %OTHERWISE), PRODUCT LIABILITY, OR OTHERWISE ARISING IN ANY WAY OUT OF THE ivan@78: %USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ivan@78: % ivan@78: %For information on commercial licenses, contact Rice University's Office of ivan@78: %Technology Transfer at techtran@rice.edu or (713) 348-6173 ivan@78: ivan@78: if(nargin < 2), ivan@78: TYPE = 'min'; ivan@78: end; ivan@78: if(rem(N,2) ~= 0), ivan@78: error('No Daubechies filter exists for ODD length'); ivan@78: end; ivan@78: K = N/2; ivan@78: a = 1; ivan@78: p = 1; ivan@78: q = 1; ivan@78: h_0 = [1 1]; ivan@78: for j = 1:K-1, ivan@78: a = -a * 0.25 * (j + K - 1)/j; ivan@78: h_0 = [0 h_0] + [h_0 0]; ivan@78: p = [0 -p] + [p 0]; ivan@78: p = [0 -p] + [p 0]; ivan@78: q = [0 q 0] + a*p; ivan@78: end; ivan@78: q = sort(roots(q)); ivan@78: qt = q(1:K-1); ivan@78: if TYPE=='mid', ivan@78: if rem(K,2)==1, ivan@78: qt = q([1:4:N-2 2:4:N-2]); ivan@78: else ivan@78: qt = q([1 4:4:K-1 5:4:K-1 N-3:-4:K N-4:-4:K]); ivan@78: end; ivan@78: end; ivan@78: h_0 = conv(h_0,real(poly(qt))); ivan@78: h_0 = sqrt(2)*h_0/sum(h_0); %Normalize to sqrt(2); ivan@78: if(TYPE=='max'), ivan@78: h_0 = fliplr(h_0); ivan@78: end; ivan@78: if(abs(sum(h_0 .^ 2))-1 > 1e-4) ivan@78: error('Numerically unstable for this value of "N".'); ivan@78: end; ivan@78: h_1 = rot90(h_0,2); ivan@78: h_1(1:2:N)=-h_1(1:2:N);