forked from speechLabBcCuny/messlJsalt15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stft_multi.m
58 lines (53 loc) · 1.84 KB
/
stft_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
function X=stft_multi(x,wlen)
% STFT_MULTI Multichannel short-time Fourier transform (STFT) using
% half-overlapping sine windows.
%
% X=stft_multi(x)
% X=stft_multi(x,wlen)
%
% Inputs:
% x: nchan x nsampl matrix containing nchan time-domain mixture signals
% with nsampl samples
% wlen: window length (default: 1024 samples or 64ms at 16 kHz, which is
% optimal for speech source separation via binary time-frequency masking)
%
% Output:
% X: nbin x nfram x nchan matrix containing the STFT coefficients with nbin
% frequency bins and nfram time frames
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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<1, error('Not enough input arguments.'); end
if nargin<2, wlen=1024; end
[nchan,nsampl]=size(x);
if nchan>nsampl, error('The signals must be within rows.'); end
if wlen~=4*floor(wlen/4), error('The window length must be a multiple of 4.'); end
%%% Computing STFT coefficients %%%
% Defining sine window
win=sin((.5:wlen-.5)/wlen*pi).';
% Zero-padding
nfram=ceil(nsampl/wlen*2);
x=[x,zeros(nchan,nfram*wlen/2-nsampl)];
% Pre-processing for edges
x=[zeros(nchan,wlen/4),x,zeros(nchan,wlen/4)];
swin=zeros((nfram+1)*wlen/2,1);
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(wlen*swin);
nbin=wlen/2+1;
X=zeros(nbin,nfram,nchan);
for i=1:nchan,
for t=0:nfram-1,
% Framing
frame=x(i,t*wlen/2+1:t*wlen/2+wlen).'.*win./swin(t*wlen/2+1:t*wlen/2+wlen);
% FFT
fframe=fft(frame);
X(:,t+1,i)=fframe(1:nbin);
end
end
return;