matlab中enframe原函数
时间: 2023-06-12 21:07:58 浏览: 435
在MATLAB中,enframe原函数用于将信号分帧。以下是enframe函数的一个示例实现:
```matlab
function frames = enframe(signal, frameSize, hopSize)
% signal: 输入信号
% frameSize: 每帧的大小
% hopSize: 帧之间的跳跃大小
% 计算帧数
numFrames = floor((length(signal)-frameSize)/hopSize) + 1;
% 初始化帧矩阵
frames = zeros(frameSize, numFrames);
% 分帧
for i = 1:numFrames
% 计算当前帧的起始位置
start = (i-1)*hopSize + 1;
% 将信号复制到当前帧中
frames(:,i) = signal(start:start+frameSize-1);
end
```
该函数接受三个参数:输入信号,每帧的大小和帧之间的跳跃大小。该函数首先计算帧数,然后初始化帧矩阵。接下来,它使用一个循环来分帧,计算每个帧的起始位置,然后将信号复制到当前帧中。函数最终返回一个帧矩阵,其中每一列是一个帧。
相关问题
matlab中enframe函数
matlab中enframe函数是用于将一维信号分割成帧的函数。它的语法如下:
frames = enframe(signal, window, overlap)
其中,signal是要分割的一维信号;window是窗函数,可以是一个向量或一个字符串,表示窗函数的类型;overlap是帧之间的重叠部分,一般是窗长的一半。
enframe函数的输出是一个矩阵,每一行表示一个帧。矩阵的列数等于窗长,行数等于帧数。
例如,如果我们要将一个长度为100的信号分成长度为20的帧,窗函数选择汉宁窗,重叠部分为10个采样点,可以这样调用enframe函数:
signal = randn(1,100);
frames = enframe(signal, hann(20), 10);
其中,randn函数用于生成一个长度为100的随机信号,hann(20)生成一个长度为20的汉宁窗。
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 是复数,则实部和虚部都被视为独立的信号。
相关推荐
![m](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)