-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathistft.m
59 lines (53 loc) · 1.29 KB
/
istft.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
function x=istft(Y,nfft,dM,dN,wintype)
% istft : Inverse Short Time Fourier Transform
% ***************************************************************@
% Inputs:
% Y, stft of x;
% nfft, window length;
% dM, sampling step in Time;
% dN, sampling step in Frequency;
% wintype, window type;
% Inputs:
% x, signal;
% Usage:
% x=istft(Y,nfft,dM,dN,wintype);
% Defaults:
% wintype='Hanning';
% dN = 1;
% dM = 0.5*nfft;
% nfft=2*(size(Y,1)-1);
% Copyright (c) 2000. Dr Israel Cohen.
% All rights reserved. Created 17/12/00.
% ***************************************************************@
if nargin == 1
nfft = 2*(size(Y,1)-1);
end
if nargin < 3
dM = 0.5*nfft;
dN = 1;
end
if nargin < 5
wintype = 'Hanning';
end
if exist(wintype)
win=eval([lower(wintype),sprintf('(%g)',nfft)]);
else
error(['Undefined window type: ',wintype])
end
%extend the anti-symmetric range of the spectum
N=nfft/dN;
N2=N/2;
Y(N2+2:N,:)=conj(Y(N2:-1:2,:));
Y=real(ifft(Y));
Y=Y((1:N)'*ones(1,dN),:);
% Apply the synthesis window
ncol=size(Y,2);
Y = win(:,ones(1,ncol)).*Y;
% Overlapp & add
x=zeros((ncol-1)*dM+nfft,1);
idx=(1:nfft)';
start=0;
for l=1:ncol
x(start+idx)=x(start+idx)+Y(:,l);
start=start+dM;
end