% Function MYPWR: Block computation of power and intensity of non-stationary signal
%
% Usage: [Pframe,tframe]=mypwr(sig,fs,tlen,tstep);
% Input:
% sig - vector with speech signal samples
% fs - sampling frequency
% tlen - length of short-time frame in miliseconds
% tstep - segmetnation step of short-time frame in miliseconds
% Output:
% Pframe - matrix with estimated power-based characteristics for all frames
% Following charactersitics are in particular columns of Pframe
% Column 1 .......... short-time power
% Column 2 .......... short-time intensity
% tframe - vector of begining times of each short-time frame
function [Pframe,tframe]=mypwr(sig,fs,tlen,tstep);
% Computation of number of short-time frame
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sig=sig(:);
slen=length(sig);
wlen=floor(fs*tlen*1e-3) ;
wstep=floor(fs*tstep*1e-3) ;
wnum=floor((slen-wlen)/wstep)+1 ;
% Creation of output vector/matrix with zero values (just one memory allocation)
Pframe=zeros(wnum,2);
tframe=zeros(wnum,1);
% Main cycle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:wnum,
% Setup of indexes for the short-time frame selection
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ii=(i-1)*wstep+1;
jj=(i-1)*wstep+wlen;
tframe(i)=(ii-1)/fs ;
frame=sig(ii:jj);
% Power computation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ps=mean(frame.^2);
Is=mean(abs(frame));
Pframe(i,1)=Ps;
Pframe(i,2)=Is;
end;