📄 hilbert2.m
字号:
function [y]=hilbert2(x)
% % hilbert2: Calculates the hilbert transform for a very long signal
% %
% % Syntax:
% %
% % [y]=hilbert2(x);
% %
% % Returns the complex hilbert transform of x to the complex variable y.
% % Leading singelton dimensions of x are removed.
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Example='1';
%
% x=randn(2, 100000);
% tic; [y]=hilbert2(x')'; t2=toc;
%
% Example='2';
% tic; [y2]=hilbert(x')'; t3=toc;
%
%
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Program Written by Edward L. Zechmann
% %
% % date 22 April 2008
% %
% % modified 10 September 2008 Added Comments
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Please feel free to modify this code.
% %
% % See Also: hilbert, fft, ifft
% %
% %
if ~isreal(x)
warning('HILBERT ignores imaginary part of input.')
x = real(x);
end
% Work along the first nonsingleton dimension
[x,nshifts] = shiftdim(x);
length_x=size(x, 1);
% maximum number of elements in a bin
bin_size=2^12;
% Maximum size of array before it is necessary to break up the array into
% bins
flag=0;
if length_x > 4*bin_size
flag=1;
end
if flag == 1
if length_x > bin_size
num_bins=ceil(length_x/bin_size);
end
y=zeros(size(x));
for e1=1:num_bins;
if e1 == num_bins
buf=x( (1+(e1-1)*bin_size):end, :);
else
buf=x( (1+(e1-1)*bin_size):(e1*bin_size), :);
end
% Reverse the fist half and second half and append to the
% beginning and end of the array.
%
% This will reduce the extraneous peaks that may be added to
% the signal.
%
n1=length(buf);
n2=floor(n1/2);
buf2=[buf(n2:(-1):1, :)' buf(1:n1, :)' buf(n1:(-1):(n2+1), :)' ]';
buf3 = hilbert(buf2);
if e1 == num_bins
y((1+(e1-1)*bin_size):end, :)=buf3(n2+(1:n1), :);
else
y((1+(e1-1)*bin_size):(e1*bin_size), :)=buf3(n2+(1:n1), :);
end
end
else
[y]=hilbert(x);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -