play.m

来自「英文书《Digital Signal Processing with Examp」· M 代码 · 共 25 行

M
25
字号
function play(y,fs,t)
% play(y,fs)
% 
% Same as wavplay except range of y is adjusted to +-1.
%
% y  =sample vector.
% fs =sampling rate (8000,11025,...etc.).
%
% Note: you may add a third argument, t, >0 and <length(y)/fs.
% Play is then terminated at t seconds.
if nargin<2
    error('Not enough arguments.');
elseif nargin>3
    error('Too many argurments.');
elseif max(y)-min(y)<=0
    error('Zero signal vector.');
end
scale=2/(max(y)-min(y));
ys=(y-min(y))*scale-1;
K=length(ys);
if(nargin==3)
    K=min(K,max(1,fix(t*fs)));
end
wavplay(ys(1:K),fs);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?