-
Notifications
You must be signed in to change notification settings - Fork 4
/
stft.m
26 lines (22 loc) · 809 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
function[stft_single, stft_double] = stft(x,w,overlap)
% Input:
% 1) x - time domain signal to be transformed
% 2) w - window size in samples
% 3) overlap - percentage of window overlap
%
% Output:
% 1) stft_single - single sided short-time spectra
% 2) stft_double - double sided short-time spectra
% (rows - frequency bins, columns - time segments)
N = length(x);
hop = hopSize(w,overlap);
window = hamming(w,'periodic');
stft_double = zeros(w,(N-w)/hop+1); % [spectra,time segments]
count = 1;
for n = 1:hop:N-w+1
segment = x(n:n+w-1); % take segment of length of window_size
segment = (segment.*window)/1.08; % apply window & scale down
stft_double(:,count) = fft(segment);
count = count + 1;
end
stft_single = stft_double(1:w/2+1,:); % +1 to keep window_size/2+1 bin