音频信号分帧

为什么要分帧?

为什么要分帧处理?因为这么做有很多好处啊!比如:

1. 若本来就是数据流,不可能所有数据都拿到,再统一处理吧?

2. 有些文件很大啊,肯定要分段处理啊。

3. 逐点(pointwise)处理看起来虽然时间分辨率高,但计算量大,

而且真的非常缺乏一种连贯性。e.g. 麦克风录音的时候,可能突然有个突发噪声,

导致采样序列中有个别野点。这些野点会对逐点处理造成很大的伤害。

4. ……

综上,分帧处理,is necessary.


什么是分帧?怎么分?

什么是分帧?通俗地理解就是,加窗处理、分段处理。随着窗口的往右(假设向右代表时间向前)推移,对加窗后的信号逐步展开处理。

因此,知道三点就够了。

1. 窗口长度是多少wlen(window length)。For the sake of simplicity,先假定窗口长度一旦确定下来,在这次计算过程中长度就不可变化了。其实按理说是可变长的。

2. 每次窗口往右移动多长,即增量increment,或步长step。也是简单起见,假定步长一旦确定下来,在这次计算过程中长度就不可变化了。

3. 窗口选什么类型。时域上的加窗就是把原始信号x(t)与窗口w(t)相乘,频域就是对应的Fourier Transform相乘(感谢读者帮我指出问题。频域是卷积…)。不同的窗函数有不同的性质。常见的有矩形窗、三角窗、Hanning窗、Hamming窗、Blackman窗、Kaiser窗……


分帧注意事项

A. 帧数Nframe(number of frame)怎么算?不一定能整除嘛。

我的理解,两种做法。

1. 若帧都很短,最后一帧,不够wlen长度的,干脆就不要了。无伤大雅。

2. 完美主义者,就先前面(Nframe-1)帧都是wlen长,最后一帧,不够wlen的,就补零(zero padding)吧。

B. 窗函数有不同的性质,要根据需求,trial and error,反复试验。


Matlab示例代码

Matlab代码大概、好像是这样。

Nframe = floor( (length(x) - wlen) / nstep) + 1;
for k = 1:Nframe
  idx = (1:wlen) + (k-1) * nstep;
  x_frame = x(idx);
end

最后,分帧以后,应该把帧的序号对应上时间嘛。

frame-to-time的函数如下。

function frameTime=frame2time(frameNum,framelen,inc,fs)
% 分帧后计算每帧对应的时间
frameTime=(((1:frameNum)-1)*inc+framelen/2)/fs;

而给定一个时刻,想求得其对应的帧的代码如下。

% fs 采样率
% t0 特定时刻
frame_idx=fix((t0*fs-wlen)/nstep +1);


另外,给一个分帧的函数。

把输入的信号x分帧(可重叠)。分帧以后的信号存放在一个矩阵中。

function [f,t]=enframe(x,win,inc)
%ENFRAME split signal up into (overlapping) frames: one per row. [F,T]=(X,WIN,INC)
%
%	F = ENFRAME(X,LEN) splits the vector X(:) up into
%	frames. Each frame is of length LEN and occupies
%	one row of the output matrix. The last few frames of X
%	will be ignored if its length is not divisible by LEN.
%	It is an error if X is shorter than LEN.
%
%	F = ENFRAME(X,LEN,INC) has frames beginning at increments of INC
%	The centre of frame I is X((I-1)*INC+(LEN+1)/2) for I=1,2,...
%	The number of frames is fix((length(X)-LEN+INC)/INC)
%
%	F = ENFRAME(X,WINDOW) or ENFRAME(X,WINDOW,INC) multiplies
%	each frame by WINDOW(:)
%
%   The second output argument, T, gives the time in samples at the centre
%   of each frame. T=i corresponds to the time of sample X(i). 
%
% Example of frame-based processing:
%          INC=20       													% set frame increment
%          NW=INC*2     													% oversample by a factor of 2 (4 is also often used)
%          S=cos((0:NW*7)*6*pi/NW);								% example input signal
%          W=sqrt(hamming(NW+1)); W(end)=[];      % sqrt hamming window of period NW
%          F=enframe(S,W,INC);               			% split into frames
%          ... process frames ...
%          X=overlapadd(F,W,INC);           			% reconstitute the time waveform (omit "X=" to plot waveform)

%	   Copyright (C) Mike Brookes 1997
%      Version: $Id: enframe.m,v 1.7 2009/11/01 21:08:21 dmb Exp $
%
%   VOICEBOX is a MATLAB toolbox for speech processing.
%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   This program is free software; you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation; either version 2 of the License, or
%   (at your option) any later version.
%
%   This program is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You can obtain a copy of the GNU General Public License from
%   http://www.gnu.org/copyleft/gpl.html or by writing to
%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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
if nargout>1
    t=(1+len)/2+indf;
end

最后,加窗分帧以后,怎么拼起来?以后总结。

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qcyfred

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值