simulation函数matlab包,matlab第三方函数包怎么调用???

本帖最后由 初学者丶宅 于 2016-4-2 17:25 编辑

function Y=stft(x,nfft,dM,dN,wintype)

% stft : Short Time Fourier Transform

% ***************************************************************@

% Inputs:

%    x,             signal;

%    nfft,          window length;

%    dM,                        sampling step in Time;

%    dN,                        sampling step in Frequency;

%    wintype,        window type;

% Usage:

%    Y=stft(x,nfft,dM,dN,wintype);

% Defaults:

%    wintype='Hanning';

%    dN = 1;

%    dM = 0.5*nfft;

%    nfft = minimum of 256 and the length of the signal;

% Notes:

%    B = STFT(A,NFFT,dM,dN,WINTYPE) calculates the STFT

%    for the signal in vector A.  The signal is split into

%    overlapping segments, each of which are windowed and then

%    Fourier transformed to produce an estimate of the

%    short-term frequency content of the signal.

% Copyright (c) 2000. Dr Israel Cohen.

% All rights reserved. Created  17/12/00.

% ***************************************************************@

x = x(:); % make a column vector for ease later

nx = length(x);

if nargin == 1

nfft = min(nx,256);

end

if nargin < 3

dM = 0.5*nfft;

dN = 1;

end

if nargin < 5

wintype = 'Hanning';

end

if exist(wintype)

wins=eval([lower(wintype),sprintf('(%g)',nfft)]);

else

error(['Undefined window type: ',wintype])

end

% find analysis window for the above synthesis window

win=biorwin(wins,dM,dN);

% figure out number of columns for offsetting the signal

% this may truncate the last portion of the signal since we'd

% rather not append zeros unnecessarily - also makes the fancy

% indexing that follows more difficult.

ncol = fix((nx-nfft)/dM+1);

y = zeros(nfft,ncol);

% now stuff x into columns of y with the proper offset

% should be able to do this with fancy indexing!

colindex = 1 + (0:(ncol-1))*dM;

rowindex = (1:nfft)';

y(:) = x(rowindex(:,ones(1,ncol))+colindex(ones(nfft,1),:)-1);

% Apply the window to the array of offset signal segments.

y(:) = win(:,ones(1,ncol)).*y;

% now fft y which does the columns

N = nfft/dN;

for k=1:dN-1

y(1:N,:) = y(1:N,:) + y((1:N)+k*N,:);

end

y = y(1:N,:);

y = fft(y);

if ~any(any(imag(x)))

y = y(1:N/2+1,:);

end

% take abs, and use image to display results

if nargout == 0

imagesc(abs(y));axis xy

else

Y = y;

end

出现的错误:

function Y=stft(x,nfft,dM,dN,wintype)

|

Error: Function definitions are not permitted in this context.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值