1+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+ % Inverse Short-Time Fourier Transform %
3+ % with MATLAB Implementation %
4+ % %
5+ % Author: M.Sc. Eng. Hristo Zhivomirov 12/26/13 %
6+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7+
8+ function [x , t ] = istft(stft , h , nfft , fs )
9+
10+ % function: [x, t] = istft(stft, h, nfft, fs)
11+ % stft - STFT matrix (only unique points, time across columns, freq across rows)
12+ % h - hop size
13+ % nfft - number of FFT points
14+ % fs - sampling frequency, Hz
15+ % x - signal in the time domain
16+ % t - time vector, s
17+
18+ % estimate the length of the signal
19+ coln = size(stft , 2 );
20+ xlen = nfft + (coln - 1 )*h ;
21+ x = zeros(1 , xlen );
22+
23+ % form a periodic hamming window
24+ win = hamming(nfft , ' periodic' );
25+
26+ % perform IFFT and weighted-OLA
27+ if rem(nfft , 2 ) % odd nfft excludes Nyquist point
28+ for b = 0 : h : (h *(coln - 1 ))
29+ % extract FFT points
30+ X = stft(: , 1 + b / h );
31+ X = [X ; conj(X(end : -1 : 2 ))];
32+
33+ % IFFT
34+ xprim = real(ifft(X ));
35+
36+ % weighted-OLA
37+ x((b + 1 ): (b + nfft )) = x((b + 1 ): (b + nfft )) + (xprim .* win )' ;
38+ end
39+ else % even nfft includes Nyquist point
40+ for b = 0 : h : (h *(coln - 1 ))
41+ % extract FFT points
42+ X = stft(: , 1 + b / h );
43+ X = [X ; conj(X(end - 1 : -1 : 2 ))];
44+
45+ % IFFT
46+ xprim = real(ifft(X ));
47+
48+ % weighted-OLA
49+ x((b + 1 ): (b + nfft )) = x((b + 1 ): (b + nfft )) + (xprim .* win )' ;
50+ end
51+ end
52+
53+ W0 = sum(win .^ 2 ); % find W0
54+ x = x .* h / W0 ; % scale the weighted-OLA
55+
56+ % calculate the time vector
57+ actxlen = length(x ); % find actual length of the signal
58+ t = (0 : actxlen - 1 )/fs ; % generate time vector
59+
60+ end
0 commit comments