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