forked from shuaijiang/STRAIGHT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerchk.m
More file actions
28 lines (23 loc) · 677 Bytes
/
powerchk.m
File metadata and controls
28 lines (23 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function pow=powerchk(x,fs,segms);
% Calculate average power of voiced portion
% pow=powerchk(x,fs,segms)
% x : signal
% fs : sampling frequency (Hz)
% segms : segment length (ms)
% 23/Sept./1999 updated
% 30/April/2005 modification for Matlab v7.0 compatibility
x1=x(:);
iv=(1:length(x1))';
x1(isnan(x1))=iv(isnan(x1))*0+0.0000000001;
x2=x1.*x1;
%n=100; % 23/Sept./1999
n=round(segms/1000*fs); % 23/Sept./1999
nw=ceil(length(x)/n);
if rem(length(x),n)>0
% x2=[x2;zeros(n*nw-length(x),1)];
x2=[x2;0.000001*randn(n*nw-length(x),1).^2]; % 23/Sept./1999
end;
x2(x2==0)=x2(x2==0)+0.000001;
pw=sum(reshape(x2,n,nw))/n;
pow=10*log10(mean(pw(pw>(mean(pw)/30))));
%keyboard