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