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