idamnjanovic@60: function [y,dc] = remove_dc(x,columns) idamnjanovic@60: %REMOVE_DC Remove DC channel from signals. idamnjanovic@60: % [Y,DC] = REMOVE_DC(X) removes the DC channel (i.e. the mean) from the idamnjanovic@60: % specified (possibly multi-dimensional) signal X. Y is the DC-free idamnjanovic@60: % signal and is the same size as X. DC is a scalar containing the mean of idamnjanovic@60: % the signal X. idamnjanovic@60: % idamnjanovic@60: % [Y,DC] = REMOVE_DC(X,'columns') where X is a 2D matrix, treats the idamnjanovic@60: % columns of X as a set of 1D signals, removing the DC channel from each idamnjanovic@60: % one individually. Y is the same size as X and contains the DC-free idamnjanovic@60: % signals. DC is a row vector of length size(X,2) containing the means of idamnjanovic@60: % the signals in X. idamnjanovic@60: % idamnjanovic@60: % See also ADD_DC. idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: if (nargin==2 && strcmpi(columns,'columns')), columns = 1; idamnjanovic@60: else columns = 0; idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: if (columns) idamnjanovic@60: dc = mean(x); idamnjanovic@60: y = addtocols(x,-dc); idamnjanovic@60: else idamnjanovic@60: if (ndims(x)==2) % temporary, will remove in future idamnjanovic@60: warning('Treating 2D matrix X as a single signal and not each column individually'); idamnjanovic@60: end idamnjanovic@60: dc = mean(x(:)); idamnjanovic@60: y = x-dc; idamnjanovic@60: end idamnjanovic@60: