annotate Problems/private/remove_dc.m @ 61:42fcbcfca132

(none)
author idamnjanovic
date Tue, 15 Mar 2011 12:21:31 +0000
parents 207a6ae9a76f
children
rev   line source
idamnjanovic@10 1 function [y,dc] = remove_dc(x,columns)
idamnjanovic@10 2 %REMOVE_DC Remove DC channel from signals.
idamnjanovic@10 3 % [Y,DC] = REMOVE_DC(X) removes the DC channel (i.e. the mean) from the
idamnjanovic@10 4 % specified (possibly multi-dimensional) signal X. Y is the DC-free
idamnjanovic@10 5 % signal and is the same size as X. DC is a scalar containing the mean of
idamnjanovic@10 6 % the signal X.
idamnjanovic@10 7 %
idamnjanovic@10 8 % [Y,DC] = REMOVE_DC(X,'columns') where X is a 2D matrix, treats the
idamnjanovic@10 9 % columns of X as a set of 1D signals, removing the DC channel from each
idamnjanovic@10 10 % one individually. Y is the same size as X and contains the DC-free
idamnjanovic@10 11 % signals. DC is a row vector of length size(X,2) containing the means of
idamnjanovic@10 12 % the signals in X.
idamnjanovic@10 13 %
idamnjanovic@10 14 % See also ADD_DC.
idamnjanovic@10 15
idamnjanovic@10 16
idamnjanovic@10 17 if (nargin==2 && strcmpi(columns,'columns')), columns = 1;
idamnjanovic@10 18 else columns = 0;
idamnjanovic@10 19 end
idamnjanovic@10 20
idamnjanovic@10 21 if (columns)
idamnjanovic@10 22 dc = mean(x);
idamnjanovic@10 23 y = addtocols(x,-dc);
idamnjanovic@10 24 else
idamnjanovic@10 25 if (ndims(x)==2) % temporary, will remove in future
idamnjanovic@10 26 warning('Treating 2D matrix X as a single signal and not each column individually');
idamnjanovic@10 27 end
idamnjanovic@10 28 dc = mean(x(:));
idamnjanovic@10 29 y = x-dc;
idamnjanovic@10 30 end
idamnjanovic@10 31