function f=enframe(x,win,inc) nx=length(x); nwin=length(win); if (nwin == 1) len = win; else len = nwin; end if (nargin < 3) inc = len; end nf = fix((nx-len+inc)/inc); f=zeros(nf,len); indf= inc*(0:(nf-1)).'; inds = (1:len); f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:)); if (nwin > 1) w = win(:)'; f = f .* w(ones(nf,1),:); end
时间: 2024-04-23 19:26:38 浏览: 174
这段代码实现了将语音信号分帧的功能。
输入参数包括语音信号x,帧长度win和帧移inc。代码首先计算出语音信号x可以被分成多少帧,即nf。然后,定义一个大小为nf*len的矩阵f,其中len表示每一帧的长度,可以是win或者win的长度。接下来,使用indf和inds计算矩阵f中每一帧的起始位置,其中indf是一个列向量,表示每一帧的起始位置,inds是一个行向量,表示每一帧中包含的样本点。最后,将每一帧信号保存到矩阵f中。
如果输入参数中的win是一个向量,则表示需要将每一帧信号乘以窗函数,以减小帧边缘的影响。因此,代码中将窗函数w转换为行向量,并使用矩阵乘法将窗函数应用到每一帧信号上,最终返回处理后的帧矩阵f。
相关问题
matlab中enframe函数源代码
enframe函数的源代码如下:
```matlab
function y = enframe(x, win, inc)
%ENFRAME split signal up into (overlapping) frames
% Y = ENFRAME(X,WIN,INC) splits the input signal X into overlapping frames
% with window WIN and frame increment INC (in samples). Each column of the
% output matrix Y is a frame of data. The last few frames of X will be
% ignored if they do not fit evenly into an even number of frames. If X is a
% matrix, each *column* is treated as a separate signal.
%
% If WIN is a scalar, a hamming window of length WIN will be used.
%
% If INC is not given, it defaults to WIN/2. For example, if you specify a
% 30 ms window and a 10 ms increment, successive frames will overlap by
% 20 ms. But if you omit the increment, ENFRAME uses a default increment
% of 15 ms.
%
% If X is complex, both the real and imaginary parts are treated as separate
% signals.
%
% Example: apply a 25ms, 10ms increment hamming window to a speech signal
% sampled at 8kHz:
%
% [x,fs] = audioread('count.wav');
% frames = enframe(x,hamming(round(fs*0.025)),round(fs*0.01));
%
% See also AUDIOGRAM, AUDIOWRITE, AUDIOREAD.
%
% Author(s): L. Shure, 5-8-87
% L. Shure, 1-13-88, revised
% J. Smith, 8-20-93, revised to allow matrix data
% P. Kabal, 10-12-97, revised for Octave
% P. Kabal, 10-12-97, revised for Matlab
% T. Krauss, 11-20-00, revised to use faster buffer allocation
% N. Shabtai, 2016-05-05, fixed bug where the last frame is ignored.
% get the window length
if length(win)==1
nwin = win; % use a Hamming window of specified length
win = hamming(nwin);
else
nwin = length(win);
end
% set the default increment
if nargin<3
inc = floor(nwin/2);
end
% make sure x is a column vector
[nr,nc] = size(x);
if (nr == 1) && (nc > 1)
x = x(:);
nr = nc;
nc = 1;
end
% add zeros at end to make sure we have an even number of windows
x(end+1:end+nwin-mod(nr-nwin,inc)-nr) = 0;
% allocate memory
nframes = 1+floor((nr-nwin)/inc);
y = zeros(nwin,nframes*nc);
% create the column pointers into x
% (this saves copying x into a bunch of columns)
colindex = repmat(1:nwin, nframes, 1) + ...
repmat((0:(nframes-1))'*inc, 1, nwin);
% copy x into y using the column pointers
y(:) = x(colindex);
y = y.'; % transpose to get one frame per row
```
该函数将输入信号 x 分成重叠的帧,每一帧的长度为 win,帧之间的重叠长度为 inc。输出矩阵 Y 的每一列都是一帧数据。如果最后一帧不足以填满一帧,将会被忽略。如果输入信号 x 是一个矩阵,那么每一列都会被视为一个独立的信号。
如果 win 是标量,则使用长度为 win 的汉明窗口。
如果未指定 inc,则默认为 win/2。例如,如果您指定了一个 30 毫秒的窗口和 10 毫秒的帧增量,则连续的帧将重叠 20 毫秒。但是,如果省略了增量,则 ENFRAME 使用默认增量 15 毫秒。
如果 x 是复数,则实部和虚部都被视为独立的信号。
阅读全文