大鹏之举 发表于 2009-4-14 09:45

到底哪个instfreq.m函数对呢?

我在网上看到两个求瞬时频率的函数,我都用了一下结果差别很大。到底哪个对呢?我有点迷糊了。
两个的出处分别为:
http://forum.vibunion.com/thread-60117-1-1.html
http://forum.vibunion.com/thread-72651-1-1.html

我自己的问题我自己解决;首先对第一个时频工具箱的instfreq.m进行验证。我的程序如下:
T=10;
N=1024;
fs=102.4
n=0:1:N-1;
dt=T/N;
t=n*dt;
x=sin(2*pi*51*t);
x=hilbert(x');
=instfreq(x);
fnor1=fnor*fs
plot(t,fnor1);
接着我对改进的instfreq.m进行验证。我以instfreq1.m命名,来加以区分。我的程序如下
T=10;
N=1024;
fs=102.4
n=0:1:N-1;
dt=T/N;
t=n*dt;
x=sin(2*pi*8*t);
x=hilbert(x');
=instfreq1(x,fs)
plot(t,fnor);
结果如下面两图所示:

[ 本帖最后由 大鹏之举 于 2009-4-14 21:15 编辑 ]

大鹏之举 发表于 2009-4-14 21:18

回复 楼主 大鹏之举 的帖子

有两个对比可知,原始的是只能得到归一化频率,需要自己转化才可以得到实际频率,而改进后的函数可以直接得到实际频率,和归一化频率。后者比较直接方便。
我还有一点不明白的是后者得到的图稍微带有点波动,而前者没有波动,就是一条直线。还请高人加以指点。

[ 本帖最后由 大鹏之举 于 2009-4-14 21:21 编辑 ]

Rovis 发表于 2009-4-16 14:58

波动应该是由于相函数不是连续函数引起的,因为相函数是锯齿函数

cboboc 发表于 2010-4-7 09:31

回复 板凳 Rovis 的帖子

楼主可否把instfreq1函数贴上来呢?

vera吧噗 发表于 2012-8-18 11:12

两个程序基本是一样的
重要的改动只是在原始的instfreq.m程序66 行计算完归一化瞬时频率fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi)之后,instfreq1.m又加了一句freq_inst=fnormhat*freq_sampling,freq_inst就是不进行归一化的瞬时频率,freq_sampling是采样频率。
只要知道自己的采样频率,用第一个原始instfreq.m算出归一化瞬时频率后自己也可以还原出真实的瞬时频率。


我想lz原始未经改动的instfreq.m程序如下,改动后的见http://forum.vibunion.com/thread-72651-1-1.html

function =instfreq(x,t,L,trace)
%INSTFREQ Instantaneous frequency estimation.
%      =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); =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,); grid;
%         title ('theoretical and estimated instantaneous frequencies');
%
%      See alsoKAYTTH, 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;
= 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
= 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;

yghit08 发表于 2012-8-18 18:02

我想不管是做归一化的还是直接出原结果的,都只拿一个仿真数据测试一下就知道了(归一化的很容易还原到原频率上,所以归不归一化不是根本问题)。至于显示的锯齿状的问题是你显示的问题。另一个问题就是你画的图的纵坐标怎么都只是一个数???至于你说的差别,根本不是同一信号的比较,何以来差别?两个结果都做的很好。不知道楼主的问题在哪!!!
页: [1]
查看完整版本: 到底哪个instfreq.m函数对呢?