信号处理——Hilbert变换及谱分析

前言

Hilbert通常用来得到解析信号,基于此原理,Hilbert可以用来对窄带信号进行解包络,并求解信号的瞬时频率,但求解包括的时候会出现端点效应,本文对于这几点分别做了简单的理论探讨。

本文内容多有借鉴他人,最后一并附上链接。

一、基本理论

  A-Hilbert变换定义

对于一个实信号x(t)

,其希尔伯特变换为:

x~(t)=x(t)∗1πt

 

式中*表示卷积运算。

Hilbert本质上也是转向器,对应频域变换为:

1πt⇔j⋅sign(ω)

 

即余弦信号的Hilbert变换时正弦信号,又有:

1πt∗1πt⇔j⋅sign(ω)⋅j⋅sign(ω)=−1

 

即信号两次Hilbert变换后是其自身相反数,因此正弦信号的Hilbert是负的余弦。

对应解析信号为:

z(t)=x(t)+jx~(t)

 

此操作实现了信号由双边谱到单边谱的转化。

  B-Hilbert解调原理

设有窄带信号:

x(t)=a(t)cos[2πfst+φ(t)]

 

其中fs

是载波频率,a(t)是x(t)的包络,φ(t)是x(t)的相位调制信号。由于x(t)是窄带信号,因此a(t)

也是窄带信号,可设为:

a(t)=[1+∑m=1MXmcos(2πfmt+γm)]

 

式中,fm

为调幅信号a(t)的频率分量,γm为fm

的各初相角。

对x(t)

进行Hilbert变换,并求解解析信号,得到:

z(t)=ej[2πfs+φ(t)][1+∑m=1MXmcos(2πfmt+γm)]

 

A(t)=[1+∑m=1MXmcos(2πfmt+γm)]

 

Φ(t)=2πfst+φ(t)

 

则解析信号可以重新表达为:

z(t)=A(t)ejΦ(t)

 

对比x(t)

表达式,容易发现

a(t)=A(t)=x2(t)+x~2(t)−−−−−−−−−−√

 

φ(t)=Φ(t)−2πfst=arctanx(t)x~(t)−2πfst

 

由此可以得出:对于窄带信号x(t)

,利用Hilbert可以求解解析信号,从而得到信号的幅值解调a(t)和相位解调φ(t),并可以利用相位解调求解频率解调f(t)

因为:

f(t)=12πdφ(t)dt=12πdΦ(t)dt−fs

 

  C-相关MATLAB指令

  • hilbert

功能:将实数信号x(n)进行Hilbert变换,并得到解析信号z(n).

调用格式:z = hilbert(x)

  • instfreq

功能:计算复信号的瞬时频率。

调用格式:[f, t] = insfreq(x,t)

示例

1

2

z = hilbert(x);

f = instfreq(z);

 

二、应用实例

 例1:给定一正弦信号,画出其Hilbert信号,直接给代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

clc

clear all

close all

ts = 0.001;

fs = 1/ts;

N = 200;

f = 50;

k = 0:N-1;

t = k*ts;

% 信号变换

% 结论:sin信号Hilbert变换后为cos信号

y = sin(2*pi*f*t);

yh = hilbert(y);    % matlab函数得到信号是合成的复信号

yi = imag(yh);      % 虚部为书上定义的Hilbert变换

figure

subplot(211)

plot(t, y)

title('原始sin信号')

subplot(212)

plot(t, yi)

title('Hilbert变换信号')

ylim([-1,1])

  对应效果图:

例2:已知信号x(t)=(1+0.5cos(2π5t))cos(2π50t+0.5sin(2π10t))

,求解该信号的包络和瞬时频率。

分析:根据解包络原理知:

信号包络:(1+0.5cos(2π5t))

 

瞬时频率:2π50t+0.5sin(2π10t)2π

 

那么问题来了,实际情况是:我们只知道x(t)

的结果,而不知道其具体表达形式,这个时候,上文的推导就起了作用:可以借助信号的Hilbert变换,从而求解信号的包络和瞬时频率。

对应代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

