请硬汉和大家帮分析下,谢谢了先!
根据安富莱的DSP教程,我的主要程序如下:
#include <stdio.h>
#include "max_lib.h"
#include "stm32_dsp.h"
short AD_data[]={2029,2034,2040,2047,2055,2062,2069,2075,2081,2087,2093,2099,2106,2112,2118,2124,\
2130,2136,2142,2148,2155,2160,2167,2173,2178,2184,2190,2196,2201,2207,2212,2217,\
2222,2227,2232,2237,2242,2247,2250,2255,2259,2263,2267,2270,2273,2275,2277,2280,\
2282,2285,2286,2288,2290,2291,2293,2295,2297,2298,2299,2300,2300,2301,2301,2303,\
2303,2304,2304,2304,2305,2305,2305,2305,2305,2304,2304,2303,2302,2299,2296,2293,\
2291,2289,2286,2284,2279,2275,2270,2266,2262,2258,2254,2249,2245,2241,2237,2232,\
2227,2223,2219,2215,2211,2206,2202,2197,2192,2188,2182,2177,2171,2165,2158,2152,\
2146,2139,2132,2125,2118,2111,2104,2097,2090,2082,2074,2067,2060,2053,2046,2040,\
2033,2027,2021,2015,2010,2004,1996,1989,1981,1975,1969,1963,1957,1951,1945,1938,\
1932,1926,1920,1914,1908,1902,1896,1890,1884,1878,1872,1867,1861,1855,1849,1844,\
1838,1833,1828,1823,1818,1813,1808,1803,1799,1794,1791,1786,1783,1779,1777,1775,\
1773,1771,1768,1765,1763,1762,1760,1759,1757,1755,1754,1751,1751,1750,1749,1748,\
1748,1747,1746,1746,1745,1745,1745,1744,1744,1744,1745,1745,1745,1746,1747,1750,\
1753,1756,1759,1761,1762,1765,1768,1773,1778,1782,1786,1790,1794,1798,1803,1807,\
1811,1815,1820,1825,1829,1834,1838,1842,1846,1851,1856,1861,1867,1872,1877,1883,\
1890,1896,1902,1909,1916,1923,1930,1937,1944,1951,1959,1966,1974,1982,1989,1995
};
long fft_result[256]={0};
long Mag[256]={0};
int main()
{
unsigned char c;
int i;
long lBufferInArray[256];
// popFFT(dataIN, data); //First parameter is the result of FFT transform.
for (i=0; i < 256; i++)
{
// lBufferInArray = AD_data << 16 ;
lBufferInArray = AD_data; //根据DSP教程,高16为虚部,我这里是0,低16位是我的采集数据,是实部
}
cr4_fft_256_stm32(fft_result, lBufferInArray, 256);
// c=max_comp(3,5);
return 0 ;
}
/* stm32_dsp.h */
/* 256 points */
void cr4_fft_256_stm32(long *pssOUT, long *pssIN, unsigned short Nbin);
变换的结果为(FFT变换后的实部和虚部):
keil环境下仿真,简单起见,列出前5个计算结果
fft_result[0] = 0x000007e4
fft_result[1] = 0xff70fff4
fft_result[2] = 0xfffcfffc
fft_result[3] = 0xfffcfffc
fft_result[4] = 0xfffcfffc
matlab计算的前5项如下:
fft_result[1] = 518353 + 0i
fft_result[2] = -1690 - 36269i
fft_result[3] = -32 - 802i
fft_result[4] = 146 - 492i
fft_result[5] = 6.3 -323i
从以上结果对比,发现两种环境下计算的结果明显不同,难道是溢出,若真是这样,这个库函数就没有什么意义,因为A/D的12位数据,值都在1000~3500之间,这个区间的值计算溢出,那怎么解决呢?
非常希望得到大家的帮助。我明天再测试下arm提供的基2定点库。 |