comparison Problems/private/remove_dc.m @ 61:42fcbcfca132

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