-
Notifications
You must be signed in to change notification settings - Fork 6
/
stft.m
40 lines (33 loc) · 887 Bytes
/
stft.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
function [Y, F] = STFT(X, NFFT, WINDOW, NOVERLAP, Fs);
%
% Short-time Fourier Transform Analysis
%
% [Y, F] = STFT(X, NFFT, WINDOW, NOVERLAP, Fs)
%
% Y : stFT doamin output matrix (NFFT x L)
% F : real frequencies corresponding to each FFT points
% Fs : sampling freguency
% NFFT : # of FFT points
% WINDOW : window function
% NOVERLAP : # of overlaped samples
%
% by Taesu Kim
% 2003. 1. 26.
%
if nargin<5, Fs = 8000; end
WLEN = size(WINDOW, 1);
SHIFT = WLEN - NOVERLAP;
N = size(X, 1);
X = [zeros(WLEN, 1); X; zeros(NFFT, 1)];
%L = fix(N/SHIFT)+fix(WLEN/SHIFT);
L = fix((N+WLEN)/SHIFT) - 1;
Y = zeros(NFFT, L);
Xn = zeros(NFFT, 1);
for i = 1:L,
sp = SHIFT*i + 1;
Xn(1:WLEN) = WINDOW.*X(sp:sp+WLEN-1);
Y(:, i) = fft(Xn);
end
Y = Y(1:fix(NFFT/2)+1,:);
% Y = Y(2:NFFT/2,:);
F = [0:fix(NFFT/2)]'.*Fs/NFFT;