function [Px,t] = sigpower(x,N) % sigpower --> Short-term power computation using a sliding window. % % % [Px,t] = sigpower(x,N) % % % An initial short-term power estimate Px(1) based on the N-sample % vector x(1:N) is updated with the new sample x(N+1) and downdated % with the oldest sample x(1), resulting in Px(2). This update % procedure of the short-term power estimate continues until the % sliding window has reached the end of the signal x. The output % vector t is a time vector corresponding to center points of the % sliding window. % % Peter S.K. Hansen, IMM, Technical University of Denmark % % Last revised: February 22, 2000 %----------------------------------------------------------------------- % Check the required input arguments. if (nargin < 1) error('Not enough input arguments.') elseif (nargin == 1) N = length(x); end if (N > length(x)) error('The window length N can not be longer than the sequence length.') end % Make sure that x is a column vector. x = x(:); % Number of power estimates to make. K = length(x)-N+1; Px = zeros(K,1); % First power estimate. Px(1) = x(1:N)'*x(1:N)/N; % Updating of the power estimate. for (k=2:K) Px(k) = Px(k-1) + (x(k+N-1)^2 - x(k-1)^2)/N; end % Time vector corresponding to center of window. t = fix(N/2)+(1:K)'; %----------------------------------------------------------------------- % End of function sigpower %-----------------------------------------------------------------------