Hi Community,
I have a set of FFT codes that is suppose to create an array of number after processing the incoming signal.
When I build my codes in code composer studio it was successfully built.
However, when I run it on debug mode it face problems.
The purpose of my project is to simply program a set of FFT algorithm in c, and allow my LM3s8962 micro-controller to process the incoming signal(Voice or sound).
I have another question, can I use the algorithm to run it in my keil uvision, since the keil uvision has the spectrum/logic analyser which I can see the frequency spectrum.
I will attach my algorithms here, if any kind hearted soul spot any mistakes in my algorithm please enlighten me.
/* * main.c */#include <stdio.h>#include <math.h>#include <stdbool.h>#include <stdint.h>#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "inc/hw_ints.h"#include "driverlib/sysctl.h"#include "driverlib/adc.h"#include "driverlib/interrupt.h"#include "driverlib/gpio.h"#include "driverlib/pin_map.h"#include "grlib/grLib.h"#include "grlib/grLibDriver.h"
short sample[8];
#pragma vector=unused_interruptsinterrupt void user_trap_function(void) //ISR to handle the end of sampling interrup, being the only enabled interrupt{ int df = 15625; //fs/N = 125000/8 int Re[8]; int Im[8]; int Ampl[8]; int fr[8]; int N = 8; //number of samples x[N] = (short)sample; // convert sample values to short integers for computation int out[2] = {0,0}; //init Re and Im results int j=0; for (j = 0; j < N; j++){ dft(x,j,out); //call DFT function Re[j] = out[0]; Im[j] = out[1]; //collect real and imaginary parts Ampl[j] = ((Re[j]^2)+(Im[j]^2))^(1/2); fr[j] = df*j;
long lX1 = (long)Ampl[j]; long lX2 = (long)Ampl[j]+1; long lY = (long)fr[j]; long ulValue = 128;
void LineDrawH (pvDisplayData, lX1, , lX1, lY, ulValue);
}
int M = 0;unsigned long sample[8]
void LineDrawH (void *pvDisplayData, long lX1, long lX2, long lY, unsigned long ulValue);
void ADC_init( void ) { SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC; // Enable the clock to the ADC module SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADCSPD125K; // Configure the ADC to sample at 125KS/s ADCSequenceDisable(ADC_BASE, 0); // Disable sample sequences 0 ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 1); // Configure sample sequence 0: processor trigger, priority = 1 IntPrioritySet(INT_ADC0SS0,0); // Set SS0 interrupt priority to 0 ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0); // Configure sample sequence 0 to sample external input ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 2, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 3, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 4, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 5, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 6, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 0, 7, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); //set interrupt flag after the seventh step ADCIntEnable(ADC_BASE, 0); // Enable the interrupt for sample sequence 0 IntEnable(INT_ADC0SS0); // Enable SS0 Interupt in NVIC M+=M; // integer to detect if ADC is initialized}
unsigned long getADC0(void){
ADCProcessorTrigger(ADC0_BASE, 0); //initiate sampling while(!ADCIntStatus(ADC0_BASE, 0, false)); //monitor interrupt flag for completion of sampling ADCSequenceDataGet(ADC0_BASE, 0, sample); //assign samples to global variable, sample
return sample; //return sample to calling function}
int dft(long *x, short k, int *out) //DFT function { int sumRe = 0; //init real component int sumIm = 0; //init imaginary component int i = 0; int N = 8; float pi = 3.1416 ; float cs = 0; //init cosine component float sn = 0; //init sine component for (i = 0; i < N; i++) //for N-point DFT { cs = cos(2*pi*(k)*i/N); //real component sn = sin(2*pi*(k)*i/N); //imaginary component sumRe += x[i]*cs; //sum of real components sumIm -= x[i]*sn; //sum of imaginary components } out[0] = sumRe; //sum of real components out[1] = sumIm; //sum of imaginary components
return(out); }int main(void) { if (M>0){ ADC_init(); //initialize ADC module if not already initialized } getADC0(); //start conversion. Interrupt flag will be set after sampling and this functioned called again after ISR executes return 0;}
Hi, Goodwin.
I am very new to keil uvision and c programming.
My project requires me to program fft/dft in c algorithm and allow my micro-processor to process the algorithm.
I am actually quite weak at this area.
You mention, there is actually an elegant way in doing my project.
Is there any available source code to be use for my intended project. Such that I no need to come out with my own algorithm.
But use an available dft or fft algorithm that was created to process an incoming signal.? Please advise
Are you a student (is this a project in school)? I asked this so I will not have to make assumptions, and hopefully provide you with more useful answer. Specifically, I would like to know the ff: