【源码】基于MATLAB的短时傅里叶变换STFT

在这里插入图片描述

本代码提供给定信号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)时间矢量。

  1. a matrix with the complex STFT coefficients with time across the columns and frequency across the rows;

  2. a frequency vector;

  3. 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/

更多精彩文章请关注微信号:在这里插入图片描述

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值