声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1002|回复: 1

[混合编程] 请大家帮忙翻译一段matlab程序

[复制链接]
发表于 2007-8-10 10:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我想把这段程序换成C语言,但由于没学过matlab,所有有些地方搞不明白,希望matlab高手帮忙说明和注释一下,万分感谢,在线等待!

function S=fft_accumulation_method(x,y,N,a,g,L)
%
% FFT_ACCUMULATION_METHOD
%              estimate the spectral correlation density using the FFT
%              accumulation method
%              Reference:
%              Roberts R. S., Brown, W. A. and Loomis, H. H.
%              "Computationally efficient algorithms for cyclic
%              spectral analysis" IEEE Signal Processing Magazine
%              8(2) pp38-49 April 1991
%              
%              Input parameters are:
%              x,y signals
%              N   length of time window used for estimating frequency
%                  segments (should be power of 2)
%              a   window used for smoothing segments
%              g   window for smoothing correlation
%              L   decimation factor
%              
% USAGE        S=fft_accumulation_method(x,y,N,a,g,L)
%
%              e.g s=fft_accumulation_method(s1,s1,64,'hamming','hamming',1)

if ~exist('L')
  L=1;
end

lx=length(x);
if (length(y)~=lx)
  error('Time series x and y must be same length')
end


n=0:floor((lx-N)/L);
ln=length(n);
a=feval(a,N)';
g=feval(g,ln)';
g=g/sum(g);
a=a/sum(a);

X=zeros(N,ln);
Y=zeros(N,ln);

Ts=1/N;

for i=1:ln
  n_r=n(i)*L+(1:N);
  X(:,i)=fftshift(fft(a.*x(n_r)))';
  Y(:,i)=fftshift(conj(fft(a.*y(n_r))))';   
end


lnd2=floor(ln/2);
lnd4=floor(ln/4)+1;
ln3d4=lnd4+lnd2-2;
S=zeros(2*N-1,lnd2*(N+1));

for alpha=-N/2+1:N/2-1
  for f=-N/2:N/2-1
    f1=f+alpha;
    f2=f-alpha;
    if ((abs(f1)<N/2)&(abs(f2)<N/2))
      f1=f1+N/2;
      f2=f2+N/2;
      fsh=fftshift(fft(g.*X(f1,:).*Y(f2,:)));
      S(2*f+N,(alpha+N/2)*lnd2+(1:lnd2-1))=fsh(1,lnd4:ln3d4);
    end
    f1=f+alpha;
    f2=f-alpha+1;
    if ((abs(f1)<N/2)&(abs(f2)<N/2))
      f1=f1+N/2;
      f2=f2+N/2;
      fsh=fftshift(fft(g.*X(f1,:).*Y(f2,:)));
      S(2*f+N+1,(alpha+N/2)*lnd2+(1:lnd2-1)-lnd4+1)=fsh(1,lnd4:ln3d4);
    end
  end  
end
回复
分享到:

使用道具 举报

发表于 2007-8-10 11:41 | 显示全部楼层
for if 等语句用法和C语言差不太多

只是里面的调用函数如“fftshift”,“zeros"等要自己写

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-21 01:20 , Processed in 0.076303 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表