annotate examples/private/remove_dc.m @ 5:f44689e95ea4

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