comparison sinest.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 42c078b19e9a
children 9b1c0825cc77
comparison
equal deleted inserted replaced
4:92ee28024c05 5:5f3c32dc6e17
6 #include "opt.h" 6 #include "opt.h"
7 #include "sinsyn.h" 7 #include "sinsyn.h"
8 #include "splines.h" 8 #include "splines.h"
9 #include "windowfunctions.h" 9 #include "windowfunctions.h"
10 10
11 /** \file sinest.h */
12
11 //--------------------------------------------------------------------------- 13 //---------------------------------------------------------------------------
12 /* 14 /**
13 function dsincd_unn: derivative of unnormalized discrete sinc function 15 function dsincd_unn: derivative of unnormalized discrete sinc function
14 16
15 In: x, scale N 17 In: x, scale N
16 18
17 Returns the derivative of sincd_unn(x, N) 19 Returns the derivative of sincd_unn(x, N)
36 r=0; 38 r=0;
37 } 39 }
38 return r; 40 return r;
39 }//dsincd_unn 41 }//dsincd_unn
40 42
41 /* 43 /**
42 function ddsincd_unn: 2nd-order derivative of unnormalized discrete sinc function 44 function ddsincd_unn: 2nd-order derivative of unnormalized discrete sinc function
43 45
44 In: x, scale (equivalently, window size) N 46 In: x, scale (equivalently, window size) N
45 47
46 Returns the 2nd-order derivative of sincd_unn(x, N) 48 Returns the 2nd-order derivative of sincd_unn(x, N)
72 } 74 }
73 return r; 75 return r;
74 }//ddsincd_unn 76 }//ddsincd_unn
75 77
76 //--------------------------------------------------------------------------- 78 //---------------------------------------------------------------------------
77 /* 79 /**
78 function Window: calculates the cosine-family-windowed spectrum of a complex sinusoid on [0:N-1] at 80 function Window: calculates the cosine-family-windowed spectrum of a complex sinusoid on [0:N-1] at
79 frequency f bins with zero central phase. 81 frequency f bins with zero central phase.
80 82
81 In: f: frequency, in bins 83 In: f: frequency, in bins
82 N: window size 84 N: window size
123 } 125 }
124 } 126 }
125 return x; 127 return x;
126 }//Window 128 }//Window
127 129
128 /* 130 /**
129 function dWindow: calculates the cosine-family-windowed spectrum and its derivative of a complex 131 function dWindow: calculates the cosine-family-windowed spectrum and its derivative of a complex
130 sinusoid on [0:N-1] at frequency f bins with zero central phase. 132 sinusoid on [0:N-1] at frequency f bins with zero central phase.
131 133
132 In: f: frequency, in bins 134 In: f: frequency, in bins
133 N: window size 135 N: window size
176 } 178 }
177 } 179 }
178 } 180 }
179 }//dWindow 181 }//dWindow
180 182
181 /* 183 /**
182 function ddWindow: calculates the cosine-family-windowed spectrum and its 1st and 2nd derivatives of 184 function ddWindow: calculates the cosine-family-windowed spectrum and its 1st and 2nd derivatives of
183 a complex sinusoid on [0:N-1] at frequency f bins with zero central phase. 185 a complex sinusoid on [0:N-1] at frequency f bins with zero central phase.
184 186
185 In: f: frequency, in bins 187 In: f: frequency, in bins
186 N: window size 188 N: window size
237 } 239 }
238 } 240 }
239 }//ddWindow 241 }//ddWindow
240 242
241 //--------------------------------------------------------------------------- 243 //---------------------------------------------------------------------------
242 /* 244 /**
243 function IPWindow: computes the truncated inner product of a windowed spectrum with that of a sinusoid 245 function IPWindow: computes the truncated inner product of a windowed spectrum with that of a sinusoid
244 at reference frequency f. 246 at reference frequency f.
245 247
246 In: x[0:N-1]: input spectrum 248 In: x[0:N-1]: input spectrum
247 f: reference frequency, in bins 249 f: reference frequency, in bins
265 { 267 {
266 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dipwindow; double ipwindow;} *p=(l_ip *)params; 268 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dipwindow; double ipwindow;} *p=(l_ip *)params;
267 return IPWindow(f, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, true); 269 return IPWindow(f, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, true);
268 }//IPWindow 270 }//IPWindow
269 271
270 /* 272 /**
271 function ddIPWindow: computes the norm of the truncated inner product of a windowed spectrum with 273 function ddIPWindow: computes the norm of the truncated inner product of a windowed spectrum with
272 that of a sinusoid at reference frequency f, as well as its 1st and 2nd derivatives. 274 that of a sinusoid at reference frequency f, as well as its 1st and 2nd derivatives.
273 275
274 In: x[0:N-1]: input spectrum 276 In: x[0:N-1]: input spectrum
275 f: reference frequency, in bins 277 f: reference frequency, in bins
304 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dipwindow; double ipwindow;} *p=(l_ip *)params; 306 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dipwindow; double ipwindow;} *p=(l_ip *)params;
305 return ddIPWindow(f, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->dipwindow, p->ipwindow); 307 return ddIPWindow(f, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->dipwindow, p->ipwindow);
306 }//ddIPWindow 308 }//ddIPWindow
307 309
308 //--------------------------------------------------------------------------- 310 //---------------------------------------------------------------------------
309 /* 311 /**
310 function IPWindowC: computes the truncated inner product of a windowed spectrum with that of a 312 function IPWindowC: computes the truncated inner product of a windowed spectrum with that of a
311 sinusoid at reference frequency f. 313 sinusoid at reference frequency f.
312 314
313 In: x[0:N-1]: input spectrum 315 In: x[0:N-1]: input spectrum
314 f: reference frequency, in bins 316 f: reference frequency, in bins
330 result*=iH2; 332 result*=iH2;
331 return result; 333 return result;
332 }//IPWindowC 334 }//IPWindowC
333 335
334 //--------------------------------------------------------------------------- 336 //---------------------------------------------------------------------------
335 /* 337 /**
336 function sIPWindow: computes the total energy of truncated inner products between multiple windowed 338 function sIPWindow: computes the total energy of truncated inner products between multiple windowed
337 spectra and that of a sinusoid at a reference frequency f. This does not consider phase alignment 339 spectra and that of a sinusoid at a reference frequency f. This does not consider phase alignment
338 between the spectra, supposedly measured at a sequence of known instants. 340 between the spectra, supposedly measured at a sequence of known instants.
339 341
340 In: x[L][N]: input spectra 342 In: x[L][N]: input spectra
368 { 370 {
369 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double dipwindow; double ipwindow; cdouble* lmd;} *p=(l_ip *)params; 371 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double dipwindow; double ipwindow; cdouble* lmd;} *p=(l_ip *)params;
370 return sIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->lmd); 372 return sIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->lmd);
371 }//sIPWindow 373 }//sIPWindow
372 374
373 /* 375 /**
374 function dsIPWindow: computes the total energy of truncated inner products between multiple windowed 376 function dsIPWindow: computes the total energy of truncated inner products between multiple windowed
375 spectra and that of a sinusoid at a reference frequency f, as well as its derivative. This does not 377 spectra and that of a sinusoid at a reference frequency f, as well as its derivative. This does not
376 consider phase synchronization between the spectra, supposedly measured at a sequence of known 378 consider phase synchronization between the spectra, supposedly measured at a sequence of known
377 instants. 379 instants.
378 380
407 { 409 {
408 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double sip;} *p=(l_ip1 *)params; 410 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double sip;} *p=(l_ip1 *)params;
409 return dsIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->sip); 411 return dsIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->sip);
410 }//dsIPWindow 412 }//dsIPWindow
411 413
412 /* 414 /**
413 function dsdIPWindow_unn: computes the energy of unnormalized truncated inner products between a given 415 function dsdIPWindow_unn: computes the energy of unnormalized truncated inner products between a given
414 windowed spectrum and that of a sinusoid at a reference frequency f, as well as its 1st and 2nd 416 windowed spectrum and that of a sinusoid at a reference frequency f, as well as its 1st and 2nd
415 derivatives. "Unnormalized" indicates that the inner product cannot be taken as the actual amplitude- 417 derivatives. "Unnormalized" indicates that the inner product cannot be taken as the actual amplitude-
416 phase factor of a sinusoid, but deviate from that by an unspecified factor. 418 phase factor of a sinusoid, but deviate from that by an unspecified factor.
417 419
452 dsipwindow=dR2; 454 dsipwindow=dR2;
453 if (w_unn) w_unn->x=rr, w_unn->y=ri; 455 if (w_unn) w_unn->x=rr, w_unn->y=ri;
454 return ddR2; 456 return ddR2;
455 }//ddsIPWindow_unn 457 }//ddsIPWindow_unn
456 458
457 /* 459 /**
458 function ddsIPWindow: computes the total energy of truncated inner products between multiple windowed 460 function ddsIPWindow: computes the total energy of truncated inner products between multiple windowed
459 spectra and that of a sinusoid at a reference frequency f, as well as its 1st and 2nd derivatives. 461 spectra and that of a sinusoid at a reference frequency f, as well as its 1st and 2nd derivatives.
460 This does not consider phase synchronization between the spectra, supposedly measured at a sequence 462 This does not consider phase synchronization between the spectra, supposedly measured at a sequence
461 of known instants. 463 of known instants.
462 464
492 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double dsip; double sip;} *p=(l_ip1 *)params; 494 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int Fr; cdouble** x; double dsip; double sip;} *p=(l_ip1 *)params;
493 return ddsIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->dsip, p->sip); 495 return ddsIPWindow(f, p->Fr, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->dsip, p->sip);
494 }//ddsIPWindow 496 }//ddsIPWindow
495 497
496 //--------------------------------------------------------------------------- 498 //---------------------------------------------------------------------------
497 /* 499 /**
498 function sIPWindowC: computes the total energy of truncated inner products between multiple frames of 500 function sIPWindowC: computes the total energy of truncated inner products between multiple frames of
499 a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f. 501 a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f.
500 502
501 In: x[L][N]: the spectrogram 503 In: x[L][N]: the spectrogram
502 offst_rel: frame offset, relative to frame size 504 offst_rel: frame offset, relative to frame size
544 { 546 {
545 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double dipwindow; double ipwindow;} *p=(l_ip *)params; 547 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double dipwindow; double ipwindow;} *p=(l_ip *)params;
546 return sIPWindowC(f, p->L, p->offst_rel, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2); 548 return sIPWindowC(f, p->L, p->offst_rel, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2);
547 }//sIPWindowC 549 }//sIPWindowC
548 550
549 /* 551 /**
550 function dsIPWindowC: computes the total energy of truncated inner products between multiple frames of 552 function dsIPWindowC: computes the total energy of truncated inner products between multiple frames of
551 a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f, together 553 a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f, together
552 with its derivative. 554 with its derivative.
553 555
554 In: x[L][N]: the spectrogram 556 In: x[L][N]: the spectrogram
591 { 593 {
592 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double sip;} *p=(l_ip *)params; 594 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double sip;} *p=(l_ip *)params;
593 return dsIPWindowC(f, p->L, p->offst_rel, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->sip); 595 return dsIPWindowC(f, p->L, p->offst_rel, p->x, p->N, p->M, p->c, p->iH2, p->k1, p->k2, p->sip);
594 }//dsIPWindowC 596 }//dsIPWindowC
595 597
596 /* 598 /**
597 function ddsIPWindowC: computes the total energy of truncated inner products between multiple frames 599 function ddsIPWindowC: computes the total energy of truncated inner products between multiple frames
598 of a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f, 600 of a spectrogram and multiple frames of a spectrogram of a sinusoid at a reference frequency f,
599 together with its 1st and 2nd derivatives. 601 together with its 1st and 2nd derivatives.
600 602
601 In: x[L][N]: the spectrogram 603 In: x[L][N]: the spectrogram
655 f & epf are given/returned in bins. 657 f & epf are given/returned in bins.
656 658
657 Further reading: "Least-square-error estimation of sinusoids.pdf" 659 Further reading: "Least-square-error estimation of sinusoids.pdf"
658 */ 660 */
659 661
660 /* 662 /**
661 function LSESinusoid: LSE estimation of the predominant stationary sinusoid. 663 function LSESinusoid: LSE estimation of the predominant stationary sinusoid.
662 664
663 In: x[N]: windowed spectrum 665 In: x[N]: windowed spectrum
664 B: spectral truncation half width, in bins. 666 B: spectral truncation half width, in bins.
665 M, c[], iH2: cosine-family window specification parameters 667 M, c[], iH2: cosine-family window specification parameters
725 else 727 else
726 a=p.hxpeak; 728 a=p.hxpeak;
727 pp=IPWindow(f, x, N, M, c, iH2, p.k1, p.k2, false); 729 pp=IPWindow(f, x, N, M, c, iH2, p.k1, p.k2, false);
728 }//LSESinusoid 730 }//LSESinusoid
729 731
730 /* 732 /**
731 function LSESinusoid: LSE estimation of stationary sinusoid predominant within [f1, f2]. 733 function LSESinusoid: LSE estimation of stationary sinusoid predominant within [f1, f2].
732 734
733 In: x[N]: windowed spectrum 735 In: x[N]: windowed spectrum
734 [f1, f2]: frequency range 736 [f1, f2]: frequency range
735 B: spectral truncation half width, in bins. 737 B: spectral truncation half width, in bins.
767 a=p.hxpeak; 769 a=p.hxpeak;
768 pp=IPWindow(f, x, N, M, c, iH2, p.k1, p.k2, false); 770 pp=IPWindow(f, x, N, M, c, iH2, p.k1, p.k2, false);
769 return f; 771 return f;
770 }//LSESinusoid 772 }//LSESinusoid
771 773
772 /* 774 /**
773 function LSESinusoid: LSE estimation of stationary sinusoid near a given initial frequency within [f1, 775 function LSESinusoid: LSE estimation of stationary sinusoid near a given initial frequency within [f1,
774 f2]. 776 f2].
775 777
776 In: x[N]: windowed spectrum 778 In: x[N]: windowed spectrum
777 f: initial frequency, in bins 779 f: initial frequency, in bins
817 } 819 }
818 } 820 }
819 return result; 821 return result;
820 }//LSESinusoid 822 }//LSESinusoid
821 823
822 /* 824 /**
823 function LSESinusoidMP: LSE estimation of a stationary sinusoid from multi-frames spectrogram without 825 function LSESinusoidMP: LSE estimation of a stationary sinusoid from multi-frames spectrogram without
824 considering phase-frequency consistency across frames. 826 considering phase-frequency consistency across frames.
825 827
826 In: x[Fr][N]: spectrogram 828 In: x[Fr][N]: spectrogram
827 f: initial frequency, in bins 829 f: initial frequency, in bins
853 } 855 }
854 } 856 }
855 return errf; 857 return errf;
856 }//LSESinusoidMP 858 }//LSESinusoidMP
857 859
858 /* 860 /**
859 function LSESinusoidMP: LSE estimation of a stationary sinusoid from multi-frames spectrogram without 861 function LSESinusoidMP: LSE estimation of a stationary sinusoid from multi-frames spectrogram without
860 considering phase-frequency consistency across frames. 862 considering phase-frequency consistency across frames.
861 863
862 In: x[Fr][N]: spectrogram 864 In: x[Fr][N]: spectrogram
863 f: initial frequency, in bins 865 f: initial frequency, in bins
897 } 899 }
898 return errf; 900 return errf;
899 }//LSESinusoidMPC 901 }//LSESinusoidMPC
900 902
901 //--------------------------------------------------------------------------- 903 //---------------------------------------------------------------------------
902 /* 904 /**
903 function IPMulti: least square estimation of multiple sinusoids, given their frequencies and an energy 905 function IPMulti: least square estimation of multiple sinusoids, given their frequencies and an energy
904 suppression index of eps, i.e. the least square error is minimized with an additional eps*||lmd||^2 906 suppression index of eps, i.e. the least square error is minimized with an additional eps*||lmd||^2
905 term. 907 term.
906 908
907 In: x[Wid]: spectrum 909 In: x[Wid]: spectrum
924 for (int i=0; i<I; i++) whw[i][i]+=eps; 926 for (int i=0; i<I; i++) whw[i][i]+=eps;
925 GECP(I, lmd, whw, whx); 927 GECP(I, lmd, whw, whx);
926 delete List; 928 delete List;
927 }//IPMulti 929 }//IPMulti
928 930
929 /* 931 /**
930 function IPMulti: least square estimation of multiple sinusoids, given their frequencies and an energy 932 function IPMulti: least square estimation of multiple sinusoids, given their frequencies and an energy
931 suppression index of eps, and optionally returns residue and sensitivity indicators for each sinusoid. 933 suppression index of eps, and optionally returns residue and sensitivity indicators for each sinusoid.
932 934
933 In: x[Wid]: spectrum 935 In: x[Wid]: spectrum
934 f[I]: frequencies 936 f[I]: frequencies
975 } 977 }
976 } 978 }
977 delete List; 979 delete List;
978 }//IPMulti 980 }//IPMulti
979 981
980 /* 982 /**
981 function IPMultiSens: computes the sensitivity of the least square estimation of multiple sinusoids given 983 function IPMultiSens: computes the sensitivity of the least square estimation of multiple sinusoids given
982 their frequencies . 984 their frequencies .
983 985
984 In: f[I]: frequencies 986 In: f[I]: frequencies
985 M, c[]: cosine-family window specification parameters 987 M, c[]: cosine-family window specification parameters
1007 sens[i]=0; for (int k=0; k<K; k++) sens[i]+=~u[i][k]; sens[i]=sqrt(sens[i]); 1009 sens[i]=0; for (int k=0; k<K; k++) sens[i]+=~u[i][k]; sens[i]=sqrt(sens[i]);
1008 } 1010 }
1009 delete List; 1011 delete List;
1010 }//IPMultiSens 1012 }//IPMultiSens
1011 1013
1012 /* 1014 /**
1013 function IPMulti: least square estimation of multi-sinusoids with GIVEN frequencies. This version 1015 function IPMulti: least square estimation of multi-sinusoids with GIVEN frequencies. This version
1014 operates in groups at least B bins from each other, rather than LSE all frequencies together. 1016 operates in groups at least B bins from each other, rather than LSE all frequencies together.
1015 1017
1016 In: x[Wid]: spectrum 1018 In: x[Wid]: spectrum
1017 f[I]: frequencies, must be ordered low to high. 1019 f[I]: frequencies, must be ordered low to high.
1054 i++; 1056 i++;
1055 } 1057 }
1056 return 0; 1058 return 0;
1057 }//IPMulti 1059 }//IPMulti
1058 1060
1059 /* 1061 /**
1060 function IPMulti_Direct: LSE estimation of multiple sinusoids given frequencies AND PHASES (direct 1062 function IPMulti_Direct: LSE estimation of multiple sinusoids given frequencies AND PHASES (direct
1061 method) 1063 method)
1062 1064
1063 In: x[Wid]: spectrum 1065 In: x[Wid]: spectrum
1064 f[I], ph[I]: frequencies and phase angles. 1066 f[I], ph[I]: frequencies and phase angles.
1113 double result=Inner(hWid, r, r).x; 1115 double result=Inner(hWid, r, r).x;
1114 delete List; 1116 delete List;
1115 return result; 1117 return result;
1116 }//IPMulti_Direct 1118 }//IPMulti_Direct
1117 1119
1118 /* 1120 /**
1119 function IPMulti_GS: LSE estimation of multiple sinusoids given frequencies AND PHASES (Gram-Schmidt method) 1121 function IPMulti_GS: LSE estimation of multiple sinusoids given frequencies AND PHASES (Gram-Schmidt method)
1120 1122
1121 In: x[Wid]: spectrum 1123 In: x[Wid]: spectrum
1122 f[I], ph[I]: frequencies and phase angles. 1124 f[I], ph[I]: frequencies and phase angles.
1123 B: spectral truncation, in bins; sinusoids over 3B bins apart are regarded non-interfering 1125 B: spectral truncation, in bins; sinusoids over 3B bins apart are regarded non-interfering
1171 double result=Inner(hWid, r, r).x; 1173 double result=Inner(hWid, r, r).x;
1172 delete List; 1174 delete List;
1173 return result; 1175 return result;
1174 }//IPMulti_GS 1176 }//IPMulti_GS
1175 1177
1176 /* 1178 /**
1177 function IPMulti: LSE estimation of I sinusoids given frequency and phase and J sinusoids given 1179 function IPMulti: LSE estimation of I sinusoids given frequency and phase and J sinusoids given
1178 frequency only 1180 frequency only
1179 1181
1180 In: x[Wid]: spectrum 1182 In: x[Wid]: spectrum
1181 f[I+J], ph[I]: frequencies and phase angles 1183 f[I+J], ph[I]: frequencies and phase angles
1232 Routines for estimation two sinusoids with 1 fixed and 1 flexible frequency 1234 Routines for estimation two sinusoids with 1 fixed and 1 flexible frequency
1233 1235
1234 Further reading: "LSE estimation for 2 sinusoids with 1 at a fixed frequency.pdf" 1236 Further reading: "LSE estimation for 2 sinusoids with 1 at a fixed frequency.pdf"
1235 */ 1237 */
1236 1238
1237 /* 1239 /**
1238 function WindowDuo: calcualtes the square norm of the inner product between windowed spectra of two 1240 function WindowDuo: calcualtes the square norm of the inner product between windowed spectra of two
1239 sinusoids at frequencies f1 and f2, df=f1-f2. 1241 sinusoids at frequencies f1 and f2, df=f1-f2.
1240 1242
1241 In: df: frequency difference, in bins 1243 In: df: frequency difference, in bins
1242 N: DFT size 1244 N: DFT size
1260 if (w) w->x=wr, w->y=wi; 1262 if (w) w->x=wr, w->y=wi;
1261 double result=wr*wr+wi*wi; 1263 double result=wr*wr+wi*wi;
1262 return result; 1264 return result;
1263 }//WindowDuo 1265 }//WindowDuo
1264 1266
1265 /* 1267 /**
1266 function ddWindowDuo: calcualtes the square norm of the inner product between windowed spectra of two 1268 function ddWindowDuo: calcualtes the square norm of the inner product between windowed spectra of two
1267 sinusoids at frequencies f1 and f2, df=f1-f2, with its 1st and 2nd derivatives 1269 sinusoids at frequencies f1 and f2, df=f1-f2, with its 1st and 2nd derivatives
1268 1270
1269 In: df: frequency difference, in bins 1271 In: df: frequency difference, in bins
1270 N: DFT size 1272 N: DFT size
1293 if (w) w->x=wr, w->y=wi; 1295 if (w) w->x=wr, w->y=wi;
1294 double ddwindow=2*(wr*ddwr+dwr*dwr+wi*ddwi+dwi*dwi); 1296 double ddwindow=2*(wr*ddwr+dwr*dwr+wi*ddwi+dwi*dwi);
1295 return ddwindow; 1297 return ddwindow;
1296 }//ddWindowDuo 1298 }//ddWindowDuo
1297 1299
1298 /* 1300 /**
1299 function sIPWindowDuo: calculates the square norm of the orthogonal projection of a windowed spectrum 1301 function sIPWindowDuo: calculates the square norm of the orthogonal projection of a windowed spectrum
1300 onto the linear span of the windowed spectra of two sinusoids at reference frequencies f1 and f2. 1302 onto the linear span of the windowed spectra of two sinusoids at reference frequencies f1 and f2.
1301 1303
1302 In: x[N]: spectrum 1304 In: x[N]: spectrum
1303 f1, f2: reference frequencies. 1305 f1, f2: reference frequencies.
1331 struct l_ip {int N; int k1; int k2; double* c; double* d; int M; double iH2; cdouble* x; double f1; double dipwindow; double ipwindow;} *p=(l_ip *)params; 1333 struct l_ip {int N; int k1; int k2; double* c; double* d; int M; double iH2; cdouble* x; double f1; double dipwindow; double ipwindow;} *p=(l_ip *)params;
1332 cdouble r1, r2; 1334 cdouble r1, r2;
1333 return sIPWindowDuo(p->f1, f2, p->x, p->N, p->c, p->d, p->M, p->iH2, p->k1, p->k2, r1, r2); 1335 return sIPWindowDuo(p->f1, f2, p->x, p->N, p->c, p->d, p->M, p->iH2, p->k1, p->k2, r1, r2);
1334 }//sIPWindowDuo 1336 }//sIPWindowDuo
1335 1337
1336 /* 1338 /**
1337 function ddsIPWindowDuo: calculates the square norm, and its 1st and 2nd derivatives against f2,, of 1339 function ddsIPWindowDuo: calculates the square norm, and its 1st and 2nd derivatives against f2,, of
1338 the orthogonal projection of a windowed spectrum onto the linear span of the windowed spectra of two 1340 the orthogonal projection of a windowed spectrum onto the linear span of the windowed spectra of two
1339 sinusoids at reference frequencies f1 and f2. 1341 sinusoids at reference frequencies f1 and f2.
1340 1342
1341 In: x[N]: spectrum 1343 In: x[N]: spectrum
1380 ddsIPWindowDuo(ddsip2, p->f1, f2, p->x, p->N, p->c, p->d, p->M, p->iH2, p->k1, p->k2, r1, r2); 1382 ddsIPWindowDuo(ddsip2, p->f1, f2, p->x, p->N, p->c, p->d, p->M, p->iH2, p->k1, p->k2, r1, r2);
1381 p->dipwindow=ddsip2[1], p->ipwindow=ddsip2[2]; 1383 p->dipwindow=ddsip2[1], p->ipwindow=ddsip2[2];
1382 return ddsip2[0]; 1384 return ddsip2[0];
1383 }//ddsIPWindowDuo 1385 }//ddsIPWindowDuo
1384 1386
1385 /* 1387 /**
1386 function LSEDuo: least-square estimation of two sinusoids of which one has a fixed frequency 1388 function LSEDuo: least-square estimation of two sinusoids of which one has a fixed frequency
1387 1389
1388 In: x[N]: the windowed spectrum 1390 In: x[N]: the windowed spectrum
1389 f1: the fixed frequency 1391 f1: the fixed frequency
1390 f2: initial value of the flexible frequency 1392 f2: initial value of the flexible frequency
1425 1427
1426 Further reading: A. R?bel, ¡°Estimating partial frequency and frequency slope using reassignment 1428 Further reading: A. R?bel, ¡°Estimating partial frequency and frequency slope using reassignment
1427 operators,¡± in Proc. ICMC¡¯02. G?teborg. 2002. 1429 operators,¡± in Proc. ICMC¡¯02. G?teborg. 2002.
1428 */ 1430 */
1429 1431
1430 /* 1432 /**
1431 function CDFTW: single-frequency windowed DTFT, centre-aligned 1433 function CDFTW: single-frequency windowed DTFT, centre-aligned
1432 1434
1433 In: data[Wid]: waveform data x 1435 In: data[Wid]: waveform data x
1434 win[Wid+1]: window function 1436 win[Wid+1]: window function
1435 k: frequency, in bins, where bin=1/Wid 1437 k: frequency, in bins, where bin=1/Wid
1448 tmp.rotate(ph); 1450 tmp.rotate(ph);
1449 X+=tmp; 1451 X+=tmp;
1450 } 1452 }
1451 }//CDFTW 1453 }//CDFTW
1452 1454
1453 /* 1455 /**
1454 function CuDFTW: single-frequency windowed DTFT of t*data[t], centre-aligned 1456 function CuDFTW: single-frequency windowed DTFT of t*data[t], centre-aligned
1455 1457
1456 In: data[Wid]: waveform data x 1458 In: data[Wid]: waveform data x
1457 wid[Wid+1]: window function 1459 wid[Wid+1]: window function
1458 k: frequency, in bins 1460 k: frequency, in bins
1472 tmp.rotate(ph); 1474 tmp.rotate(ph);
1473 X+=tmp; 1475 X+=tmp;
1474 } 1476 }
1475 }//CuDFTW 1477 }//CuDFTW
1476 1478
1477 /* 1479 /**
1478 function TFReas: time-frequency reassignment 1480 function TFReas: time-frequency reassignment
1479 1481
1480 In: data[Wid]: waveform data 1482 In: data[Wid]: waveform data
1481 win[Wid+1], dwin[Wid+1], ddwin[Wid+1]: window function and its derivatives 1483 win[Wid+1], dwin[Wid+1], ddwin[Wid+1]: window function and its derivatives
1482 f, t: initial digital frequency and time 1484 f, t: initial digital frequency and time
1505 dwdt=(xtt.y*x.x-xtt.x*x.y)/px-2*(xt.x*x.x+xt.y*x.y)*(xt.y*x.x-xt.x*x.y)/px/px; 1507 dwdt=(xtt.y*x.x-xtt.x*x.y)/px-2*(xt.x*x.x+xt.y*x.y)*(xt.y*x.x-xt.x*x.y)/px/px;
1506 if (dtdt!=0) fslope=dwdt/dtdt/(2*M_PI); 1508 if (dtdt!=0) fslope=dwdt/dtdt/(2*M_PI);
1507 else fslope=0; 1509 else fslope=0;
1508 } //TFReas*/ 1510 } //TFReas*/
1509 1511
1510 /* 1512 /**
1511 function TFReas: sinusoid estimation using reassignment method 1513 function TFReas: sinusoid estimation using reassignment method
1512 1514
1513 In: data[Wid]: waveform data 1515 In: data[Wid]: waveform data
1514 w[Wid+1], dw[Wid+1], ddw[Wid+1]: window function and its derivatives 1516 w[Wid+1], dw[Wid+1], ddw[Wid+1]: window function and its derivatives
1515 win[Wid]: window function used for estimating amplitude and phase by projection onto a chirp 1517 win[Wid]: window function used for estimating amplitude and phase by projection onto a chirp
1565 1567
1566 Further reading: Wen X. and M. Sandler, "Additive and multiplicative reestimation schemes 1568 Further reading: Wen X. and M. Sandler, "Additive and multiplicative reestimation schemes
1567 for the sinusoid modeling of audio," in Proc. EUSIPCO'09, Glasgow, 2009. 1569 for the sinusoid modeling of audio," in Proc. EUSIPCO'09, Glasgow, 2009.
1568 */ 1570 */
1569 1571
1570 /* 1572 /**
1571 function AdditiveUpdate: additive reestimation of time-varying sinusoid 1573 function AdditiveUpdate: additive reestimation of time-varying sinusoid
1572 1574
1573 In: x[Count]: waveform data 1575 In: x[Count]: waveform data
1574 Wid, Offst: frame size and hop 1576 Wid, Offst: frame size and hop
1575 fs[Count], as[Count], phs[Count]: initial estimate of sinusoid parameters 1577 fs[Count], as[Count], phs[Count]: initial estimate of sinusoid parameters
1641 if (fs[i]<0 || fs[i]>0.5){} 1643 if (fs[i]<0 || fs[i]>0.5){}
1642 } 1644 }
1643 delete[] y; delete[] lf; delete[] ref; 1645 delete[] y; delete[] lf; delete[] ref;
1644 }//AdditiveUpdate 1646 }//AdditiveUpdate
1645 1647
1646 /* 1648 /**
1647 function AdditiveAnalyzer: sinusoid analyzer with one additive update 1649 function AdditiveAnalyzer: sinusoid analyzer with one additive update
1648 1650
1649 In: x[Count]: waveform data 1651 In: x[Count]: waveform data
1650 Wid, Offst: frame size and hop size 1652 Wid, Offst: frame size and hop size
1651 BasicAnalyzer: pointer to a sinusoid analyzer 1653 BasicAnalyzer: pointer to a sinusoid analyzer
1661 { 1663 {
1662 BasicAnalyzer(fs, as, phs, das, x, Count, Wid, Offst, ref, reserved, LogA); 1664 BasicAnalyzer(fs, as, phs, das, x, Count, Wid, Offst, ref, reserved, LogA);
1663 AdditiveUpdate(fs, as, phs, das, x, Count, Wid, Offst, BasicAnalyzer, reserved, LogA); 1665 AdditiveUpdate(fs, as, phs, das, x, Count, Wid, Offst, BasicAnalyzer, reserved, LogA);
1664 }//AdditiveAnalyzer 1666 }//AdditiveAnalyzer
1665 1667
1666 /* 1668 /**
1667 function MultiplicativeUpdate: multiplicative reestimation of time-varying sinusoid 1669 function MultiplicativeUpdate: multiplicative reestimation of time-varying sinusoid
1668 1670
1669 In: x[Count]: waveform data 1671 In: x[Count]: waveform data
1670 Wid, Offst: frame size and hop 1672 Wid, Offst: frame size and hop
1671 fs[Count], as[Count], phs[Count]: initial estimate of sinusoid parameters 1673 fs[Count], as[Count], phs[Count]: initial estimate of sinusoid parameters
1726 } 1728 }
1727 1729
1728 delete[] y; delete[] lf; delete[] lref; 1730 delete[] y; delete[] lf; delete[] lref;
1729 }//MultiplicativeUpdate 1731 }//MultiplicativeUpdate
1730 1732
1731 /* 1733 /**
1732 function MultiplicativeAnalyzer: sinusoid analyzer with one multiplicative update 1734 function MultiplicativeAnalyzer: sinusoid analyzer with one multiplicative update
1733 1735
1734 In: x[Count]: waveform data 1736 In: x[Count]: waveform data
1735 Wid, Offst: frame size and hop size 1737 Wid, Offst: frame size and hop size
1736 BasicAnalyzer: pointer to a sinusoid analyzer 1738 BasicAnalyzer: pointer to a sinusoid analyzer
1804 1806
1805 Further reading: Wen X. and M. Sandler, "Evaluating parameters of time-varying 1807 Further reading: Wen X. and M. Sandler, "Evaluating parameters of time-varying
1806 sinusoids by demodulation," in Proc. DAFx'08, Espoo, 2008. 1808 sinusoids by demodulation," in Proc. DAFx'08, Espoo, 2008.
1807 */ 1809 */
1808 1810
1809 /* 1811 /**
1810 function ReEstFreq: sinusoid reestimation by demodulating frequency. 1812 function ReEstFreq: sinusoid reestimation by demodulating frequency.
1811 1813
1812 In: x[Wid+Offst*(FrCount-1)]: waveform data 1814 In: x[Wid+Offst*(FrCount-1)]: waveform data
1813 FrCount, Wid, Offst: frame count, frame size and hop size 1815 FrCount, Wid, Offst: frame count, frame size and hop size
1814 fbuf[FrCount], ns[FrCount]: initial frequency estiamtes and their timing 1816 fbuf[FrCount], ns[FrCount]: initial frequency estiamtes and their timing
1894 fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp; 1896 fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp;
1895 } 1897 }
1896 } 1898 }
1897 }//ReEstFreq 1899 }//ReEstFreq
1898 1900
1899 /* 1901 /**
1900 function ReEstFreq_2: sinusoid reestimation by demodulating frequency. This is that same as ReEstFreq(...) 1902 function ReEstFreq_2: sinusoid reestimation by demodulating frequency. This is that same as ReEstFreq(...)
1901 except that it calls Sinusoid(...) to synthesize the phase track used for demodulation and that it 1903 except that it calls Sinusoid(...) to synthesize the phase track used for demodulation and that it
1902 does not allow variable window sizes for estimating demodulated sinusoid. 1904 does not allow variable window sizes for estimating demodulated sinusoid.
1903 1905
1904 In: x[Wid+Offst*(FrCount-1)]: waveform data 1906 In: x[Wid+Offst*(FrCount-1)]: waveform data
1973 if (la*2>abuf[fr]) 1975 if (la*2>abuf[fr])
1974 fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp+centralph; 1976 fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp+centralph;
1975 } 1977 }
1976 }//ReEstFreq_2 1978 }//ReEstFreq_2
1977 1979
1978 /* 1980 /**
1979 function ReEstFreqAmp: sinusoid reestimation by demodulating frequency and amplitude. 1981 function ReEstFreqAmp: sinusoid reestimation by demodulating frequency and amplitude.
1980 1982
1981 In: x[Wid+Offst*(FrCount-1)]: waveform data 1983 In: x[Wid+Offst*(FrCount-1)]: waveform data
1982 FrCount, Wid, Offst: frame count, frame size and hop size 1984 FrCount, Wid, Offst: frame count, frame size and hop size
1983 fbuf[FrCount], abuf[FrCount], ns[FrCount]: initial frequency and amplitude estiamtes and their 1985 fbuf[FrCount], abuf[FrCount], ns[FrCount]: initial frequency and amplitude estiamtes and their
2085 if (la*2>abuf[fr]) fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp; 2087 if (la*2>abuf[fr]) fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp;
2086 } 2088 }
2087 } 2089 }
2088 }//ReEstFreqAmp 2090 }//ReEstFreqAmp
2089 2091
2090 /* 2092 /**
2091 function Reestimate2: iterative demodulation method for sinusoid parameter reestimation. 2093 function Reestimate2: iterative demodulation method for sinusoid parameter reestimation.
2092 2094
2093 In: x[(FrCount-1)*Offst+Wid]: waveform data 2095 In: x[(FrCount-1)*Offst+Wid]: waveform data
2094 FrCount, Wid, Offst: frame count, frame size and hop size 2096 FrCount, Wid, Offst: frame count, frame size and hop size
2095 win[Wid]: window function 2097 win[Wid]: window function
2174 2176
2175 Further reading: Wen X. and M. Sandler, "Notes on model-based non-stationary sinusoid estimation methods 2177 Further reading: Wen X. and M. Sandler, "Notes on model-based non-stationary sinusoid estimation methods
2176 using derivatives," in Proc. DAFx'09, Como, 2009. 2178 using derivatives," in Proc. DAFx'09, Como, 2009.
2177 */ 2179 */
2178 2180
2179 /* 2181 /**
2180 function Derivative: derivative method for estimating amplitude derivative, frequency, and frequency derivative given 2182 function Derivative: derivative method for estimating amplitude derivative, frequency, and frequency derivative given
2181 signal and its derivatives. 2183 signal and its derivatives.
2182 2184
2183 In: x[Wid], dx[Wid], ddx[Wid]: waveform and its derivatives 2185 In: x[Wid], dx[Wid], ddx[Wid]: waveform and its derivatives
2184 win[Wid]: window function 2186 win[Wid]: window function
2223 *a1=miu0; 2225 *a1=miu0;
2224 2226
2225 FreeFFTBuffer(fft); 2227 FreeFFTBuffer(fft);
2226 }//Derivative 2228 }//Derivative
2227 2229
2228 /* 2230 /**
2229 function Xkw: computes windowed spectrum of x and its derivatives up to order K at angular frequency omg, 2231 function Xkw: computes windowed spectrum of x and its derivatives up to order K at angular frequency omg,
2230 from x using window w and its derivatives. 2232 from x using window w and its derivatives.
2231 2233
2232 In: x[Wid]: waveform data 2234 In: x[Wid]: waveform data
2233 w[K+1][Wid]: window functions and its derivatives up to order K 2235 w[K+1][Wid]: window functions and its derivatives up to order K
2257 cdouble *thisX=&X[k], *lastX=&X[k-1]; 2259 cdouble *thisX=&X[k], *lastX=&X[k-1];
2258 for (int kk=K-k; kk>=0; kk--) thisX[kk]=-lastX[kk+1]+cdouble(0, omg)*lastX[kk]; 2260 for (int kk=K-k; kk>=0; kk--) thisX[kk]=-lastX[kk+1]+cdouble(0, omg)*lastX[kk];
2259 } 2261 }
2260 }//Xkw 2262 }//Xkw
2261 2263
2262 /* 2264 /**
2263 function Xkw: computes windowed spectrum of x and its derivatives up to order K at angular frequency 2265 function Xkw: computes windowed spectrum of x and its derivatives up to order K at angular frequency
2264 omg, from x and its derivatives using window w. 2266 omg, from x and its derivatives using window w.
2265 2267
2266 In: x[K+1][Wid]: waveform data and its derivatives up to order K. 2268 In: x[K+1][Wid]: waveform data and its derivatives up to order K.
2267 w[Wid]: window function 2269 w[Wid]: window function
2284 X[k]+=tmp.rotate(-ph); 2286 X[k]+=tmp.rotate(-ph);
2285 } 2287 }
2286 } 2288 }
2287 }//Xkw 2289 }//Xkw
2288 2290
2289 /* 2291 /**
2290 function Derivative: derivative method for estimating the model log(s)=h[M]'r[M], by discarding extra 2292 function Derivative: derivative method for estimating the model log(s)=h[M]'r[M], by discarding extra
2291 equations 2293 equations
2292 2294
2293 In: s[Wid]: waveform data 2295 In: s[Wid]: waveform data
2294 win[][Wid]: window function and its derivatives 2296 win[][Wid]: window function and its derivatives
2405 delete[] ind; 2407 delete[] ind;
2406 DeAlloc2(Smkw); 2408 DeAlloc2(Smkw);
2407 DeAlloc2(A); 2409 DeAlloc2(A);
2408 }//Derivative*/ 2410 }//Derivative*/
2409 2411
2410 /* 2412 /**
2411 function DerivativeLS: derivative method for estimating the model log(s)=h[M]'r[M], least-square 2413 function DerivativeLS: derivative method for estimating the model log(s)=h[M]'r[M], least-square
2412 implementation 2414 implementation
2413 2415
2414 In: s[Wid]: waveform data 2416 In: s[Wid]: waveform data
2415 win[][Wid]: window function and its derivatives 2417 win[][Wid]: window function and its derivatives
2495 delete[] ind; 2497 delete[] ind;
2496 DeAlloc2(Smkw); 2498 DeAlloc2(Smkw);
2497 DeAlloc2(A); 2499 DeAlloc2(A);
2498 }//DerivativeLS 2500 }//DerivativeLS
2499 2501
2500 /* 2502 /**
2501 function DerivativeLS: derivative method for estimating the model log(s)=h[M]'r[M] using Fr 2503 function DerivativeLS: derivative method for estimating the model log(s)=h[M]'r[M] using Fr
2502 measurement points a quarter of Wid apart from each other, implemented by least-square. 2504 measurement points a quarter of Wid apart from each other, implemented by least-square.
2503 2505
2504 In: s[Wid+(Fr-1)*Wid/4]: waveform data 2506 In: s[Wid+(Fr-1)*Wid/4]: waveform data
2505 win[][Wid]: window function and its derivatives 2507 win[][Wid]: window function and its derivatives
2600 2602
2601 Further reading: M. Abe and J. O. Smith III, ¡°AM/FM rate estimation for time-varying sinusoidal 2603 Further reading: M. Abe and J. O. Smith III, ¡°AM/FM rate estimation for time-varying sinusoidal
2602 modeling,¡± in Proc. ICASSP'05, Philadelphia, 2005. 2604 modeling,¡± in Proc. ICASSP'05, Philadelphia, 2005.
2603 */ 2605 */
2604 2606
2605 /* 2607 /**
2606 function RDFTW: windowed DTFT at frequency k bins 2608 function RDFTW: windowed DTFT at frequency k bins
2607 2609
2608 In: data[Wid]: waveform data 2610 In: data[Wid]: waveform data
2609 w[Wid]: window function 2611 w[Wid]: window function
2610 k: frequency, in bins 2612 k: frequency, in bins
2627 Xr+=tmp*cos(ph); 2629 Xr+=tmp*cos(ph);
2628 Xi+=tmp*sin(ph); //*/ 2630 Xi+=tmp*sin(ph); //*/
2629 } 2631 }
2630 }//RDFTW 2632 }//RDFTW
2631 2633
2632 /* 2634 /**
2633 function TFAS05: the Abe-Smith method 2005 2635 function TFAS05: the Abe-Smith method 2005
2634 2636
2635 In: data[Wid]: waveform data 2637 In: data[Wid]: waveform data
2636 w[Wid]: window function 2638 w[Wid]: window function
2637 res: resolution of frequency for QIFFT 2639 res: resolution of frequency for QIFFT
2721 yeses=y+zt[6]*alf*alf/p+zt[7]*log(1+beta_p*beta_p), 2723 yeses=y+zt[6]*alf*alf/p+zt[7]*log(1+beta_p*beta_p),
2722 pheses=ph+zt[8]*alf*alf*beta/p+zt[9]*atan(beta_p); //*/ 2724 pheses=ph+zt[8]*alf*alf*beta/p+zt[9]*atan(beta_p); //*/
2723 f=feses/Wid, a=exp(yeses), ph=pheses, fslope=2*beta/2/M_PI, aesp=alf; 2725 f=feses/Wid, a=exp(yeses), ph=pheses, fslope=2*beta/2/M_PI, aesp=alf;
2724 }//TFAS05 2726 }//TFAS05
2725 2727
2726 /* 2728 /**
2727 function TFAS05_enh: the Abe-Smith method 2005 enhanced by LSE amplitude and phase estimation 2729 function TFAS05_enh: the Abe-Smith method 2005 enhanced by LSE amplitude and phase estimation
2728 2730
2729 In: data[Wid]: waveform data 2731 In: data[Wid]: waveform data
2730 w[Wid]: window function 2732 w[Wid]: window function
2731 res: resolution of frequency for QIFFT 2733 res: resolution of frequency for QIFFT
2755 double aesp, fslope; 2757 double aesp, fslope;
2756 TFAS05_enh(f, t, a, ph, aesp, fslope, Wid, data, w, res); 2758 TFAS05_enh(f, t, a, ph, aesp, fslope, Wid, data, w, res);
2757 }//TFAS05_enh 2759 }//TFAS05_enh
2758 2760
2759 //--------------------------------------------------------------------------- 2761 //---------------------------------------------------------------------------
2760 /* 2762 /**
2761 function DerivativeLSv_AmpPh: estimate the constant-term in the local derivative method. This is used 2763 function DerivativeLSv_AmpPh: estimate the constant-term in the local derivative method. This is used
2762 by the local derivative algorithm, whose implementation is found in the header file as templates. 2764 by the local derivative algorithm, whose implementation is found in the header file as templates.
2763 2765
2764 In: sv0: inner product <s, v0>, where s is the sinusoid being estimated. 2766 In: sv0: inner product <s, v0>, where s is the sinusoid being estimated.
2765 integr_h[M][Wid]: M vectors containing samples of the integral of basis functions h[M]. 2767 integr_h[M][Wid]: M vectors containing samples of the integral of basis functions h[M].
2786 2788
2787 Further reading: Wen X. and M. Sandler, "Spline exponential approximation of time-varying 2789 Further reading: Wen X. and M. Sandler, "Spline exponential approximation of time-varying
2788 sinusoids," under review. 2790 sinusoids," under review.
2789 */ 2791 */
2790 2792
2791 /* 2793 /**
2792 function setv: computes I test functions v[I] by modulation u[I] to frequency f 2794 function setv: computes I test functions v[I] by modulation u[I] to frequency f
2793 2795
2794 In: u[I+1][Wid], du[I+1][Wid]: base-band test functions and their derivatives 2796 In: u[I+1][Wid], du[I+1][Wid]: base-band test functions and their derivatives
2795 f: carrier frequency 2797 f: carrier frequency
2796 Out: v[I][Wid], dv[I][Wid]: test functions and their derivatives 2798 Out: v[I][Wid], dv[I][Wid]: test functions and their derivatives
2814 if (f>=fbin || I%2==1){v[I-1][c]=u[I-1][c]*rot; dv[I-1][c]=du[I-1][c]*rot+jomg*v[I-1][c];} 2816 if (f>=fbin || I%2==1){v[I-1][c]=u[I-1][c]*rot; dv[I-1][c]=du[I-1][c]*rot+jomg*v[I-1][c];}
2815 else{v[I-1][c]=u[I][c]*rot; dv[I-1][c]=du[I][c]*rot+jomg*v[I-1][c];} 2817 else{v[I-1][c]=u[I][c]*rot; dv[I-1][c]=du[I][c]*rot+jomg*v[I-1][c];}
2816 } 2818 }
2817 }//setv 2819 }//setv
2818 2820
2819 /* 2821 /**
2820 function setvhalf: computes I half-size test functions v[I] by modulation u[I] to frequency f. 2822 function setvhalf: computes I half-size test functions v[I] by modulation u[I] to frequency f.
2821 2823
2822 In: u[I][hWid*2], du[I][Wid*2]: base-band test functions and their derivatives 2824 In: u[I][hWid*2], du[I][Wid*2]: base-band test functions and their derivatives
2823 f: carrier frequency 2825 f: carrier frequency
2824 Out: v[I][hWid], dv[hWid]: half-size test functions and their derivatives 2826 Out: v[I][hWid], dv[hWid]: half-size test functions and their derivatives
2838 } 2840 }
2839 }//setvhalf 2841 }//setvhalf
2840 2842
2841 //#define ERROR_CHECK 2843 //#define ERROR_CHECK
2842 2844
2843 /* 2845 /**
2844 function DerivativePiecewise: Piecewise derivative algorithm. In this implementation of the piecewise 2846 function DerivativePiecewise: Piecewise derivative algorithm. In this implementation of the piecewise
2845 method the test functions v are constructed from I "basic" (single-frame) test functions, each 2847 method the test functions v are constructed from I "basic" (single-frame) test functions, each
2846 covering the same period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I 2848 covering the same period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I
2847 test functions are used. 2849 test functions are used.
2848 2850
3021 else LSLinear(L_1*I, N, aita, srv[0], sv[0]); 3023 else LSLinear(L_1*I, N, aita, srv[0], sv[0]);
3022 3024
3023 delete mlist; 3025 delete mlist;
3024 }//DerivativePiecewise 3026 }//DerivativePiecewise
3025 3027
3026 /* 3028 /**
3027 function DerivativePiecewise2: Piecewise derivative algorithm in which the real and imaginary parts of 3029 function DerivativePiecewise2: Piecewise derivative algorithm in which the real and imaginary parts of
3028 the exponent are modelled separately. In this implementation of the piecewise method the test 3030 the exponent are modelled separately. In this implementation of the piecewise method the test
3029 functions v are constructed from I "basic" (single-frame) test functions, each covering the same 3031 functions v are constructed from I "basic" (single-frame) test functions, each covering the same
3030 period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I test functions are 3032 period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I test functions are
3031 used. 3033 used.
3276 } 3278 }
3277 DeAlloc2(v); DeAlloc2(dv); 3279 DeAlloc2(v); DeAlloc2(dv);
3278 return ene; 3280 return ene;
3279 }//testsv 3281 }//testsv
3280 3282
3281 /* 3283 /**
3282 function DerivativePiecewise3: Piecewise derivative algorithm in which the log amplitude and frequeny 3284 function DerivativePiecewise3: Piecewise derivative algorithm in which the log amplitude and frequeny
3283 are modeled separately as piecewise functions. In this implementation of the piecewise method the test 3285 are modeled separately as piecewise functions. In this implementation of the piecewise method the test
3284 functions v are constructed from I "basic" (single-frame) test functions, each covering the same 3286 functions v are constructed from I "basic" (single-frame) test functions, each covering the same
3285 period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I test functions are 3287 period of 2T, by shifting these I functions by steps of T. A total number of (L-1)I test functions are
3286 used. 3288 used.
3442 delete mlist; 3444 delete mlist;
3443 }//DerivativePiecewise3 3445 }//DerivativePiecewise3
3444 3446
3445 //initialization routines for the piecewise derivative method 3447 //initialization routines for the piecewise derivative method
3446 3448
3447 /* 3449 /**
3448 function seth: set h[M] to a series of power functions. 3450 function seth: set h[M] to a series of power functions.
3449 3451
3450 In: M, T. 3452 In: M, T.
3451 Out: h[M][T], where h[m] is power function of order m. 3453 Out: h[M][T], where h[m] is power function of order m.
3452 3454
3461 { 3463 {
3462 hm=h[m]; for (int t=0; t<T; t++) hm[t]=pow(t*1.0, m); 3464 hm=h[m]; for (int t=0; t<T; t++) hm[t]=pow(t*1.0, m);
3463 } 3465 }
3464 }//seth 3466 }//seth
3465 3467
3466 /* 3468 /**
3467 function setdh: set dh[M] to the derivative of a series of power functions. 3469 function setdh: set dh[M] to the derivative of a series of power functions.
3468 3470
3469 In: M, T. 3471 In: M, T.
3470 Out: dh[M][T], where dh[m] is derivative of the power function of order m. 3472 Out: dh[M][T], where dh[m] is derivative of the power function of order m.
3471 3473
3481 { 3483 {
3482 dhm=dh[m]; for (int t=0; t<T; t++) dhm[t]=m*pow(t*1.0, m-1); 3484 dhm=dh[m]; for (int t=0; t<T; t++) dhm[t]=m*pow(t*1.0, m-1);
3483 } 3485 }
3484 }//setdh 3486 }//setdh
3485 3487
3486 /* 3488 /**
3487 function setdih: set dih[M] to the difference of the integral of a series of power functions. 3489 function setdih: set dih[M] to the difference of the integral of a series of power functions.
3488 3490
3489 In: M, I 3491 In: M, I
3490 Out: dih[M][I], where the accumulation of dih[m] is the integral of the power function of order m. 3492 Out: dih[M][I], where the accumulation of dih[m] is the integral of the power function of order m.
3491 3493
3500 { 3502 {
3501 dihm=dih[m]; for (int t=0; t<T; t++) dihm[t]=(pow(t+1.0, m+1)-pow(t*1.0, m+1))/(m+1); 3503 dihm=dih[m]; for (int t=0; t<T; t++) dihm[t]=(pow(t+1.0, m+1)-pow(t*1.0, m+1))/(m+1);
3502 } 3504 }
3503 }//setdih 3505 }//setdih
3504 3506
3505 /* 3507 /**
3506 function sshLinear: sets M and h[M] for the linear spline model 3508 function sshLinear: sets M and h[M] for the linear spline model
3507 3509
3508 In: T 3510 In: T
3509 Out: M=2, h[2][T] filled out for linear spline model. 3511 Out: M=2, h[2][T] filled out for linear spline model.
3510 3512
3514 { 3516 {
3515 M=2; Allocate2L(double, M, T, h, mlist); 3517 M=2; Allocate2L(double, M, T, h, mlist);
3516 for (int t=0; t<T; t++) h[0][t]=1, h[1][t]=t; 3518 for (int t=0; t<T; t++) h[0][t]=1, h[1][t]=t;
3517 }//sshLinear 3519 }//sshLinear
3518 3520
3519 /* 3521 /**
3520 function sdihLinear: sets dih[M] for the linear spline model. For testing only. 3522 function sdihLinear: sets dih[M] for the linear spline model. For testing only.
3521 3523
3522 In: T 3524 In: T
3523 Out: dih[2][T] filled out for linear spline model. 3525 Out: dih[2][T] filled out for linear spline model.
3524 3526
3528 { 3530 {
3529 Allocate2L(double, 2, T, dih, mlist); 3531 Allocate2L(double, 2, T, dih, mlist);
3530 for (int t=0; t<T; t++) dih[0][t]=1, dih[1][t]=t+0.5; 3532 for (int t=0; t<T; t++) dih[0][t]=1, dih[1][t]=t+0.5;
3531 }//sdihLinear 3533 }//sdihLinear
3532 3534
3533 /* 3535 /**
3534 function sshCubic: sets M and h[M] for cubic spline models. 3536 function sshCubic: sets M and h[M] for cubic spline models.
3535 3537
3536 In: T 3538 In: T
3537 Out: M=4 and h[M] filled out for cubic spline models, including cubic and cubic-Hermite. 3539 Out: M=4 and h[M] filled out for cubic spline models, including cubic and cubic-Hermite.
3538 3540
3542 { 3544 {
3543 M=4; Allocate2L(double, M, T, h, mlist); 3545 M=4; Allocate2L(double, M, T, h, mlist);
3544 for (int t=0; t<T; t++) h[3][t]=t*t*t, h[2][t]=t*t, h[1][t]=t, h[0][t]=1; 3546 for (int t=0; t<T; t++) h[3][t]=t*t*t, h[2][t]=t*t, h[1][t]=t, h[0][t]=1;
3545 }//sshCubic 3547 }//sshCubic
3546 3548
3547 /* 3549 /**
3548 function sdihCubic: sets dih[M] for cubic spline models. 3550 function sdihCubic: sets dih[M] for cubic spline models.
3549 3551
3550 In: T 3552 In: T
3551 Out: dih[4] filled out for cubic spline models. 3553 Out: dih[4] filled out for cubic spline models.
3552 3554
3559 { 3561 {
3560 dih[3][t]=t*(t*(t+1.5)+1)+0.25, dih[2][t]=t*(t+1)+1.0/3, dih[1][t]=t+0.5, dih[0][t]=1; 3562 dih[3][t]=t*(t*(t+1.5)+1)+0.25, dih[2][t]=t*(t+1)+1.0/3, dih[1][t]=t+0.5, dih[0][t]=1;
3561 } 3563 }
3562 }//sdihCubic*/ 3564 }//sdihCubic*/
3563 3565
3564 /* 3566 /**
3565 function ssALinearSpline: sets N and A[L] for the linear spline model 3567 function ssALinearSpline: sets N and A[L] for the linear spline model
3566 3568
3567 In: L, M, T 3569 In: L, M, T
3568 Out: N=L+1, A[L][M][N] filled out for the linear spline model 3570 Out: N=L+1, A[L][M][N] filled out for the linear spline model
3569 3571
3575 Allocate3L(double, L, M, N, A, mlist); 3577 Allocate3L(double, L, M, N, A, mlist);
3576 memset(A[0][0], 0, sizeof(double)*L*M*N); 3578 memset(A[0][0], 0, sizeof(double)*L*M*N);
3577 double iT=1.0/T; for (int l=0; l<L; l++) A[l][0][l]=1, A[l][1][l]=-iT, A[l][1][l+1]=iT; 3579 double iT=1.0/T; for (int l=0; l<L; l++) A[l][0][l]=1, A[l][1][l]=-iT, A[l][1][l+1]=iT;
3578 }//ssALinearSpline 3580 }//ssALinearSpline
3579 3581
3580 /* 3582 /**
3581 function ssLinearSpline: sets M, N, h and A for the linear spline model 3583 function ssLinearSpline: sets M, N, h and A for the linear spline model
3582 3584
3583 In: L, M, T 3585 In: L, M, T
3584 Out: N and h[][] and A[][][] filled out for the linear spline model 3586 Out: N and h[][] and A[][][] filled out for the linear spline model
3585 3587
3589 { 3591 {
3590 seth(M, T, h, mlist); 3592 seth(M, T, h, mlist);
3591 ssALinearSpline(L, T, M, N, A, mlist); 3593 ssALinearSpline(L, T, M, N, A, mlist);
3592 }//ssLinearSpline 3594 }//ssLinearSpline
3593 3595
3594 /* 3596 /**
3595 function ssACubicHermite: sets N and A[L] for cubic Hermite spline model 3597 function ssACubicHermite: sets N and A[L] for cubic Hermite spline model
3596 3598
3597 In: L, M, T 3599 In: L, M, T
3598 Out: N=2(L+1), A[L][M][N] filled out for the cubic Hermite spline 3600 Out: N=2(L+1), A[L][M][N] filled out for the cubic Hermite spline
3599 3601
3611 A[l][1][2*l+1]=1; 3613 A[l][1][2*l+1]=1;
3612 A[l][0][2*l]=1; 3614 A[l][0][2*l]=1;
3613 } 3615 }
3614 }//ssACubicHermite 3616 }//ssACubicHermite
3615 3617
3616 /* 3618 /**
3617 function ssLinearSpline: sets M, N, h and A for the cubic Hermite spline model 3619 function ssLinearSpline: sets M, N, h and A for the cubic Hermite spline model
3618 3620
3619 In: L, M, T 3621 In: L, M, T
3620 Out: N and h[][] and A[][][] filled out for the cubic Hermite spline model 3622 Out: N and h[][] and A[][][] filled out for the cubic Hermite spline model
3621 3623
3625 { 3627 {
3626 seth(M, T, h, mlist); 3628 seth(M, T, h, mlist);
3627 ssACubicHermite(L, T, M, N, A, mlist); 3629 ssACubicHermite(L, T, M, N, A, mlist);
3628 }//ssCubicHermite 3630 }//ssCubicHermite
3629 3631
3630 /* 3632 /**
3631 function ssACubicSpline: sets N and A[L] for cubic spline model 3633 function ssACubicSpline: sets N and A[L] for cubic spline model
3632 3634
3633 In: L, M, T 3635 In: L, M, T
3634 mode: boundary mode of cubic spline, 0=natural, 1=quadratic run-out, 2=cubic run-out 3636 mode: boundary mode of cubic spline, 0=natural, 1=quadratic run-out, 2=cubic run-out
3635 Out: N=2(L+1), A[L][M][N] filled out for the cubic spline 3637 Out: N=2(L+1), A[L][M][N] filled out for the cubic spline
3660 A[l][1][l]-=iT; A[l][1][l+1]+=iT; A[l][0][l]+=1; 3662 A[l][1][l]-=iT; A[l][1][l+1]+=iT; A[l][0][l]+=1;
3661 } 3663 }
3662 DeAlloc2(ML); DeAlloc2(MR); DeAlloc2(M42); 3664 DeAlloc2(ML); DeAlloc2(MR); DeAlloc2(M42);
3663 }//ssACubicSpline 3665 }//ssACubicSpline
3664 3666
3665 /* 3667 /**
3666 function ssLinearSpline: sets M, N, h and A for the cubic spline model 3668 function ssLinearSpline: sets M, N, h and A for the cubic spline model
3667 3669
3668 In: L, M, T 3670 In: L, M, T
3669 Out: N and h[][] and A[][][] filled out for the cubic spline model 3671 Out: N and h[][] and A[][][] filled out for the cubic spline model
3670 3672
3674 { 3676 {
3675 seth(M, T, h, mlist); 3677 seth(M, T, h, mlist);
3676 ssACubicSpline(L, T, M, N, A, mlist, mode); 3678 ssACubicSpline(L, T, M, N, A, mlist, mode);
3677 }//ssCubicSpline 3679 }//ssCubicSpline
3678 3680
3679 /* 3681 /**
3680 function setu: sets u[I+1] as base-band windowed Fourier atoms, whose frequencies come in the order of 3682 function setu: sets u[I+1] as base-band windowed Fourier atoms, whose frequencies come in the order of
3681 0, 1, -1, 2, -2, 3, -3, 4, etc, in bins. 3683 0, 1, -1, 2, -2, 3, -3, 4, etc, in bins.
3682 3684
3683 In: I, Wid: number and size of atoms to generate. 3685 In: I, Wid: number and size of atoms to generate.
3684 WinOrder: order (=vanishing moment) of window function to use (2=Hann, 4=Hann^2, etc.) 3686 WinOrder: order (=vanishing moment) of window function to use (2=Hann, 4=Hann^2, etc.)
3705 } 3707 }
3706 } 3708 }
3707 DeAlloc2(wins); 3709 DeAlloc2(wins);
3708 }//setu 3710 }//setu
3709 3711
3710 /* 3712 /**
3711 function DerivativePiecewiseI: wrapper for DerivativePiecewise(), doing the initialization ,etc. 3713 function DerivativePiecewiseI: wrapper for DerivativePiecewise(), doing the initialization ,etc.
3712 3714
3713 In: L, T: number and length of pieces 3715 In: L, T: number and length of pieces
3714 s[LT]: waveform signal 3716 s[LT]: waveform signal
3715 ds[LT]: derivative of s[LT], used only when ERROR_CHECK is defined. 3717 ds[LT]: derivative of s[LT], used only when ERROR_CHECK is defined.
3737 3739
3738 DerivativePiecewise(N, aita, L, f, T, s, A, M, h, I, u, du, endmode, ds); 3740 DerivativePiecewise(N, aita, L, f, T, s, A, M, h, I, u, du, endmode, ds);
3739 delete mlist; 3741 delete mlist;
3740 }//DerivativePiecewiseI 3742 }//DerivativePiecewiseI
3741 3743
3742 /* 3744 /**
3743 function DerivativePiecewiseII: wrapper for DerivativePiecewise2(), doing the initialization ,etc. 3745 function DerivativePiecewiseII: wrapper for DerivativePiecewise2(), doing the initialization ,etc.
3744 This models the derivative of log ampltiude and frequency as separate piecewise polynomials, the first 3746 This models the derivative of log ampltiude and frequency as separate piecewise polynomials, the first
3745 specified by SpecifyA, the second by SpecifyB. 3747 specified by SpecifyA, the second by SpecifyB.
3746 3748
3747 In: L, T: number and length of pieces 3749 In: L, T: number and length of pieces
3776 DerivativePiecewise2(Np, p, Nq, q, L, f, T, s, A, B, M, h, I, u, du, endmode, ds); 3778 DerivativePiecewise2(Np, p, Nq, q, L, f, T, s, A, B, M, h, I, u, du, endmode, ds);
3777 3779
3778 delete mlist; 3780 delete mlist;
3779 }//DerivativePiecewiseII 3781 }//DerivativePiecewiseII
3780 3782
3781 /* 3783 /**
3782 function DerivativePiecewiseIII: wrapper for DerivativePiecewise3(), doing the initialization ,etc. 3784 function DerivativePiecewiseIII: wrapper for DerivativePiecewise3(), doing the initialization ,etc.
3783 Notice that this time the log amplitude, rather than its derivative, is modeled as a piecewise 3785 Notice that this time the log amplitude, rather than its derivative, is modeled as a piecewise
3784 polynomial specified by SpecifyA. 3786 polynomial specified by SpecifyA.
3785 3787
3786 In: L, T: number and length of pieces 3788 In: L, T: number and length of pieces
3824 DerivativePiecewise3(Np, p, Nq, q, L, f, T, s, A, B, M, h, I, u, du, endmode, ds, dh); 3826 DerivativePiecewise3(Np, p, Nq, q, L, f, T, s, A, B, M, h, I, u, du, endmode, ds, dh);
3825 3827
3826 delete mlist; 3828 delete mlist;
3827 }//DerivativePiecewiseIII 3829 }//DerivativePiecewiseIII
3828 3830
3829 /* 3831 /**
3830 function AmpPhCorrectionExpA: model-preserving amplitude and phase correction in piecewise derivative 3832 function AmpPhCorrectionExpA: model-preserving amplitude and phase correction in piecewise derivative
3831 method. 3833 method.
3832 3834
3833 In: aita[N]: inital independent coefficients 3835 In: aita[N]: inital independent coefficients
3834 L, T: number and size of pieces 3836 L, T: number and size of pieces
3966 } 3968 }
3967 double result=s2ph[0]; 3969 double result=s2ph[0];
3968 delete mlist; 3970 delete mlist;
3969 return result; 3971 return result;
3970 }//AmpPhCorrectionExpA 3972 }//AmpPhCorrectionExpA
3973