-
Notifications
You must be signed in to change notification settings - Fork 29
/
exSinStraightSynthBU.m
62 lines (51 loc) · 1.48 KB
/
exSinStraightSynthBU.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
function sy = exSinStraightSynth(f0raw,fs,n3sgram,shiftm)
gdm=gdmap(n3sgram,fs);
[amx,fmx,gmx]= sinucompgd(f0raw,fs,n3sgram,gdm,shiftm);
amx(isnan(amx))=0;
sy=sum(amx'.*cos(cumsum(2*pi*fmx/fs))');
function [amx,fmx,gmx]= sinucompgd(f0raw,fs,n3sgram,gdm,shiftm)
% [amx,fmx]=sinucomp(f0raw,fs,n3sgram,shiftm)
% program to generate matrix for sinusoidal synthesis
%
% Designed and Coded by Hideki Kawahara
% 07/Sept./2003
t=0:1/fs:(length(f0raw)-1)/1000/shiftm;
f0i=interp1((0:length(f0raw)-1)/1000/shiftm,f0raw,t)';
f0l=min(f0raw(f0raw>0));
ng=n3sgram';
ng(:,1) = ng(:,1)*0;
gd=gdm';
[nn,mm]=size(ng);
% ---- instantaneous frequency matrix ---
nh=ceil(fs/2/f0l);
nt=length(f0i);
fmx=zeros(nt,nh);
tmx=fmx;
for ii=1:nh
fmx(:,ii)=ii*f0i;
tmx(:,ii)=t';
end;
% ---- instantaneous amplitude matrix ---
amx=zeros(nt,nh);
[ff,tt]=meshgrid((0:(mm-1))*fs/((mm-1)*2),(0:(length(f0raw)-1))/1000/shiftm);
%keyboard;
amx=interp2(ff,tt,ng,fmx,tmx);
gmx=interp2(ff,tt,gd,fmx,tmx);
function gdm=gdmap(n3sgram,fs)
% gdm=gdmap(n3sgram,fs)
% function to calculate group delay map from
% smoothed time frequency representation
% Designed and coded by Hideki Kawahara
% 7/Sept./2003
[nn,mm]=size(n3sgram);
fftl=(nn-1)*2;
rbb2=fftl/2:-1:2;
gdm=zeros(nn,mm);
for ii=1:mm
ff=[n3sgram(:,ii);n3sgram(rbb2,ii)];
ccp=real(fft(log(ff)));
ccp2=[ccp(1);2*ccp(2:fftl/2);0*ccp(fftl/2+1:fftl)];
ffx=(-ifft(ccp2));
gdt=-diff(imag(ffx)/(2*pi*fs/fftl));
gdm(:,ii)=[gdt(1);gdt(1:fftl/2)];
end;