|
<P>function x = hilbert(xr,n)<BR>%HILBERT Discrete-time analytic signal via Hilbert transform.<BR>% X = HILBERT(Xr) computes the so-called discrete-time analytic signal<BR>% X = Xr + i*Xi such that Xi is the Hilbert transform of real vector Xr.<BR>% If the input Xr is complex, then only the real part is used: Xr=real(Xr).<BR>% If Xr is a matrix, then HILBERT operates along the columns of Xr.<BR>%<BR>% HILBERT(Xr,N) computes the N-point Hilbert transform. Xr is padded with <BR>% zeros if it has less than N points, and truncated if it has more. <BR>%<BR>% For a discrete-time analytic signal X, the last half of fft(X) is zero, <BR>% and the first (DC) and center (Nyquist) elements of fft(X) are purely real.<BR>%<BR>% Example:<BR>% Xr = [1 2 3 4];<BR>% X = hilbert(Xr)<BR>% produces X=[1+1i 2-1i 3-1i 4+1i] such that Xi=imag(X)=[1 -1 -1 1] is the<BR>% Hilbert transform of Xr, and Xr=real(X)=[1 2 3 4]. Note that the last half<BR>% of fft(X)=[10 -4+4i -2 0] is zero (in this example, the last half is just<BR>% the last element). Also note that the DC and Nyquist elements of fft(X)<BR>% (10 and -2) are purely real.<BR>%<BR>% See also FFT, IFFT.</P>
<P>% Copyright 1988-2002 The MathWorks, Inc.<BR>% $Revision: 1.10 $ $Date: 2002/03/28 17:28:20 $</P>
<P>% References:<BR>% [1] Alan V. Oppenheim and Ronald W. Schafer, Discrete-Time<BR>% Signal Processing, 2nd ed., Prentice-Hall, Upper Saddle River, <BR>% New Jersey, 1998.<BR>%<BR>% [2] S. Lawrence Marple, Jr., Computing the discrete-time analytic <BR>% signal via FFT, IEEE Transactions on Signal Processing, Vol. 47, <BR>% No. 9, September 1999, pp.2600--2603.</P>
<P>if nargin<2, n=[]; end<BR>if ~isreal(xr)<BR> warning('HILBERT ignores imaginary part of input.')<BR> xr = real(xr);<BR>end<BR>% Work along the first nonsingleton dimension<BR>[xr,nshifts] = shiftdim(xr);<BR>if isempty(n)<BR> n = size(xr,1);<BR>end<BR>x = fft(xr,n,1); % n-point FFT over columns.<BR>h = zeros(n,~isempty(x)); % nx1 for nonempty. 0x0 for empty.<BR>if n>0 & 2*fix(n/2)==n<BR> % even and nonempty<BR> h([1 n/2+1]) = 1;<BR> h(2:n/2) = 2;<BR>elseif n>0<BR> % odd and nonempty<BR> h(1) = 1;<BR> h(2:(n+1)/2) = 2;<BR>end<BR>x = ifft(x.*h(:,ones(1,size(x,2))));</P>
<P>% Convert back to the original shape.<BR>x = shiftdim(x,-nshifts);</P> |
|