www.pudn.com > dspproject.rar > segment.m, change:2016-05-15,size:849b


function Seg=segment(signal,W,SP,Window) 
 
% SEGMENT chops a signal to overlapping windowed segments 
% A= SEGMENT(X,W,SP,WIN) returns a matrix which its columns are segmented 
% and windowed frames of the input one dimentional signal, X. W is the 
% number of samples per window, default value W=256. SP is the shift 
% percentage, default value SP=0.4. WIN is the window that is multiplied by 
% each segment and its length should be W. the default window is hamming 
% window. 
% 06-Sep-04 
% Esfandiar Zavarehei 
 
if nargin<3 
    SP=.4; 
end 
if nargin<2 
    W=256; 
end 
if nargin<4 
    Window=hamming(W); 
end 
Window=Window(:); %make it a column vector 
 
L=length(signal); 
SP=fix(W.*SP); 
N=fix((L-W)/SP +1); %number of segments 
 
Index=(repmat(1:W,N,1)+repmat((0:(N-1))'*SP,1,W))'; 
hw=repmat(Window,1,N); 
Seg=signal(Index).*hw;