首頁>Club>
12
回覆列表
  • 1 # 使用者834195712159

    程式碼示例:

    float ar[1024],ai[1024];/* 原始資料實部,虛部 */

    float a[2050];

    void fft(int nn) /* nn資料長度 */

    {

    int n1,n2,i,j,k,l,m,s,l1;

    float t1,t2,x,y;

    float w1,w2,u1,u2,z;

    float fsin[10]={0.000000,1.000000,0.707107,0.3826834,0.1950903,0.09801713,0.04906767,0.02454123,0.01227154,0.00613588,};

    float fcos[10]={-1.000000,0.000000,0.7071068,0.9238796,0.9807853,0.99518472,0.99879545,0.9996988,0.9999247,0.9999812,};

    switch(nn)

    {

    case 1024: s=10; break;

    case 512: s=9; break;

    case 256: s=8; break;

    }

    n1=nn/2; n2=nn-1;

    j=1;

    for(i=1;i<=nn;i++)

    {

    baia[2*i]=ar[i-1];

    a[2*i+1]=ai[i-1];

    }

    for(l=1;l<n2;l++)

    {

    if(l<j)

    {

    t1=a[2*j];

    t2=a[2*j+1];

    a[2*j]=a[2*l];

    a[2*j+1]=a[2*l+1];

    a[2*l]=t1;

    a[2*l+1]=t2;

    }

    k=n1;

    while (k<j)

    {

    j=j-k;

    k=k/2;

    }

    j=j+k;

    }

    for(i=1;i<=s;i++)

    {

    u1=1;

    u2=0;

    m=(1<<i);

    k=m>>1;

    w1=fcos[i-1];

    w2=-fsin[i-1];

    for(j=1;j<=k;j++)

    {

    for(l=j;l<nn;l=l+m)

    {

    l1=l+k;

    t1=a[2*l1]*u1-a[2*l1+1]*u2;

    t2=a[2*l1]*u2+a[2*l1+1]*u1;

    a[2*l1]=a[2*l]-t1;

    a[2*l1+1]=a[2*l+1]-t2;

    a[2*l]=a[2*l]+t1;

    a[2*l+1]=a[2*l+1]+t2;

    }

    z=u1*w1-u2*w2;

    u2=u1*w2+u2*w1;

    u1=z;

    }

    }

    for(i=1;i<=nn/2;i++)

    {

    ar[i]=4*a[2*i+2]/nn; /* 實部 */

    ai[i]=-4*a[2*i+3]/nn; /* 虛部 */

    a[i]=4*sqrt(ar[i]*ar[i]+ai[i]*ai[i]); /* 幅值 */

    }

    }

  • 中秋節和大豐收的關聯?
  • 超聲波計數器製作原理?