0

我正在使用 MSP432P401R 对 SAR ADC 样本进行 FFT,在 MATLAB 中进行 FFT 并得到与在线 C 编译器相同的结果,但 Code Composer Studio IDE 给出的输出与 MATLAB 结果不同,我认为这可能是编译器问题,所以尝试阅读相同的结果一些更改并尝试但没有得到结果,如 MATLAB。

在线 C 编译器是 gcc 5.4.1 c99。并在 CCS TI v5.2.5 编译器中使用。

float m;
float ur, ui, sr, si,tr, ti;
long double Temp_A[256],ArrayA[256]={2676,2840,2838,2832,2826,2818,2814,2808,
        2804,2798,2790,2784,2778,2770,2764,2758,2752,2746,2740,2734,
        2726,2720,2714,2706,2700,2692,2686,2680,2674,2668,2660,2654,
        2646,2642,2634,2624,2618,2612,2604,2598,2590,2584,2576,2570,
        2562,2556,2550,2542,2536,2530,2522,2512,2508,2498,2490,2484,
        2478,2470,2462,2454,2448,2442,2432,2426,2420,2414,2404,2398,
        2390,2382,2374,2368,2360,2352,2346,2338,2330,2322,2314,2306,
        2300,2294,2286,2278,2272,2262,2258,2250,2238,2234,2228,2220,
        2208,2202,2192,2186,2178,2170,2164,2156,2150,2142,2134,2126,
        2116,2110,2104,2096,2088,2078,2070,2062,2054,2046,2040,2034,
        2026,2018,2010,2002,1994,1986,1978,1970,1962,1954,1946,1936,
        1930,1922,1914,1908,1902,1894,1886,1876,1868,1860,1852,1846,
        1838,1830,1822,1814,1804,1796,1790,1784,1776,1768,1760,1754,
        1746,1738,1728,1720,1714,1708,1698,1692,1684,1674,1668,1656,
        1656,1644,1640,1628,1624,1612,1610,1598,1596,1584,1580,1570,
        1564,1554,1546,1540,1532,1526,1520,1512,1504,1496,1490,1482,
        1474,1468,1462,1454,1446,1438,1432,1424,1420,1410,1404,1398,
        1392,1384,1376,1370,1364,1356,1348,1342,1336,1328,1322,1316,
        1308,1300,1294,1286,1280,1276,1270,1262,1254,1248,1242,1236,
        1230,1222,1216,1210,1206,1198,1192,1188,1178,1172,1168,1162,
        1154,1148,1144,1138,1132,1126,1120,1114,1108,1102,1096,1090,
        1084,1080,1074,1068,1062,1058,1052,1048},ArrayA_IMX[256]={0};
unsigned int jm1,i;
unsigned int ip,l;

void main(void)
{
    WDT_A->CTL = WDT_A_CTL_PW |WDT_A_CTL_HOLD;
    VCORE();
    CLK();
    P1DIR |= BIT5;          //CLK--AD7352 OUTPUT DIRECTION
    P1DIR |= BIT7;          //CHIP SELECT--AD7352 OUTPUT DIRECTION
    P5DIR &= ~BIT0;         //SDATAA--AD7352 INPUT DIRECTION P5.0
    P5DIR &= ~BIT2;         //SDATAB--AD7352 INPUT DIRECTION P5.2
    while(1)
    {
            bit_reversal(ArrayA);
            fft(ArrayA,ArrayA_IMX);
    }
}
void bit_reversal(long double REX[])
{
    int i,i2,n,m;
    int tx,k,j;
    n = 1;
    m=8;
    for (i=0;i<m;i++)
    {
        n *= 2;
    }
    i2 = n >> 1;
    j = 0;
    for (i=0;i<n-1;i++)
    {
        if (i < j)
        {
            tx = REX[i];
            //ty = IMX[i];
            REX[i] = REX[j];
            //IMX[i] = IMX[j];
            REX[j] = tx;
            //IMX[j] = ty;
        }
        k = i2;
        while (k <= j)
        {
            j -= k;
            k >>= 1;
        }
        j += k;
    }
}
void fft(long double REX[],long double IMX[])
{
    N = 256;
    nm1 = N - 1;
    nd2 = N / 2;
    m = log10l(N) / log10l(2);
    j = nd2;

  for (l = 1; l <= m; l++)
  {
    le = powl(2, l);
    le2 = le / 2;
    ur = 1;
    ui = 0;

// Calculate sine and cosine values
sr = cosl(M_PI/le2);
si = -sinl(M_PI/le2);

// Loop for each sub DFT
for (j = 1; j <= le2; j++)
{
    jm1 = j - 1;

  // Loop for each butterfly
    for (i = jm1; i <= nm1; i += le)
    {
        ip = i + le2;
        tr = REX[ip]*ur - IMX[ip]*ui;
        ti = REX[ip]*ui + IMX[ip]*ur;
        REX[ip] = REX[i] - tr;
        IMX[ip] = IMX[i] - ti;
        REX[i] = REX[i] + tr;
        IMX[i] = IMX[i] + ti;
  }
  tr = ur;
  ur = tr*sr - ui*si;
  ui = tr*si + ui*sr;
}

}
  }
4

0 回答 0