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