-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathistft_multi.m
59 lines (54 loc) · 1.95 KB
/
istft_multi.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_multi(X,nsampl)
% ISTFT_MULTI Multichannel inverse short-time Fourier transform (ISTFT)
% using half-overlapping sine windows.
%
% x=istft_multi(X,nsampl)
%
% Inputs:
% X: nbin x nfram x nsrc matrix containing STFT coefficients for nsrc
% sources with nbin frequency bins and nfram time frames or nbin x nfram x
% nsrc x nchan matrix containing the STFT coefficients of nsrc spatial
% source images over nchan channels
% nsampl: number of samples to which the corresponding time-domain signals
% are to be truncated
%
% Output:
% x: nsrc x nsampl matrix or nsrc x nsampl x nchan matrix containing the
% corresponding time-domain signals
% If x is a set of signals of length nsampl and X=stft_multi(x), then
% x=istft_multi(X,nsampl).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2008 Emmanuel Vincent
% This software is distributed under the terms of the GNU Public License
% version 3 (http://www.gnu.org/licenses/gpl.txt)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Errors and warnings %%%
if nargin<2, error('Not enough input arguments.'); end
[nbin,nfram,nsrc,nchan]=size(X);
if nbin==2*floor(nbin/2), error('The number of frequency bins must be odd.'); end
wlen=2*(nbin-1);
%%% Computing inverse STFT signal %%%
% Defining sine window
win=sin((.5:wlen-.5)/wlen*pi);
% Pre-processing for edges
swin=zeros(1,(nfram+1)*wlen/2);
for t=0:nfram-1,
swin(t*wlen/2+1:t*wlen/2+wlen)=swin(t*wlen/2+1:t*wlen/2+wlen)+win.^2;
end
swin=sqrt(swin/wlen);
x=zeros(nsrc,(nfram+1)*wlen/2,nchan);
for i=1:nchan,
for j=1:nsrc,
for t=0:nfram-1,
% IFFT
fframe=[X(:,t+1,j,i);conj(X(wlen/2:-1:2,t+1,j,i))];
frame=real(ifft(fframe));
% Overlap-add
x(j,t*wlen/2+1:t*wlen/2+wlen,i)=x(j,t*wlen/2+1:t*wlen/2+wlen,i)+frame.'.*win./swin(t*wlen/2+1:t*wlen/2+wlen);
end
end
end
% Truncation
x=x(:,wlen/4+1:wlen/4+nsampl,:);
return;