本代码提供给定信号x[n]的短时傅立叶变换(STFT)的Matlab函数。
The present code is a Matlab function that provides a Short-Time Fourier Transform (STFT) of a given signal x[n].
该函数是Matlab命令“spectrogram”的替代方案。
The function is an alternative of the Matlab command “spectrogram”.
该函数输出的变量为:
1)具有列时间和行频率的复STFT系数矩阵;
2)频率矢量;
3)时间矢量。
-
a matrix with the complex STFT coefficients with time across the columns and frequency across the rows;
-
a frequency vector;
-
a time vector.
参考文献:
[1] J. Benesty, M. Sondhi, Y. Huang. Springer Handbook of Speech Processing. Berlin, Springer, 2008.
[2] J. Smith. Spectral Audio Signal Processing. W3K Publishing, 2011.
[3] T. Dutoit, F. Marquґes. Applied Signal Processing: A MATLAB-Based Proof of Concept. New York, Springer, 2009.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Short-Time Fourier Transform %
% with MATLAB Implementation %
% %
% Author: Ph.D. Eng. Hristo Zhivomirov 12/21/13 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [STFT, f, t] = stft(x, win, hop, nfft, fs)
% function: [STFT, f, t] = stft(x, win, hop, nfft, fs)
%
% Input:
% x - signal in the time domain
% win - analysis window function
% hop - hop size
% nfft - number of FFT points
% fs - sampling frequency, Hz
%
% Output:
% STFT - STFT-matrix (only unique points, time
% across columns, frequency across rows)
% f - frequency vector, Hz
% t - time vector, s
% representation of the signal as column-vector
x = x(????;
% determination of the signal length
xlen = length(x);
% determination of the window length
wlen = length(win);
% stft matrix size estimation and preallocation
NUP = ceil((1+nfft)/2); % calculate the number of unique fft points
L = 1+fix((xlen-wlen)/hop); % calculate the number of signal frames
STFT = zeros(NUP, L); % preallocate the stft matrix
% STFT (via time-localized FFT)
for l = 0:L-1
% windowing
xw = x(1+l*hop : wlen+l*hop).*win;
% FFT
X = fft(xw, nfft);
% update of the stft matrix
STFT(:, 1+l) = X(1:NUP);
end
% calculation of the time and frequency vectors
t = (wlen/2:hop:wlen/2+(L-1)*hop)/fs;
f = (0:NUP-1)*fs/nfft;
end
完整源码及示例下载地址:
http://page5.dfpan.com/fs/4lcj22215291d67ef85/
更多精彩文章请关注微信号: