完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,抱歉我的英语不好。我可以在FFTBuffic中获得FFT频谱,但是不能得到FrimeSuffRealEdCurx()的功率谱。我的代码有什么问题,或者程序参数错误吗?我使用DSPIC33 FJ64 GP802。有人请告诉我。
以上来自于百度翻译 以下为原文 Hi, sorry for my bad English. I can get FFT spectrum in fftbuffer, but can not get power spectrum generated by the function SquareMagnitudeCplx(). Is there something wrong with my code, or program parameter wrong? i use dsPIC33FJ64GP802. Someone please tell me. #include #include #include #include #include #define LOG2N 7 #define FFT_SIZE 128 //=2^7 #define NUM_TAPS 138 unsigned int Index; unsigned int flag; fractional SigIn[FFT_SIZE]; fractional FilterOut[FFT_SIZE]; fractcomplex fftBuffer[ FFT_SIZE ] __attribute__ ((space(ymemory), aligned (FFT_SIZE * 2 * 2))); // Place fftBuffer in Y-memory aligned to the size the array in bytes fractional window[FFT_SIZE]; // Hamming window fractional powerspec[FFT_SIZE]; // Power Spectrum fractcomplex twiddleFactors[ FFT_SIZE/2 ]__attribute__((space(xmemory))); fractional _YBSS(128) delay[FFT_SIZE]; const fractional lpfCoeffs[NUM_TAPS] __attribute__ ((space(auto_psv), aligned (FFT_SIZE * 2 * 2))) ={ 1424,-2012,-1898,131,4372,8848,10772,8848,4372,131,-1898,-2012,1424 }; //filter coefficient FIRStruct LPF; //LPF fc1=1000 fc2=2000 void initADC(void) { AD1PCFGL = 0x03C0; //AN0-3 analog AD1CON1bits.SSRC = 2; //Internal counter ends sampling and starts conversion (auto-convert) AD1CON1bits.AD12B = 1; //12-bit, 1-channel ADC operation AD1CON1bits.ADON = 1; //ADC module is operating AD1CON1bits.ASAM = 1; AD1CON2 = 0x00; //ADCON2 no scan AD1CON3bits.SAMC = 0; //Autosample time AD1CON3 = 0b0000000000001001; // Tad={Tcy(ADCS+1)}/2>334ns, Then ADCS>18.7, Tad=10*Tcy AD1PCFGL=0xFFFF; //AD1PCFGH=0xFFFF; AD1CSSL = 0b0000000000000000; AD1PCFGLbits.PCFG1 = 0; //port pin in analogmode, port read input disabled, ADC samples pin voltage IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit IEC0bits.AD1IE = 0; // Do Not Enable A/D interrupt } //return ADC result 32uS@Tcy=36.85MHz unsigned int readADC() { AD1CHS0 = 0x0001; //input channel in this AN1 is input AD1CON1bits.SAMP = 1; // ADC Sample Enable bit while(!AD1CON1bits.DONE); //wait until done ADC AD1CON1bits.DONE=0; //status = 0 return ADC1BUF0; //result } // Timer subroutine void __attribute__((interrupt, auto_psv)) _T3Interrupt(void) { IFS0bits.T3IF = 0; while(!IFS0bits.AD1IF); SigIn[Index++] = readADC(); //FIR (FFT_SIZE, &FilterOut[Index++], &SigIn[Index++], &HPF); if(Index == FFT_SIZE) { T3CONbits.TON = 0; flag = 1; } IFS0bits.AD1IF = 0; IFS0bits.T3IF = 0; } int main(void) { int i, j, k; /// Initialize Clock OSCCON = 0x00300; // PRIPLL?? CLKDIV = 0x0100; // prescaler set1:2 PLLFBD = 0x0026; // 40times?8MHz÷2×40÷2 = 80MHz RCONbits.SWDTEN = 0; //watchdog timer off initADC(); OpenTimer3(T3_ON & T3_GATE_OFF & T3_PS_1_1 &T3_SOURCE_INT, 1600-1); ConfigIntTimer3(T3_INT_PRIOR_5 & T3_INT_ON); /// T3setting:T3= 10kHz = 16000kHz / 1600 flag = 0; Index = 0; TwidFactorInit(LOG2N, twiddleFactors, 0); HammingInit (FFT_SIZE, window); FIRStructInit( &LPF, NUM_TAPS, (fractional *)lpfCoeffs, PSVPAG, delay ); FIRDelayInit (&LPF); DISICNT = 0x0000; //enable interruput while(1) { //while(!flag); flag = 0; fftBuffer[0].real = 0; fftBuffer[1].real = 0; for(j = 0; j < FFT_SIZE; j++) FIR (1, &FilterOut[j], &SigIn[j], &LPF); VectorWindow(FFT_SIZE, FilterOut, FilterOut, window); for(i = 2; i < FFT_SIZE; i++) { fftBuffer.real = FilterOut; fftBuffer.imag = 0; } FFTComplexIP(LOG2N, fftBuffer, twiddleFactors, COEFFS_IN_DATA); BitReverseComplex(LOG2N, fftBuffer ); SquareMagnitudeCplx( FFT_SIZE , fftBuffer, powerspec); |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
5206 浏览 9 评论
2017 浏览 8 评论
1943 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
758浏览 1评论
644浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
558浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
656浏览 0评论
556浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-8 01:45 , Processed in 1.017373 second(s), Total 46, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号