comparison wavelet.cpp @ 5:5f3c32dc6e17

* Adjust comment syntax to permit Doxygen to generate HTML documentation; add Doxyfile
author Chris Cannam
date Wed, 06 Oct 2010 15:19:49 +0100
parents fc19d45615d1
children 977f541d6683
comparison
equal deleted inserted replaced
4:92ee28024c05 5:5f3c32dc6e17
3 #include <math.h> 3 #include <math.h>
4 #include <string.h> 4 #include <string.h>
5 #include "wavelet.h" 5 #include "wavelet.h"
6 #include "matrix.h" 6 #include "matrix.h"
7 7
8 /** \file wavelet.h */
9
8 //--------------------------------------------------------------------------- 10 //---------------------------------------------------------------------------
9 /* 11 /**
10 function csqrt: real implementation of complex square root z=sqrt(x) 12 function csqrt: real implementation of complex square root z=sqrt(x)
11 13
12 In: xr and xi: real and imaginary parts of x 14 In: xr and xi: real and imaginary parts of x
13 Out: zr and zi: real and imaginary parts of z=sqrt(x) 15 Out: zr and zi: real and imaginary parts of z=sqrt(x)
14 16
26 zr=xi/2/ri; 28 zr=xi/2/ri;
27 zi=ri; 29 zi=ri;
28 } 30 }
29 }//csqrt 31 }//csqrt
30 32
31 /* 33 /**
32 function Daubechies: calculates the Daubechies filter of a given order p 34 function Daubechies: calculates the Daubechies filter of a given order p
33 35
34 In: filter order p 36 In: filter order p
35 Out: h[2p]: the 2p FIR coefficients 37 Out: h[2p]: the 2p FIR coefficients
36 38
101 as another N-point sequance. Level 1 details are found at N/2 points 1, 3, 5, ..., 103 as another N-point sequance. Level 1 details are found at N/2 points 1, 3, 5, ...,
102 N-1; level 2 details are found at N/4 points 2, 6, ..., N-2; level 3 details are 104 N-1; level 2 details are found at N/4 points 2, 6, ..., N-2; level 3 details are
103 found at N/8 points 4, 12, ..., N-4; etc. 105 found at N/8 points 4, 12, ..., N-4; etc.
104 */ 106 */
105 107
106 /* 108 /**
107 function dwtpqmf: in this implementation h and g are the same as reconstruction qmf filters. In fact 109 function dwtpqmf: in this implementation h and g are the same as reconstruction qmf filters. In fact
108 the actual filters used are their mirrors and filter origin are aligned to the ends of the real 110 the actual filters used are their mirrors and filter origin are aligned to the ends of the real
109 filters, which turn out to be the starts of h and g. 111 filters, which turn out to be the starts of h and g.
110 112
111 The inverse transform is idwtp(), the same as inversing dwtp(). 113 The inverse transform is idwtp(), the same as inversing dwtp().
167 } 169 }
168 delete[] tmp; 170 delete[] tmp;
169 return n; 171 return n;
170 }//dwtpqmf 172 }//dwtpqmf
171 173
172 /* 174 /**
173 function dwtp: in this implementation h and g can be different from mirrored reconstruction filters, 175 function dwtp: in this implementation h and g can be different from mirrored reconstruction filters,
174 i.e. the biorthogonal transform. h[0] and g[0] are aligned at the ends of the filters, i.e. h[-M+1:0], 176 i.e. the biorthogonal transform. h[0] and g[0] are aligned at the ends of the filters, i.e. h[-M+1:0],
175 g[-M+1:0]. 177 g[-M+1:0].
176 178
177 In: in[Count]: waveform data 179 In: in[Count]: waveform data
223 } 225 }
224 delete[] tmp; 226 delete[] tmp;
225 return n; 227 return n;
226 }//dwtp 228 }//dwtp
227 229
228 /* 230 /**
229 function dwtp: in this implementation h and g can be different size. h[0] and g[0] are aligned at the 231 function dwtp: in this implementation h and g can be different size. h[0] and g[0] are aligned at the
230 ends of the filters, i.e. h[-Mh+1:0], g[-Mg+1:0]. 232 ends of the filters, i.e. h[-Mh+1:0], g[-Mg+1:0].
231 233
232 In: in[Count]: waveform data 234 In: in[Count]: waveform data
233 h[-Mh+1:0], g[-Mg+1:0]: quadratic mirror filter pair 235 h[-Mh+1:0], g[-Mg+1:0]: quadratic mirror filter pair
287 } 289 }
288 delete[] tmp; 290 delete[] tmp;
289 return n; 291 return n;
290 }//dwtp 292 }//dwtp
291 293
292 /* 294 /**
293 function dwtp: in this implementation h and g can be arbitrarily located: h from $sh to $eh, g from 295 function dwtp: in this implementation h and g can be arbitrarily located: h from $sh to $eh, g from
294 $sg to $eg. 296 $sg to $eg.
295 297
296 In: in[Count]: waveform data 298 In: in[Count]: waveform data
297 h[sh:eh-1], g[sg:eg-1]: quadratic mirror filter pair 299 h[sh:eh-1], g[sg:eg-1]: quadratic mirror filter pair
343 } 345 }
344 delete[] tmp; 346 delete[] tmp;
345 return n; 347 return n;
346 }//dwtp 348 }//dwtp
347 349
348 /* 350 /**
349 function idwtp: periodic wavelet reconstruction by qmf 351 function idwtp: periodic wavelet reconstruction by qmf
350 352
351 In: in[Count]: wavelet transform in interleaved format 353 In: in[Count]: wavelet transform in interleaved format
352 h[M], g[M]: quadratic mirror filter pair 354 h[M], g[M]: quadratic mirror filter pair
353 N: maximal time resolution 355 N: maximal time resolution
384 L--; 386 L--;
385 } 387 }
386 delete[] tmp; 388 delete[] tmp;
387 }//idwtp 389 }//idwtp
388 390
389 /* 391 /**
390 function idwtp: in which h and g can have different length. 392 function idwtp: in which h and g can have different length.
391 393
392 In: in[Count]: wavelet transform in interleaved format 394 In: in[Count]: wavelet transform in interleaved format
393 h[Mh], g[Mg]: quadratic mirror filter pair 395 h[Mh], g[Mg]: quadratic mirror filter pair
394 N: maximal time resolution 396 N: maximal time resolution
449 L--; 451 L--;
450 } 452 }
451 delete[] tmp; 453 delete[] tmp;
452 }//idwtp 454 }//idwtp
453 455
454 /* 456 /**
455 function idwtp: in which h and g can be arbitrarily located: h from $sh to $eh, g from $sg to $eg 457 function idwtp: in which h and g can be arbitrarily located: h from $sh to $eh, g from $sg to $eg
456 458
457 In: in[Count]: wavelet transform in interleaved format 459 In: in[Count]: wavelet transform in interleaved format
458 h[sh:eh-1], g[sg:eg-1]: quadratic mirror filter pair 460 h[sh:eh-1], g[sg:eg-1]: quadratic mirror filter pair
459 N: maximal time resolution 461 N: maximal time resolution
513 int c=1; 515 int c=1;
514 for (int i=1; i<=k; i++) c=c*(n+1-i)/i; 516 for (int i=1; i<=k; i++) c=c*(n+1-i)/i;
515 return c; 517 return c;
516 } 518 }
517 519
518 /* 520 /**
519 function splinewl: computes spline biorthogonal wavelet filters. This version of splinewl calcualtes 521 function splinewl: computes spline biorthogonal wavelet filters. This version of splinewl calcualtes
520 the positive-time half of h and hm coefficients only. 522 the positive-time half of h and hm coefficients only.
521 523
522 p1 and p2 must have the same parity. If p1 is even, p1 coefficients will be returned in h1; if p1 is 524 p1 and p2 must have the same parity. If p1 is even, p1 coefficients will be returned in h1; if p1 is
523 odd, p1-1 coefficients will be returned in h1. 525 odd, p1-1 coefficients will be returned in h1.
587 delete[] _hh1; 589 delete[] _hh1;
588 delete[] _hh2; 590 delete[] _hh2;
589 }//splinewl 591 }//splinewl
590 592
591 593
592 /* 594 /**
593 function splinewl: calculates the analysis and reconstruction filter pairs of spline biorthogonal 595 function splinewl: calculates the analysis and reconstruction filter pairs of spline biorthogonal
594 wavelet (h, g) and (hm, gm). h has the size p1+1, hm has the size p1+2p2-1. 596 wavelet (h, g) and (hm, gm). h has the size p1+1, hm has the size p1+2p2-1.
595 597
596 If p1+1 is odd, then all four filters are symmetric; if not, then h and hm are symmetric, while g and 598 If p1+1 is odd, then all four filters are symmetric; if not, then h and hm are symmetric, while g and
597 gm are anti-symmetric. 599 gm are anti-symmetric.
727 } 729 }
728 return -p1-p2+1; 730 return -p1-p2+1;
729 }//splinewl 731 }//splinewl
730 732
731 //--------------------------------------------------------------------------- 733 //---------------------------------------------------------------------------
732 /* 734 /**
733 function wavpacqmf: calculate pseudo local cosine transforms using wavelet packet 735 function wavpacqmf: calculate pseudo local cosine transforms using wavelet packet
734 736
735 In: data[Count], Count=fr*WID, waveform data 737 In: data[Count], Count=fr*WID, waveform data
736 WID: largest scale, equals 2^ORDER 738 WID: largest scale, equals 2^ORDER
737 wid: smallest scale, euqals 2^order 739 wid: smallest scale, euqals 2^order
794 } 796 }
795 797
796 delete[] _data1; 798 delete[] _data1;
797 }//wavpacqmf 799 }//wavpacqmf
798 800
799 /* 801 /**
800 function iwavpacqmf: inverse transform of wavpacqmf 802 function iwavpacqmf: inverse transform of wavpacqmf
801 803
802 In: spec[Fr][Wid], Fr>M*2 804 In: spec[Fr][Wid], Fr>M*2
803 h[M], g[M], quadratic mirror filter pair 805 h[M], g[M], quadratic mirror filter pair
804 Out: data[Fr*Wid] 806 Out: data[Fr*Wid]
851 K=(K>>1); 853 K=(K>>1);
852 } 854 }
853 delete[] _data1; 855 delete[] _data1;
854 }//iwavpacqmf 856 }//iwavpacqmf
855 857
856 /* 858 /**
857 function wavpac: calculate pseudo local cosine transforms using wavelet packet, 859 function wavpac: calculate pseudo local cosine transforms using wavelet packet,
858 860
859 In: data[Count], Count=fr*WID, waveform data 861 In: data[Count], Count=fr*WID, waveform data
860 WID: largest scale, equals 2^ORDER 862 WID: largest scale, equals 2^ORDER
861 wid: smallest scale, euqals 2^order 863 wid: smallest scale, euqals 2^order
937 } 939 }
938 940
939 delete[] _data1; 941 delete[] _data1;
940 }//wavpac 942 }//wavpac
941 943
942 /* 944 /**
943 function iwavpac: inverse transform of wavpac 945 function iwavpac: inverse transform of wavpac
944 946
945 In: spec[Fr][Wid] 947 In: spec[Fr][Wid]
946 h[hs:he-1], g[gs:ge-1], reconstruction filter pair 948 h[hs:he-1], g[gs:ge-1], reconstruction filter pair
947 Out: data[Fr*Wid] 949 Out: data[Fr*Wid]