怎么实现fft用C语言编译,大神们求助

% Noisy Signal
% Use Fourier transforms to find the frequency components of a signal buried
% in noise.
%
% Specify the parameters of a signal with a sampling frequency of 1 kHz and
% a signal duration of 1 second.
% Copyright 2015 The MathWorks, Inc.

Fs = 1000; % Sampling frequency

T = 1/Fs; % Sampling period

L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
%%
% Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz
% sinusoid of amplitude 1.

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
%%
% Corrupt the signal with zero-mean white noise with a variance of 4.

Y = fft(S);

这个是MATLAB2016B中得语句,怎么用C语言编译

3个回答

1.先得到待变换的抽样数据和点数,你这里是两个sin的叠加,按一定频率抽样即可;
2.构建FFT函数,FFT函数的构建可参考http://blog.csdn.net/tf18269639242/article/details/53024276;
3.将数据。

return_failed
return_failed 贴个dsp实现的fft代码:
大约 3 年之前 回复
qq_39507269
qq_39507269 网页打不开
大约 3 年之前 回复

#define PI 3.14159265358979323846
#define SAMPLENUMBER 128

void FFT();
void InitForFFT();
void MakeWave();

int INPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
float fWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER],w[SAMPLENUMBER];
float sin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];

main()
{
int i;

InitForFFT();
MakeWave();
for ( i=0;i<SAMPLENUMBER;i++ )
{
    fWaveR[i]=INPUT[i];
    fWaveI[i]=0.0f;
    w[i]=0.0f;
}
FFT(fWaveR,fWaveI);
for ( i=0;i<SAMPLENUMBER;i++ )
{
    DATA[i]=w[i];
}
while ( 1 );    // break point

}

void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER])
{
int x0,x1,x2,x3,x4,x5,x6,xx;
int i,j,k,b,p,L;
float TR,TI,temp;

/********** following code invert sequence ************/
for ( i=0;i<SAMPLENUMBER;i++ )
{
    x0=x1=x2=x3=x4=x5=x6=0;
    x0=i&0x01; x1=(i/2)&0x01; x2=(i/4)&0x01; x3=(i/8)&0x01;x4=(i/16)&0x01; x5=(i/32)&0x01; x6=(i/64)&0x01;
    xx=x0*64+x1*32+x2*16+x3*8+x4*4+x5*2+x6;
    dataI[xx]=dataR[i];
}
for ( i=0;i<SAMPLENUMBER;i++ )
{
    dataR[i]=dataI[i]; dataI[i]=0; 
}

/************** following code FFT *******************/
for ( L=1;L<=7;L++ )
{ /* for(1) */
    b=1; i=L-1;
    while ( i>0 ) 
    {
        b=b*2; i--;
    } /* b= 2^(L-1) */
    for ( j=0;j<=b-1;j++ ) /* for (2) */
    {
        p=1; i=7-L;
        while ( i>0 ) /* p=pow(2,7-L)*j; */
        {
            p=p*2; i--;
        }
        p=p*j;
        for ( k=j;k<128;k=k+2*b ) /* for (3) */
        {
            TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b];
            dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
            dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
            dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
            dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
        } /* END for (3) */
    } /* END for (2) */
} /* END for (1) */
for ( i=0;i<SAMPLENUMBER/2;i++ )
{ 
    w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
}

} /* END FFT */

void InitForFFT()
{
int i;

for ( i=0;i<SAMPLENUMBER;i++ )
{
    sin_tab[i]=sin(PI*2*i/SAMPLENUMBER);
    cos_tab[i]=cos(PI*2*i/SAMPLENUMBER);
}

}

void MakeWave()
{
int i;

for ( i=0;i<SAMPLENUMBER;i++ )
{
    INPUT[i]=sin(PI*2*i/SAMPLENUMBER*3)*1024;
}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问