clear all; clc; close all;

 

fs=400;                                 % 采样频率

N=400;                                  % 数据长度

n=0:1:N-1;

dt=1/fs;

t=n*dt;                                 % 时间序列

A=0.5;                                  % 相位调制幅值

x=(1+0.5*cos(2*pi*5*t)).*cos(2*pi*50*t+A*sin(2*pi*10*t));  % 信号序列

z=hilbert(x');                          % 希尔伯特变换

a=abs(z);                               % 包络线

fnor=instfreq(z);                       % 瞬时频率

fnor=[fnor(1); fnor; fnor(end)];        % 瞬时频率补齐

% 作图

pos = get(gcf,'Position');

set(gcf,'Position',[pos(1), pos(2)-100,pos(3),pos(4)]);

subplot 211; plot(t,x,'k'); hold on;

plot(t,a,'r--','linewidth',2);

title('包络线'); ylabel('幅值'); xlabel(['时间/s' 10 '(a)']);

ylim([-2,2]);

subplot 212; plot(t,fnor*fs,'k'); ylim([43 57]);

title('瞬时频率'); ylabel('频率/Hz');  xlabel(['时间/s' 10 '(b)']);

  其中instfreq为时频工具包的代码,可能有的朋友没有该代码,这里给出其程序:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

function [fnormhat,t]=instfreq(x,t,L,trace);

%INSTFREQ Instantaneous frequency estimation.

%   [FNORMHAT,T]=INSTFREQ(X,T,L,TRACE) computes the instantaneous

%   frequency of the analytic signal X at time instant(s) T, using the

%   trapezoidal integration rule.

%   The result FNORMHAT lies between 0.0 and 0.5.

%

%   X : Analytic signal to be analyzed.

%   T : Time instants           (default : 2:length(X)-1).

%   L : If L=1, computes the (normalized) instantaneous frequency

%       of the signal X defined as angle(X(T+1)*conj(X(T-1)) ;

%       if L>1, computes a Maximum Likelihood estimation of the

%       instantaneous frequency of the deterministic part of the signal

%       blurried in a white gaussian noise.

%       L must be an integer        (default : 1).

%   TRACE : if nonzero, the progression of the algorithm is shown

%                                   (default : 0).

%   FNORMHAT : Output (normalized) instantaneous frequency.

%   T : Time instants.

%

%   Examples :

%    x=fmsin(70,0.05,0.35,25); [instf,t]=instfreq(x); plot(t,instf)

%    N=64; SNR=10.0; L=4; t=L+1:N-L; x=fmsin(N,0.05,0.35,40);

%    sig=sigmerge(x,hilbert(randn(N,1)),SNR);

%    plotifl(t,[instfreq(sig,t,L),instfreq(x,t)]); grid;

%    title ('theoretical and estimated instantaneous frequencies');

%

%   See also  KAYTTH, SGRPDLAY.

 

%   F. Auger, March 1994, July 1995.

%   Copyright (c) 1996 by CNRS (France).

%

%   ------------------- CONFIDENTIAL PROGRAM --------------------

%   This program can not be used without the authorization of its

%   author(s). For any comment or bug report, please send e-mail to

%   f.auger@ieee.org

 

if (nargin == 0),

 error('At least one parameter required');

end;

[xrow,xcol] = size(x);

if (xcol~=1),

 error('X must have only one column');

end

 

if (nargin == 1),

 t=2:xrow-1; L=1; trace=0.0;

elseif (nargin == 2),

 L = 1; trace=0.0;

elseif (nargin == 3),

 trace=0.0;

end;

 

if L<1,

 error('L must be >=1');

end

[trow,tcol] = size(t);

if (trow~=1),

 error('T must have only one row');

end;

 

if (L==1),

 if any(t==1)|any(t==xrow),

  error('T can not be equal to 1 neither to the last element of X');

 else

  fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi);

 end;

else

 H=kaytth(L);

 if any(t<=L)|any(t+L>xrow),

  error('The relation L<T<=length(X)-L must be satisfied');

 else

  for icol=1:tcol,

   if trace, disprog(icol,tcol,10); end;

   ti = t(icol); tau = 0:L;

   R = x(ti+tau).*conj(x(ti-tau));

   M4 = R(2:L+1).*conj(R(1:L));

    

   diff=2e-6;

   tetapred = H * (unwrap(angle(-M4))+pi);

   while tetapred<0.0 , tetapred=tetapred+(2*pi); end;

   while tetapred>2*pi, tetapred=tetapred-(2*pi); end;

   iter = 1;

   while (diff > 1e-6)&(iter<50),

    M4bis=M4 .* exp(-j*2.0*tetapred);

    teta = H * (unwrap(angle(M4bis))+2.0*tetapred);

    while teta<0.0 , teta=(2*pi)+teta; end;

    while teta>2*pi, teta=teta-(2*pi); end;

    diff=abs(teta-tetapred);

    tetapred=teta; iter=iter+1;

   end;

   fnormhat(icol,1)=teta/(2*pi);

  end;

 end;

end;

  对应的结果图为:

可以看到信号的包络、瞬时频率,均已完成求解。

 例3:例2中信号包络为规则的正弦函数,此处给定任意形式的包络(以指数形式为例),并利用Hilbert求解包络以及瞬时频率,并给出对应的Hilbert谱。

程序:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

clc

clear all

close all

ts = 0.001;

fs = 1/ts;

N = 200;

k = 0:N-1;

t = k*ts;

% 原始信号

f1 = 10;

f2 = 70;

% a = cos(2*pi*f1*t);       % 包络1

a = 2 + exp(0.2*f1*t);     % 包络2

% a = 1./(1+t.^2*50);       % 包络3

m = sin(2*pi*f2*t);         % 调制信号

y = a.*m;  % 信号调制

figure

subplot(241)

plot(t, a)

title('包络')

subplot(242)

plot(t, m)

title('调制信号')

subplot(243)

plot(t, y)

title('调制结果')

% 包络分析

% 结论:Hilbert变换可以有效提取包络、高频调制信号的频率等

yh = hilbert(y);

aabs = abs(yh);                 % 包络的绝对值

aangle = unwrap(angle(yh));     % 包络的相位

af = diff(aangle)/2/pi;         % 包络的瞬时频率,差分代替微分计算

% NFFT = 2^nextpow2(N);

NFFT = 2^nextpow2(1024*4);      % 改善栅栏效应

f = fs*linspace(0,1,NFFT);

YH = fft(yh, NFFT)/N;           % Hilbert变换复信号的频谱

A = fft(aabs, NFFT)/N;          % 包络的频谱

subplot(245)

plot(t, aabs,'r', t, a)

title('包络的绝对值')

legend('包络分析结果', '真实包络')

subplot(246)

plot(t, aangle)

title('调制信号的相位')

subplot(247)

plot(t(1:end-1), af*fs)

title('调制信号的瞬时频率')

subplot(244)

plot(f,abs(YH))

title('原始信号的Hilbert谱')

xlabel('频率f (Hz)')

ylabel('|YH(f)|')

subplot(248)

plot(f,abs(A))

title('包络的频谱')

xlabel('频率f (Hz)')

ylabel('|A(f)|')

  对应结果图:

从结果可以观察,出了边界误差较大,结果值符合预期。对于边界效应的分析,见扩展阅读部分。注意:此处瞬时频率求解,没有用instfreq函数,扩展阅读部分对该函数作进一步讨论

 

三、扩展阅读

  A-瞬时频率求解方法对比

对于离散数据,通常都是用差分代替微分,因此瞬时频率也可根据概念直接求解。此处对比分析两种求解瞬时频率的方法,给出代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

clc

clear all

close all

ts = 0.001;

fs = 1/ts;

N = 200;

k = 0:N-1;

t = k*ts;

% 原始信号

f1 = 10;

f2 = 70;

% a = cos(2*pi*f1*t);       % 包络1

a = 2 + exp(0.2*f1*t);     % 包络2

% a = 1./(1+t.^2*50);       % 包络3

m = sin(2*pi*f2*t);         % 调制信号

y = a.*m;  % 信号调制

figure

yh = hilbert(y);

aangle = unwrap(angle(yh));     % 包络的相位

af1 = diff(aangle)/2/pi;         % 包络的瞬时频率,差分代替微分计算

af1 = [af1(1),af1];

subplot 211

plot(t, af1*fs);hold on;

plot(t,70*ones(1,length(t)),'r--','linewidth',2);

title('直接求解调制信号的瞬时频率');

legend('频率估值','真实值','location','best');

subplot 212

af2 = instfreq(yh.').';

af2 = [af2(1),af2,af2(end)];

plot(t, af2*fs);hold on;

plot(t,70*ones(1,length(t)),'r--','linewidth',2);

title('instfreq求解调制信号的瞬时频率');

legend('频率估值','真实值','location','best');

  结果图:

可以看出,两种方式结果近似,但instfreq的结果更为平滑一些。

  B-端点效应分析

对于任意包络,求解信号的包络以及瞬时频率,容易出现端点误差较大的情况,该现象主要基于信号中的Gibbs现象,限于篇幅,拟为此单独写一篇文章,具体请参考:Hilbert端点效应分析

  C-VMD、EMD

 Hilbert经典应用总绕不开HHT(Hilbert Huang),HHT基于EMD,近年来又出现了VMD分解,拟为此同样写一篇文章,略说一二心得,具体参考:EMD、VMD的一点小思考

   D-解包络方法

需要认识到,Hilbert不是解包络的唯一途径,低通滤波(LPF)等方式一样可以达到该效果,只不过截止频率需要调参。

给出一个Hilbert、低通滤波解包络的代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

function y=envelope(signal,Fs)

 

%Example:

%   load('s4.mat');

%   signal=s4;

%   Fs=12000;

%   envelope(signal,Fs);

clc;

close all;

 

%Normal FFT

y=signal;

figure();

N=2*2048;T=N/Fs;

sig_f=abs(fft(y(1:N)',N));

sig_n=sig_f/(norm(sig_f));

freq_s=(0:N-1)/T;

subplot 311

plot(freq_s(2:250),sig_n(2:250));title('FFT of Original Signal');

 

 

%Envelope Detection based on Low pass filter and then FFT

[a,b]=butter(2,0.1);%butterworth Filter of 2 poles and Wn=0.1

%sig_abs=abs(signal); % Can be used instead of squaring, then filtering and

%then taking square root

sig_sq=2*signal.*signal;% squaring for rectifing

%gain of 2 for maintianing the same energy in the output

y_sq = filter(a,b,sig_sq); %applying LPF

y=sqrt(y_sq);%taking Square root

%advantages of taking square and then Square root rather than abs, brings

%out some hidden information more efficiently

N=2*2048;T=N/Fs;

sig_f=abs(fft(y(1:N)',N));

sig_n=sig_f/(norm(sig_f));

freq_s=(0:N-1)/T;

subplot 312

plot(freq_s(2:250),sig_n(2:250));title('Envelope Detection: LPF Method');

 

 

 

%Envelope Detection based on Hilbert Transform and then FFT

analy=hilbert(signal);

y=abs(analy);

N=2*2048;T=N/Fs;

sig_f=abs(fft(y(1:N)',N));

sig_n=sig_f/(norm(sig_f));

freq_s=(0:N-1)/T;

subplot 313

plot(freq_s(2:250),sig_n(2:250));title('Envelope Detection : Hilbert Transform')

  结果图:

效果是不是也不错?

Hilbert硬件实现思路

思路1(时域处理):借助MATLAB fdatool实现,Hilbert transform,导出滤波器系数

思路2(频域处理)

参考:

了凡春秋:http://blog.sina.com.cn/s/blog_6163bdeb0102e1wv.html#cmt_3294265

宋知用:《MATLAB在语音信号分析和合成中的应用》

分类: 01-MATLAB, 21-信号处理

标签: Hilbert, 希尔伯特, MATLAB, 端点效应, VMD, EMD

  • 6
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值