-
Notifications
You must be signed in to change notification settings - Fork 29
/
MulticueF0v14.m
3094 lines (2844 loc) · 97.2 KB
/
MulticueF0v14.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [f0raw,vuv,auxouts,prm]=MulticueF0v14(x,fs,f0floor,f0ceil)
% Source information extraction using multiple cues
% Default values are used when other arguments are missing.
% You can modify specific parameters by assigning them.
% The control parameters open to user in this version are
% F0 search range.
% Examples:
% f0=MulticueF0v14(x,fs);
% x: input signal (monaural signal)
% fs: sampling frequency (Hz)
% f0: fundamental frequency (Hz)
% f0 is set to zero when unvoiced.
% f0=MulticueF0v14(x,fs,f0floor,f0ceil)
% f0floor: Lower limit of F0 search (Hz)
% f0ceil: Upper limit of F0 search (Hz)
% [f0raw,vuv,auxouts]=MulticueF0v14(x,fs,f0floor,f0ceil)
% f0raw: fundamental frequency without V/UV information
% vuv: V/UV indicator, 1:voiced, 0: unvoiced
% auxouts: base information for f0 extraction (structure variable)
%
% [f0raw,vuv,auxouts,prmouts]=MulticueF0v14(x,fs,prmin)
% prmin: structure variable for control parameters
% f0raw: fundamental frequency without V/UV information
% vuv: V/UV indicator, 1:voiced, 0: unvoiced
% auxouts: base information for f0 extraction (structure variable)
% prmouts: structure variable showing used control parameters
%
% Copyright(c) Wakayama University, 2004
% This version is very experimental. No warranty.
% Please contact: [email protected]
% Designed and coded by Hideki Kawahara
% 31/August/2004 first conceiled version
% 27/September/2004 revised version v10
% 14/November/2004 revised version v11
% 12/January/2005 revised version v12
% 13/January/2005 graphics disabled version
% 10/May/2005 added control input
switch nargin
case {2,4}
case 3
if ~isstruct(f0floor)
ok=displayusage;
f0raw=[];vuv=[];
return;
else
prmin = f0floor;
end;
otherwise
ok=displayusage;
f0raw=[];vuv=[];
return;
end
switch nargin
case 3
case 4
prmin.F0searchLowerBound=f0floor;
prmin.F0searchUpperBound=f0ceil;
prmin.DisplayPlots=0;
otherwise
prmin.DisplayPlots=0;
end;
[f0raw,vuv,auxouts,prm]=SourceInfobyMultiCues050111(x,fs,prmin);
nn=min(length(vuv),length(f0raw));
f0raw=f0raw(1:nn)';
vuv=vuv(1:nn)';
switch nargout
case 1
f0raw=f0raw.*vuv;
case {3,4}
otherwise
ok=displayusage;
return;
end
return;
function ok=displayusage;
fprintf(' Source information extraction using multiple cues\n');
fprintf(' Default values are used when other arguments are missing.\n');
fprintf(' You can modify specific parameters by assigning them.\n');
fprintf(' The control parameters open to user in this version are\n');
fprintf(' F0 search range.\n');
fprintf(' Example:1\n');
fprintf(' f0=MulticueF0v14(x,fs);\n');
fprintf(' x: input signal (monaural signal)\n');
fprintf(' fs: sampling frequency (Hz)\n');
fprintf(' f0: fundamental frequency (Hz)\n');
fprintf(' f0 is set to zero when unvoiced.\n');
fprintf(' f0=MulticueF0v14(x,fs,f0floor,f0ceil)\n');
fprintf(' f0floor: Lower limit of F0 search (Hz)\n');
fprintf(' f0ceil: Upper limit of F0 search (Hz)\n');
fprintf(' [f0raw,vuv,auxouts]=MulticueF0v14(x,fs,f0floor,f0ceil)\n');
fprintf(' f0raw: fundamental frequency without V/UV information\n');
fprintf(' vuv: V/UV indicator, 1:voiced, 0: unvoiced\n');
fprintf(' auxouts: base information for f0 extraction (structure variable)\n');
fprintf(' [f0raw,vuv,auxouts,prmouts]=MulticueF0v14(x,fs,prmin)\n');
fprintf(' prmin: structure variable for control parameters\n');
fprintf(' f0raw: fundamental frequency without V/UV information\n');
fprintf(' vuv: V/UV indicator, 1:voiced, 0: unvoiced\n');
fprintf(' auxouts: base information for f0 extraction (structure variable)\n');
fprintf(' prmouts: structure variable showing used control parameters\n');
fprintf('\n');
fprintf(' Copyright(c) Wakayama University, 2004,2005\n');
fprintf(' This version is very experimental. No warranty.\n');
fprintf(' Please contact: [email protected]\n');
ok=1;
function [f0raw,vuv,auxouts,prm]=SourceInfobyMultiCues050111(x,fs,prmin)
% Source information extraction function
% with combined source information
% minimum requisite is to provide x and fs and receive f0.
% Default values are used when other arguments are missing.
% You can modify specific parameters by assigning using prmin.
% Example:1
% SourceInfobyMultiCues050111(x,fs);
% Simplest usage
% Example:2
% f0raw=SourceInfobyMultiCues050111(x,fs);
% F0 for voiced segment is what you get.
% Example:3
% [f0raw,vuv,auxouts,prm]=SourceInfobyMultiCues050111(x,fs);
% You can check what defaults were and raw information.
% Example:4
% [f0raw,vuv,auxouts,prm]=SourceInfobyMultiCues050111(x,fs,prmin);
% You have full control (and responsibility).
% Designed and coded by Hideki Kawahara
% 24/June/2004
% 26/June/2004
% 30/June/2004
% 01/July/2004
% 04/July/2004 New mixing method without mixed map
% 05/July/2004 Revised tracking measure
% 06/July/2004 Revised tracking lgorithm further and bug fix
% 07/July/2004 Revised tracking, funcamental bug fix
% 10/July/2004 Revised proprocessing for fs independence
% 15/July/2004 Bug fix for batch job
% 16/July/2004 Revised for better initial position
% 17/July/2004 Updated default values to improve robustness
% 18/July/2004 Bug fix in tracking (boundary value)
% 19/July/2004 Bug fix in tracking revised default parameters
% 21/July/2004 Bug fix in tracking revised default parameters
% 23/July/2004 New deconvolution of autocorrelation
% 25/July/2004 Bug fix in tracking
% 25/July/2004 Revised map merge procedure
% 27/July/2004 Straightforward tracking routine
% 29/July/2004 Combined tracking and fine tuning parameters
% 02/Aug./2004 New tracking algorithm
% 07/Aug./2004 Yet other tracking (segment selection) algorithm
% 14/Aug./2004 Added missing segment recovary
% 15/Aug./2004 New V/UV decision logic was integrated
% 31/Aug./2004 minor bug fix
% 25/Aug./2004 bug fix and revised when no output is assigned
% 11/Jan./2005 minor bug fix for boundary logic
% 12/Jan./2005 bug fix for all zero segment
% Assuming x consists of data
% Assuming fs consists of sampling frequency (Hz)
%------ check input arguments
prm=zsetdefaultparams;
switch nargin
case {2,3}
otherwise
help SourceInfobyMultiCues040701
f0raw=[];vuv=[];
return;
end
[nn,mm]=size(x);
if min(nn,mm)>1
display('Using only the first channel.');
if nn<mm
x=x(1,:);
else
x=x(:,1);
end;
end;
x=x(:); % make sure x is a column vector.
%--- safe guard for all zero segments 12/Jan./2005
l1ms=round(fs/1000);
if length(x(x==0))>l1ms % bug fix 16/Aug./2008
zv=randn(size(x(x==0)));
zv=cumsum(zv-mean(zv));
zv=zv/std(zv)*std(x)/10000;
x(x==0)=zv;
end;
%------ set initial parameters
if nargin==3
if isfield(prmin,'F0searchLowerBound')==1;
prm.F0searchLowerBound=prmin.F0searchLowerBound;end;
if isfield(prmin,'F0searchUpperBound')==1;
prm.F0searchUpperBound=prmin.F0searchUpperBound;end;
if isfield(prmin,'F0frameUpdateInterval')==1;
prm.F0frameUpdateInterval=prmin.F0frameUpdateInterval;end;
if isfield(prmin,'NofChannelsInOctave')==1;
prm.NofChannelsInOctave=prmin.NofChannelsInOctave;end;
if isfield(prmin,'IFWindowStretch')==1;
prm.IFWindowStretch=prmin.IFWindowStretch;end;
if isfield(prmin,'DisplayPlots')==1;
prm.DisplayPlots=prmin.DisplayPlots;end;
if isfield(prmin,'IFsmoothingLengthRelToFc')==1;
prm.IFsmoothingLengthRelToFc=prmin.IFsmoothingLengthRelToFc;end;
if isfield(prmin,'IFminimumSmoothingLength')==1;
prm.IFminimumSmoothingLength=prmin.IFminimumSmoothingLength;end;
if isfield(prmin,'IFexponentForNonlinearSum')==1;
prm.IFexponentForNonlinearSum=prmin.IFexponentForNonlinearSum;end;
if isfield(prmin,'IFnumberOfHarmonicForInitialEstimate')==1;
prm.IFnumberOfHarmonicForInitialEstimate=prmin.IFnumberOfHarmonicForInitialEstimate;end;
if isfield(prmin,'TimeConstantForPowerCalculation')==1;
prm.TimeConstantForPowerCalculation=prmin.TimeConstantForPowerCalculation;end;
if isfield(prmin,'ACtimeWindowLength')==1;
prm.ACtimeWindowLength=prmin.ACtimeWindowLength;end;
if isfield(prmin,'ACnumberOfFrequencySegments')==1;
prm.ACnumberOfFrequencySegments=prmin.ACnumberOfFrequencySegments;end;
if isfield(prmin,'ACfrequencyDomainWindowWidth')==1;
prm.ACfrequencyDomainWindowWidth=prmin.ACfrequencyDomainWindowWidth;end;
if isfield(prmin,'ACpowerExponentForNonlinearity')==1;
prm.ACpowerExponentForNonlinearity=prmin.ACpowerExponentForNonlinearity;end;
if isfield(prmin,'ACamplitudeCompensationInShortLag')==1;
prm.ACamplitudeCompensationInShortLag=prmin.ACamplitudeCompensationInShortLag;end;
if isfield(prmin,'ACexponentForACdistance')==1;
prm.ACexponentForACdistance=prmin.ACexponentForACdistance;end;
if isfield(prmin,'AClagSmoothingLength')==1;
prm.AClagSmoothingLength=prmin.AClagSmoothingLength;end;
if isfield(prmin,'ACtemporalSmoothingLength')==1;
prm.ACtemporalSmoothingLength=prmin.ACtemporalSmoothingLength;end;
if isfield(prmin,'ThresholdForSilence')==1;
prm.ThresholdForSilence=prmin.ThresholdForSilence;end;
if isfield(prmin,'ThresholdForVUV')==1;
prm.ThresholdForVUV=prmin.ThresholdForVUV;end;
if isfield(prmin,'WeightForAutocorrelationMap')==1;
prm.WeightForAutocorrelationMap=prmin.WeightForAutocorrelationMap;end;
if isfield(prmin,'WeightForInstantaneousFqMap')==1;
prm.WeightForInstantaneousFqMap=prmin.WeightForInstantaneousFqMap;end;
if isfield(prmin,'VUVthresholdOfAC1')==1;
prm.VUVthresholdOfAC1=prmin.VUVthresholdOfAC1;end;
if isfield(prmin,'SDforNormalizeMixingDistance')==1;
prm.SDforNormalizeMixingDistance=prmin.SDforNormalizeMixingDistance;end;
if isfield(prmin,'SDforTrackingNormalization')==1;
prm.SDforTrackingNormalization=prmin.SDforTrackingNormalization;end;
if isfield(prmin,'MaxumumPermissibleOctaveJump')==1;
prm.MaxumumPermissibleOctaveJump=prmin.MaxumumPermissibleOctaveJump;end;
if isfield(prmin,'ThresholdToStartSearch')==1;
prm.ThresholdToStartSearch=prmin.ThresholdToStartSearch;end;
if isfield(prmin,'ThresholdToQuitSearch')==1;
prm.ThresholdToQuitSearch=prmin.ThresholdToQuitSearch;end;
if isfield(prmin,'ThresholdForReliableRegion')==1;
prm.ThresholdForReliableRegion=prmin.ThresholdForReliableRegion;end;
end;
%----- copy modified analysis conditions to internal variables
f0floor=prm.F0searchLowerBound; % f0floor
f0ceil=prm.F0searchUpperBound; % f0ceil
shiftm=prm.F0frameUpdateInterval; % % F0 calculation interval (ms)
nvo=prm.NofChannelsInOctave; % nvo=24; % Number of channels in one octave
mu=prm.IFWindowStretch; % mu=1.2; % window stretch from isometric window
imgi=prm.DisplayPlots; % imgi=1; % image display indicator (1: display image)
smp=prm.IFsmoothingLengthRelToFc; % smp=1; % smoothing length relative to fc (ratio)
minm=prm.IFminimumSmoothingLength; % minm=5; % minimum smoothing length (ms)
pcIF=prm.IFexponentForNonlinearSum; % pc=0.5; % exponent to represent nonlinear summation
ncIF=prm.IFnumberOfHarmonicForInitialEstimate; % nc=1; % number of harmonic component to use (1,2,3)
tcpower=prm.TimeConstantForPowerCalculation; % tcpower=10; % time constant for power calculation (ms)
wtlm=prm.ACtimeWindowLength; % Time window length for Autocorrelation based method (ms)
ndiv=prm.ACnumberOfFrequencySegments; % for Autocorrelation method
wflf=prm.ACfrequencyDomainWindowWidth; % for Autocorrelation method (Hz)
pcAC=prm.ACpowerExponentForNonlinearity; % for Autocorrelation method
ampAC=prm.ACamplitudeCompensationInShortLag; % for Autocorrelation method (ratio)
betaAC=prm.ACexponentForACdistance; % Nonlinear distance measure for post processing
lagslAC=prm.AClagSmoothingLength; % Lag smoothing length for post processing (s) !!
timeslAC=prm.ACtemporalSmoothingLength; % Temporal smoothing length for post processing (ms)
thsilence=prm.ThresholdForSilence; % for silence decision above average noise level (dB)
thvuv=prm.ThresholdForVUV; % for V/UV decision based on first autocorrelation and C/N
wAC=prm.WeightForAutocorrelationMap; % weight for combining maps (Autocorrelation)
wIF=prm.WeightForInstantaneousFqMap; % weight for combining maps (Instantaneous Frequency)
ac1th=prm.VUVthresholdOfAC1;
mixsd=prm.SDforNormalizeMixingDistance; % Normalization factor for mixing F0 distance (octave)
nsd=prm.SDforTrackingNormalization;
f0jump=prm.MaxumumPermissibleOctaveJump;
strel=prm.ThresholdToStartSearch;
endrel=prm.ThresholdToQuitSearch;
endrel2=prm.ThresholdForReliableRegion;
nvc=ceil(log(f0ceil/f0floor)/log(2)*nvo); ...
% Number of channels in whole search range
%------- extract fixed points of frequency to instantaneous frequency map
[f0v,vrv,dfv,nf,aav]= ...
zfixpF0VexMltpBG4(x,fs,f0floor,nvc,nvo,mu,imgi,shiftm,smp,minm,pcIF,ncIF);
[val,pos]=zmultiCandIF(f0v,vrv);
[y,ind,fq]=zremoveACinduction(x,fs,pos);
%------- Pre processing of AC induction if necessary
if ind==1
xbak=x;x=y;
[f0v,vrv,dfv,nf,aav]= ...
zfixpF0VexMltpBG4(x,fs,f0floor,nvc,nvo,mu,imgi,shiftm,smp,minm,pcIF,ncIF);
end;
%---- selecting multiple F0 candidates based on IF
[val,pos]=zmultiCandIF(f0v,vrv);
if imgi==1
hh=figure;semilogy(pos,'+');grid on;hold on;
set(gca,'fontsize',16);
axis([0 length(x)/fs*1000 f0floor f0ceil]);
end;
%---- selecting multiple F0 candidates based on modified Autocorrelation
dn=max(1,floor(fs/max(8000,3*2*f0ceil)));
if imgi==1;
h1=figure;
else
h1=-1;
end;
[lagspec,lx]= ...
zlagspectestnormal(decimate(x,dn),fs/dn,shiftm,length(x)/fs*1000,shiftm,wtlm,ndiv,wflf,pcAC,ampAC,h1);
[f02,pl2]=zmultiCandAC(lx,lagspec,betaAC,lagslAC,timeslAC);
if imgi==1
figure(hh);semilogy(f02,'o');hold off
xlabel('time (ms)');ylabel('frequency (Hz)');
title('F0 candidates: o:autocorrelation +:instantaneous frequency')
end;
%----- Combine multiple source information with dynamic range normalization
%[f0mapIF,f0mapAC,fx]=zCombineSourceInfoNorm(val,pos,f02,pl2,f0floor,f0ceil,nvo);
%----- selecting multiple F0 candidates based on multiple source
%[f0cand,relv]=zmultiCandf0map(fx,wIF*f0mapIF+wAC*f0mapAC);
auxouts.F0candidatesByIF=pos;
auxouts.CNofcandidatesByIF=val;
auxouts.F0candidatesByAC=f02;
auxouts.ACofcandidatesByAC=pl2;
[f0cand,relv]=zcombineRanking4(auxouts,mixsd,wAC,wIF,prm); % New mixing routine
%f0cand=f0cand(:,1:3);
%relv=relv(:,1:3);
if imgi==1
figure
semilogy(f0cand,'+');grid on;
set(gca,'fontsize',16);
axis([0 length(f0cand) f0floor f0ceil]);
title('F0 candidates by mixed source information');
xlabel('time (ms)')
ylabel('frequency (Hz)')
end;
%keyboard
%----- Calculate power envelope
pws=zVpowercalc(x,fs,tcpower,shiftm,2000);
pwsdb=10*log10(abs(pws)+0.00000000001);
mxpwsdb=max(pwsdb);
[hstgrm,binlvl]=hist(pwsdb,mxpwsdb+(-60:2));
q10=interp1(cumsum(hstgrm+0.000000001)/sum(hstgrm)*100,binlvl,10); % 10% quantile level
[dmy1,minid]=min(abs(q10-binlvl));
bb=max(1,min(length(binlvl),minid+(-5:5))); % search range 10 dB % safeguard
noiselevel=sum(hstgrm(bb).*binlvl(bb))/sum(hstgrm(bb));
if imgi==1
figure
plot(pwsdb);grid on;
set(gca,'fontsize',16);
axis([0 length(pwsdb) noiselevel-10 max(pwsdb)]);
hold on;
plot([0 length(pwsdb)],noiselevel*[1 1],'r');
plot([0 length(pwsdb)],noiselevel*[1 1]+3,'r-.');
title('Instantaneous power solid line:noise level, dash-dot line:threshold')
xlabel('time (ms)');ylabel('power (dB)')
end;
%----- F0 tracking
ac1=zeros(1,length(f0cand));
for ii=1:length(f0cand)
ac1(ii)=zfirstac(x,fs,round(ii/1000*fs),30);
end;
auxouts.F0candidatesByMix=f0cand;
auxouts.RELofcandidatesByMix=relv;
auxouts.FirstAutoCorrelation=ac1;
auxouts.InstantaneousPower=pwsdb;
%f0raw0=zf0trackmulti(auxouts,ac1th,f0jump,nsd);
%[f0raw0,segb]=zf0trackmulti25(auxouts,ac1th,f0jump,nsd,prm); %
%27/July/2004
%[f0s,rels,csegs]=contiguousSegment6(auxouts,strel,endrel,endrel2,prm);
[f0s,rels,csegs]=zcontiguousSegment10(auxouts,prm);
[f0raw0,relc]=zfillf0gaps6(auxouts,f0s,rels,csegs,prm);
%[f0s,rels,csegs]=zcontiguousSegment2(auxouts,0.55,0.16,0.4);% first param. was 0.5 (by 3AM 28)
%f0raw0(f0s>0)=f0s(f0s>0);
if imgi==1;
figure
semilogy(f0raw0,'c');grid on;
set(gca,'fontsize',16);
axis([0 length(f0raw0) f0floor f0ceil]);
drawnow;
end;
%------ F0 refinement using first three harmonic components
f0raw0(isnan(f0raw0))=zeros(size(f0raw0(isnan(f0raw0))));
f0raw0(f0raw0>f0ceil)=f0raw0(f0raw0>f0ceil)*0+f0ceil;
f0raw0((f0raw0<f0floor)&(f0raw0>0))=f0raw0((f0raw0<f0floor)&(f0raw0>0))*0+f0floor;
%dn2=floor(fs/(f0ceil*3*2));
[f0raw2,ecr,ac1]=zrefineF06m(decimate(x,dn),fs/dn,f0raw0,1024,1.1,3,1,1,length(f0raw0));
if imgi==1;
hold on;
semilogy(f0raw2,'g');grid on;
end;
%------ Threshoulding for silence and V/UV
%thsilence=3; % for silence
%thvuv=0.6; % for V/UV
%f00=f0raw2;
%f00(pwsdb(1:length(f00))<(noiselevel+thsilence))=f00(pwsdb(1:length(f00))<(noiselevel+thsilence))*0;
%f0raw3=f00;
%f0raw3((zdB(ecr)/100+ac1)<thvuv)=f0raw3((zdB(ecr)/100+ac1)<thvuv)*0;
%----- new V/UV decision routine 15/Aug./2004
auxouts.BackgroundNoiselevel=noiselevel;
vuv=zvuvdecision4(f0raw2,auxouts);
nnll=min(length(f0raw2),length(vuv));
f0raw3=f0raw2(1:nnll).*vuv(1:nnll);
if imgi==1
semilogy(f0raw3,'k');hold off
title('F0 estimates, cyan:initial, greeen:fine-tuned, black:voiced part')
xlabel('time (ms)');ylabel('frequency (Hz)');
end;
%vuv=zdB(ecr)/100+ac1;
f0raw=f0raw2(1:nnll);vuv=vuv(1:nnll);
auxouts.F0candidatesByIF=pos;
auxouts.CNofcandidatesByIF=val;
auxouts.F0candidatesByAC=f02;
auxouts.ACofcandidatesByAC=pl2;
auxouts.F0candidatesByMix=f0cand;
auxouts.RELofcandidatesByMix=relv;
auxouts.RefinedCN=ecr;
auxouts.FirstAutoCorrelation=ac1;
auxouts.F0initialEstimate=f0raw0;
auxouts.BackgroundNoiselevel=noiselevel;
auxouts.InstantaneousPower=pwsdb;
auxouts.RefinedF0estimates=f0raw;
auxouts.VUVindicator=vuv;
if imgi==1; displaysummary(auxouts,f0floor,f0ceil); end;
switch nargout
case 0
f0raw=auxouts;eval(['help ' mfilename]);
case 1
f0raw=f0raw3;
case 2
case {3,4}
otherwise
eval(['help ' mfilename]);
return;
end
%------
function prm=zsetdefaultparams;
prm.F0searchLowerBound=40; % f0floor
prm.F0searchUpperBound=800; % f0ceil
prm.F0frameUpdateInterval=1; % shiftm % F0 calculation interval (ms)
prm.NofChannelsInOctave=24; % nvo=24; % Number of channels in one octave
prm.IFWindowStretch=1.2; % mu=1.2; % window stretch from isometric window
prm.DisplayPlots=0; % imgi=1; % image display indicator (1: display image)
prm.IFsmoothingLengthRelToFc=1; % smp=1; % smoothing length relative to fc (ratio)
prm.IFminimumSmoothingLength=5; % minm=5; % minimum smoothing length (ms)
prm.IFexponentForNonlinearSum=0.5; % pc=0.5; % exponent to represent nonlinear summation
prm.IFnumberOfHarmonicForInitialEstimate=1; % nc=1; % number of harmonic component to use (1,2,3)
prm.TimeConstantForPowerCalculation=10; % tcpower=10; % time constant for power calculation (ms)
prm.ACtimeWindowLength=60; % Time window length for Autocorrelation based method (ms)
prm.ACnumberOfFrequencySegments=8; % for Autocorrelation method
prm.ACfrequencyDomainWindowWidth=2200; % for Autocorrelation method (Hz)
prm.ACpowerExponentForNonlinearity=0.5; % for Autocorrelation method
prm.ACamplitudeCompensationInShortLag=1.6; %2.2; % for Autocorrelation method (ratio) 23/July/2004
prm.ACexponentForACdistance=4; % Nonlinear distance measure for post processing
prm.AClagSmoothingLength=0.0001; % Lag smoothing length for post processing (s) !! 0.01 to 0.0001 23/July/2004
prm.ACtemporalSmoothingLength=20; % Temporal smoothing length for post processing (ms)
prm.ThresholdForSilence=3; % for silence decision above average noise level (dB)
prm.ThresholdForVUV=0.6; % for V/UV decision based on first autocorrelation and C/N
prm.WeightForAutocorrelationMap=1; % weight for combining maps (Autocorrelation)
prm.WeightForInstantaneousFqMap=1; % weight for combining maps (Instantaneous Frequency)
prm.VUVthresholdOfAC1=-0.1; % First autocorrelation thershould for VUV in segment search
prm.SDforNormalizeMixingDistance=0.3; % Normalization factor for mixing F0 distance (octave)
prm.SDforTrackingNormalization=0.2;
prm.MaxumumPermissibleOctaveJump=0.4;
prm.ThresholdToStartSearch=0.3;
prm.ThresholdToQuitSearch=0.35;
prm.ThresholdForReliableRegion=0.25;
prm.WhoAmI=mfilename;
return;
%%%------------
function oki=displaysummary(f,f0floor,f0ceil)
oki=1;
nn=length(f.RefinedF0estimates);
figure
subplot(211);
semilogy(f.F0initialEstimate,'c');grid on;
hold on;
semilogy(f.RefinedF0estimates.*f.VUVindicator,'b');grid on;
set(gca,'fontsize',14);
xlabel('time (ms)');
ylabel('frequency (Hz)');
axis([1 nn f0floor f0ceil]);
subplot(212);
plot(f.RELofcandidatesByMix,'.');grid on;
set(gca,'fontsize',14);
xlabel('time (ms)');
ylabel('relative periodicity');
axis([1 nn 0 1]);
drawnow
%%%------------
function [f0v,vrv,dfv,nf,aav]=zfixpF0VexMltpBG4(x,fs,f0floor,nvc,nvo,mu,imgi,shiftm,smp,minm,pc,nc)
% Fixed point analysis to extract F0
% [f0v,vrv,dfv,nf]=fixpF0VexMltpBG4(x,fs,f0floor,nvc,nvo,mu,imgi,shiftm,smp,minm,pc,nc)
% x : input signal
% fs : sampling frequency (Hz)
% f0floor : lowest frequency for F0 search
% nvc : total number of filter channels
% nvo : number of channels per octave
% mu : temporal stretching factor
% imgi : image display indicator (1: display image)
% shiftm : frame shift in ms
% smp : smoothing length relative to fc (ratio)
% minm : minimum smoothing length (ms)
% pc : exponent to represent nonlinear summation
% nc : number of harmonic component to use (1,2,3)
% Designed and coded by Hideki Kawahara
% 28/March/1999
% 04/April/1999 revised to multi component version
% 07/April/1999 bi-reciprocal smoothing for multi component compensation
% 01/May/1999 first derivative of Amplitude is taken into account
% 17/Dec./2000 display bug fix
% 19/Sep./2002 bug fix (mu information was discarded.)
% 07/Dec./2002 waitbar was added
%f0floor=40;
%nvo=12;
%nvc=52;
%mu=1.1;
x=cleaninglownoise(x,fs,f0floor);
fxx=f0floor*2.0.^((0:nvc-1)/nvo)';
fxh=max(fxx);
dn=max(1,floor(fs/(fxh*6.3)));
if nc>2
pm3=zmultanalytFineCSPB(decimate(x,dn),fs/dn,f0floor,nvc,nvo,mu,3); % error crrect 2002.9.19 (mu was fixed 1.1)
pif3=zwvlt2ifq(pm3,fs/dn);
[nn,mm]=size(pif3);
pif3=pif3(:,1:3:mm);
pm3=pm3(:,1:3:mm);
end;
if nc>1
pm2=zmultanalytFineCSPB(decimate(x,dn),fs/dn,f0floor,nvc,nvo,mu,2);% error crrect 2002.9.19(mu was fixed 1.1)
pif2=zwvlt2ifq(pm2,fs/dn);
[nn,mm]=size(pif2);
pif2=pif2(:,1:3:mm);
pm2=pm2(:,1:3:mm);
end;
pm1=zmultanalytFineCSPB(decimate(x,dn*3),fs/(dn*3),f0floor,nvc,nvo,mu,1);% error crrect 2002.9.19(mu was fixed 1.1)
%%%% safe guard added on 15/Jan./2003
mxpm1=max(max(abs(pm1)));
eeps=mxpm1/10000000;
pm1(pm1==0)=pm1(pm1==0)+eeps;
%%%% safe guard end
pif1=zwvlt2ifq(pm1,fs/(dn*3));
%keyboard;
[nn,mm1]=size(pif1);
mm=mm1;
if nc>1
[nn,mm2]=size(pif2);
mm=min(mm1,mm2);
end;
if nc>2
[nn,mm3]=size(pif3);
mm=min([mm1 mm2 mm3]);
end;
if nc == 2
for ii=1:mm
pif2(:,ii)=(pif1(:,ii).*(abs(pm1(:,ii))).^pc ...
+pif2(:,ii)/2.*(abs(pm2(:,ii))).^pc )...
./((abs(pm1(:,ii))).^pc+(abs(pm2(:,ii))).^pc);
end;
end;
if nc == 3
for ii=1:mm
pif2(:,ii)=(pif1(:,ii).*(abs(pm1(:,ii))).^pc ...
+pif2(:,ii)/2.*(abs(pm2(:,ii))).^pc ...
+pif3(:,ii)/3.*(abs(pm3(:,ii))).^pc )...
./((abs(pm1(:,ii))).^pc+(abs(pm2(:,ii))).^pc+(abs(pm3(:,ii))).^pc);
end;
end;
if nc == 1
pif2=pif1;
end;
%pif2=zwvlt2ifq(pm,fs/dn)*2*pi;
pif2=pif2*2*pi;
dn=dn*3;
[slp,pbl]=zifq2gpm2(pif2,f0floor,nvo);
[nn,mm]=size(pif2);
dpif=[pif2(:,2:mm)-pif2(:,1:mm-1)]*fs/dn;
dpif(:,mm)=dpif(:,mm-1);
[dslp,dpbl]=zifq2gpm2(dpif,f0floor,nvo);
damp=[abs(pm1(:,2:mm))-abs(pm1(:,1:mm-1))]*fs/dn;
damp(:,mm)=damp(:,mm-1);
damp=damp./abs(pm1);
%[c1,c2]=znormwght(1000);
fxx=f0floor*2.0.^((0:nn-1)/nvo)'*2*pi;
mmp=0*dslp;
[c1,c2b]=znrmlcf2(1);
%%%hpg=waitbar(0,'P/N map calculation'); % 07/Dec./2002 by H.K.
for ii=1:nn
% [c1,c2]=znrmlcf2(fxx(ii)/2/pi); % This is OK, but the next Eq is much faster.
c2=c2b*(fxx(ii)/2/pi)^2;
cff=damp(ii,:)/fxx(ii)*2*pi*0;
mmp(ii,:)=(dslp(ii,:)./(1+cff.^2)/sqrt(c2)).^2+(slp(ii,:)./sqrt(1+cff.^2)/sqrt(c1)).^2;
%%%waitbar(ii/nn);%,hpg); % 07/Dec./2002 by H.K.
end;
%%%close(hpg);
if smp~=0
smap=zsmoothmapB(mmp,fs/dn,f0floor,nvo,smp,minm,0.4);
else
smap=mmp;
end;
fixpp=zeros(round(nn/3),mm);
fixvv=fixpp+100000000;
fixdf=fixpp+100000000;
fixav=fixpp+1000000000;
nf=zeros(1,mm);
%%%hpg=waitbar(0,'Fixed pints calculation'); % 07/Dec./2002 by H.K.
for ii=1:mm
[ff,vv,df,aa]=zfixpfreq3(fxx,pif2(:,ii),smap(:,ii),dpif(:,ii)/2/pi,pm1(:,ii));
kk=length(ff);
fixpp(1:kk,ii)=ff;
fixvv(1:kk,ii)=vv;
fixdf(1:kk,ii)=df;
fixav(1:kk,ii)=aa;
nf(ii)=kk;
%%%if rem(ii,10)==0; waitbar(ii/mm); end;% 07/Dec./2002 by H.K.
end;
%%%close(hpg); % 07/Dec./2002 by H.K.
fixpp(fixpp==0)=fixpp(fixpp==0)+1000000;
%keyboard
%[vvm,ivv]=min(fixvv);
%
%for ii=1:mm
% ff00(ii)=fixpp(ivv(ii),ii);
% esgm(ii)=fixvv(ivv(ii),ii);
%end;
np=max(nf);
f0v=fixpp(1:np,round(1:shiftm/dn*fs/1000:mm))/2/pi;
vrv=fixvv(1:np,round(1:shiftm/dn*fs/1000:mm));
dfv=fixdf(1:np,round(1:shiftm/dn*fs/1000:mm));
aav=fixav(1:np,round(1:shiftm/dn*fs/1000:mm));
nf=nf(round(1:shiftm/dn*fs/1000:mm));
if imgi==1
okid=cnmap(fixpp,smap,fs,dn,nvo,f0floor,shiftm);
end;
%ff00=ff00(round(1:shiftm/dn*fs/1000:mm));
%esgm=sqrt(esgm(round(1:shiftm/dn*fs/1000:mm)));
%keyboard;
return;
%------------------------------------------------------------------
function okid=cnmap(fixpp,smap,fs,dn,nvo,f0floor,shiftm)
% This function had a bug in map axis.
% 17/Dec./2000 bug fix by Hideki Kawahara.
dt=dn/fs;
[nn,mm]=size(smap);
aa=figure;
%set(aa,'PaperPosition',[0.3 0.25 8 10.9]);
%set(aa,'Position',[30 130 520 680]);
%subplot(211);
imagesc([0 (mm-1)*dt*1000],[1 nn],zdB(smap(:,round(1:shiftm/dn*fs/1000:mm))));axis('xy')
set(gca,'fontsize',16);
hold on;
tx=((1:shiftm/dn*fs/1000:mm)-1)*dt*1000;
plot(tx,(nvo*log(fixpp(:,round(1:shiftm/dn*fs/1000:mm))/f0floor/2/pi)/log(2)+0.5)','ko');
plot(tx,(nvo*log(fixpp(:,round(1:shiftm/dn*fs/1000:mm))/f0floor/2/pi)/log(2)+0.5)','w.');
hold off
xlabel('time (ms)');
ylabel('channel #');
title('Instantaneous frequency-based fixed points')
colormap(jet);
okid=1;
return;
%------------------------------------------------------------------
function pm=zmultanalytFineCSPm(x,fs,f0floor,nvc,nvo,mu,mlt);
% Dual waveleta analysis using cardinal spline manipulation
% pm=multanalytFineCSP(x,fs,f0floor,nvc,nvo);
% Input parameters
%
% x : input signal (2kHz sampling rate is sufficient.)
% fs : sampling frequency (Hz)
% f0floor : lower bound for pitch search (60Hz suggested)
% nvc : number of total voices for wavelet analysis
% nvo : number of voices in an octave
% mu : temporal stretch factor
% Outpur parameters
% pm : wavelet transform using iso-metric Gabor function
%
% If you have any questions, mailto:[email protected]
%
% Copyright (c) ATR Human Information Processing Research Labs. 1996
% Invented and coded by Hideki Kawahara
% 30/Oct./1996
t0=1/f0floor;
lmx=round(6*t0*fs*mu);
wl=2^ceil(log(lmx)/log(2));
x=x(:)';
nx=length(x);
tx=[x,zeros(1,wl)];
gent=((1:wl)-wl/2)/fs;
%nvc=18;
wd=zeros(nvc,wl);
wd2=zeros(nvc,wl);
ym=zeros(nvc,nx);
pm=zeros(nvc,nx);
mpv=1;
%mu=1.0;
for ii=1:nvc
t=gent*mpv;
t=t(abs(t)<3.5*mu*t0);
wbias=round((length(t)-1)/2);
wd1=exp(-pi*(t/t0/mu).^2);%.*exp(i*2*pi*t/t0);
wd2=max(0,1-abs(t/t0/mu));
wd2=wd2(wd2>0);
wwd=conv(wd2,wd1);
wwd=wwd(abs(wwd)>0.0001);
wbias=round((length(wwd)-1)/2);
wwd=wwd.*exp(i*2*pi*mlt*t(round((1:length(wwd))-wbias+length(t)/2))/t0);
pmtmp1=fftfilt(wwd,tx);
pm(ii,:)=pmtmp1(wbias+1:wbias+nx)*sqrt(mpv);
mpv=mpv*(2.0^(1/nvo));
% keyboard;
end;
%[nn,mm]=size(pm);
%pm=pm(:,1:mlt:mm);
%----------------------------------------------------------------
function pif=zwvlt2ifq(pm,fs)
% Wavelet to instantaneous frequency map
% fqv=wvlt2ifq(pm,fs)
% Coded by Hideki Kawahara
% 02/March/1999
[nn,mm]=size(pm);
pm=pm./(abs(pm));
pif=abs(pm(:,:)-[pm(:,1),pm(:,1:mm-1)]);
pif=fs/pi*asin(pif/2);
pif(:,1)=pif(:,2);
%----------------------------------------------------------------
function [slp,pbl]=zifq2gpm2(pif,f0floor,nvo)
% Instantaneous frequency 2 geometric parameters
% [slp,pbl]=ifq2gpm(pif,f0floor,nvo)
% slp : first order coefficient
% pbl : second order coefficient
% Coded by Hideki Kawahara
% 02/March/1999
[nn,mm]=size(pif);
fx=f0floor*2.0.^([0:nn-1]/nvo)*2*pi;
c=2.0^(1/nvo);
g=[1/c/c 1/c 1;1 1 1;c*c c 1];
h=inv(g);
%slp=pif(1:nn-2,:)*h(1,1)+pif(2:nn-1,:)*h(1,2)+pif(3:nn,:)*h(1,3);
slp=((pif(2:nn-1,:)-pif(1:nn-2,:))/(1-1/c) ...
+(pif(3:nn,:)-pif(2:nn-1,:))/(c-1))/2;
slp=[slp(1,:);slp;slp(nn-2,:)];
pbl=pif(1:nn-2,:)*h(2,1)+pif(2:nn-1,:)*h(2,2)+pif(3:nn,:)*h(2,3);
pbl=[pbl(1,:);pbl;pbl(nn-2,:)];
for ii=1:nn
slp(ii,:)=slp(ii,:)/fx(ii);
pbl(ii,:)=pbl(ii,:)/fx(ii);
end;
%------------------------------------------
%function [c1,c2]=znormwght(n)
%zz=0:1/n:3;
%hh=[diff(zGcBs(zz,0)) 0]*n;
%c1=sum((zz.*hh).^2)/n;
%c2=sum((2*pi*zz.^2.*hh).^2)/n;
%-------------------------------------------
function p=zGcBs(x,k)
tt=x+0.0000001;
p=tt.^k.*exp(-pi*tt.^2).*(sin(pi*tt+0.0001)./(pi*tt+0.0001)).^2;
%--------------------------------------------
function smap=zsmoothmapB(map,fs,f0floor,nvo,mu,mlim,pex)
[nvc,mm]=size(map);
%mu=0.4;
t0=1/f0floor;
lmx=round(6*t0*fs*mu);
wl=2^ceil(log(lmx)/log(2));
gent=((1:wl)-wl/2)/fs;
smap=map;
mpv=1;
zt=0*gent;
iiv=1:mm;
for ii=1:nvc
t=gent*mpv; %t0*mu/mpv*1000
t=t(abs(t)<3.5*mu*t0);
wbias=round((length(t)-1)/2);
wd1=exp(-pi*(t/(t0*(1-pex))/mu).^2);
wd2=exp(-pi*(t/(t0*(1+pex))/mu).^2);
wd1=wd1/sum(wd1);
wd2=wd2/sum(wd2);
tm=fftfilt(wd1,[map(ii,:) zt]);
tm=fftfilt(wd2,[1.0./tm(iiv+wbias) zt]);
smap(ii,:)=1.0./tm(iiv+wbias);
if t0*mu/mpv*1000 > mlim
mpv=mpv*(2.0^(1/nvo));
end;
end;
%--------------------------------------------
function [ff,vv,df]=zfixpfreq2(fxx,pif2,mmp,dfv)
nn=length(fxx);
iix=(1:nn)';
cd1=pif2-fxx;
cd2=[diff(cd1);cd1(nn)-cd1(nn-1)];
cdd1=[cd1(2:nn);cd1(nn)];
fp=(cd1.*cdd1<0).*(cd2<0);
ixx=iix(fp>0);
ff=pif2(ixx)+(pif2(ixx+1)-pif2(ixx)).*cd1(ixx)./(cd1(ixx)-cdd1(ixx));
%vv=mmp(ixx);
vv=mmp(ixx)+(mmp(ixx+1)-mmp(ixx)).*(ff-fxx(ixx))./(fxx(ixx+1)-fxx(ixx));
df=dfv(ixx)+(dfv(ixx+1)-dfv(ixx)).*(ff-fxx(ixx))./(fxx(ixx+1)-fxx(ixx));
%--------------------------------------------
function [ff,vv,df,aa]=zfixpfreq3(fxx,pif2,mmp,dfv,pm)
aav=abs(pm);
nn=length(fxx);
iix=(1:nn)';
cd1=pif2-fxx;
cd2=[diff(cd1);cd1(nn)-cd1(nn-1)];
cdd1=[cd1(2:nn);cd1(nn)];
fp=(cd1.*cdd1<0).*(cd2<0);
ixx=iix(fp>0);
ff=pif2(ixx)+(pif2(ixx+1)-pif2(ixx)).*cd1(ixx)./(cd1(ixx)-cdd1(ixx));
%vv=mmp(ixx);
vv=mmp(ixx)+(mmp(ixx+1)-mmp(ixx)).*(ff-fxx(ixx))./(fxx(ixx+1)-fxx(ixx));
df=dfv(ixx)+(dfv(ixx+1)-dfv(ixx)).*(ff-fxx(ixx))./(fxx(ixx+1)-fxx(ixx));
aa=aav(ixx)+(aav(ixx+1)-aav(ixx)).*(ff-fxx(ixx))./(fxx(ixx+1)-fxx(ixx));
%--------------------------------------------
function [c1,c2]=znrmlcf2(f)
n=100;
x=0:1/n:3;
g=zGcBs(x,0);
dg=[diff(g) 0]*n;
dgs=dg/2/pi/f;
xx=2*pi*f*x;
c1=sum((xx.*dgs).^2)/n*2;
c2=sum((xx.^2.*dgs).^2)/n*2;
%--------------------------------------------
function x=cleaninglownoise(x,fs,f0floor);
flm=50;
flp=round(fs*flm/1000);
nn=length(x);
wlp=fir1(flp*2,f0floor/(fs/2));
wlp(flp+1)=wlp(flp+1)-1;
wlp=-wlp;
tx=[x(:)' zeros(1,2*length(wlp))];
ttx=fftfilt(wlp,tx);
x=ttx((1:nn)+flp);
return;
%%%---------
function pm=zmultanalytFineCSPB(x,fs,f0floor,nvc,nvo,mu,mlt);
% Dual waveleta analysis using cardinal spline manipulation
% pm=multanalytFineCSPB(x,fs,f0floor,nvc,nvo,mu,mlt)
% Input parameters
%
% x : input signal (2kHz sampling rate is sufficient.)
% fs : sampling frequency (Hz)
% f0floor : lower bound for pitch search (60Hz suggested)
% nvc : number of total voices for wavelet analysis
% nvo : number of voices in an octave
% mu : temporal stretch factor
% mlt : harmonic ID#
% Outpur parameters
% pm : wavelet transform using iso-metric Gabor function
%
% If you have any questions, mailto:[email protected]
%
% Copyright (c) ATR Human Information Processing Research Labs. 1996
% Invented and coded by Hideki Kawahara
% 30/Oct./1996
% 07/Dec./2002 waitbar was added
t0=1/f0floor;
lmx=round(6*t0*fs*mu);
wl=2^ceil(log(lmx)/log(2));
x=x(:)';
nx=length(x);
tx=[x,zeros(1,wl)];
txx=tx;
gent=((1:wl)-wl/2)/fs;
%nvc=18;
wd=zeros(nvc,wl);
wd2=zeros(nvc,wl);
ym=zeros(nvc,nx);
pm=zeros(nvc,nx);
mpv=1;
%fs
%mu=1.0;
%%%hpg=waitbar(0,['wavelet analysis for initial F0 and P/N estimation with HM#:' num2str(mlt)]); % 07/Dec./2002 by H.K.
for ii=1:nvc
tb=gent*mpv;
t=tb(abs(tb)<3.5*mu*t0);
wbias=round((length(t)-1)/2);
wd1=exp(-pi*(t/t0/mu).^2);%.*exp(i*2*pi*t/t0);
wd2=max(0,1-abs(t/t0/mu));
wd2=wd2(wd2>0);
wwd=conv(wd2,wd1);
wwd=wwd(abs(wwd)>0.00001);
wbias=round((length(wwd)-1)/2);
wwd=wwd.*exp(i*2*pi*mlt*t(round((1:length(wwd))-wbias+length(t)/2))/t0);
pmtmp1=fftfilt(wwd,tx);
% ampp=abs(pmtmp1(wbias+1:wbias+nx));
% txx=[x./ampp,zeros(1,wl)];
% txx=tx;
% pmtmp1=fftfilt(wwd,txx);
% disp(['ii= ' num2str(ii) ' sum=' num2str(sum(abs(wwd)),6)]);
pm(ii,:)=pmtmp1(wbias+1:wbias+nx)*sqrt(mpv);
mpv=mpv*(2.0^(1/nvo));
%%%waitbar(ii/nvc);%,hpg); % 07/Dec./2002 by H.K.
% keyboard;
end;
%%%close(hpg); % 07/Dec./2002 by H.K.
%[nn,mm]=size(pm);
%pm=pm(:,1:mlt:mm);
%%%----
function x=zdB(y)
x=20*log10(y);
%%%-----
function [val,pos]=zmultiCandIF(f0v,vrv)
% [val,pos]=multiCandIF(f0v,vrv)
% F0 candidates based on instantaneous frequency
% fixed points
% f0v : fixed point frequencies (Hz)
% vrv : fixed point N/C (ratio)
% by Hideki Kawahara
% 23/June/2004
[nr,nc]=size(f0v);
[nr2,nc2]=size(vrv);
if (nr~=nr2) | (nc~=nc2);val=[];pos=[];return;end;
vrvdb=-zdBpower(vrv);