# FFT on dsPIC ADC Values

Status
Not open for further replies.

#### krazy

##### New Member
Does anyone have any sample code for this?

I am trying to perform FFT on dsPIC ADC input and don't know where to begin.

Thank you.

#### krazy

##### New Member
Thanks for that. I'm browsing it thru it now....

For the record, I am trying to perform a FFT on the ADC buffer data to extract beats from music. I'm hoping this shouldn't be too hard...

#### krazy

##### New Member
Also, does anyone have any idea what twiddle factors are? I can't find any simplified explanations of it off hand.

#### krazy

##### New Member
Yeah I didn't understand that :\

What are some instances/examples of common 'trigonometic coefficients'? In what context is this meaningful?

Last edited:

#### BronzeG3

##### New Member
If i remember correctly, part of the process of doing the FFT involves multiplying the data by a series of constants. These constants are called Twiddle Factors.

When doing an FFT on a uC, you can pre-calculate these factors instead of having to calculate them every time.

#### krazy

##### New Member
Ah that makes sense!

My only problem with that is exactly what context they are used. They seem to be pretty specific to some kind of generalized formula, I'd imagine ('trigonometric coefficients'). I guess I just need to see that formula so I can understand what they are, are supposed to be, and how I can use them for fun and profit.

#### krazy

##### New Member
You don't need to know about twiddle factors or coefficients to run an FFT. Microchip has a free library for many of the common DSP tasks. Just call the appropriate function.

FFT is in: dsPIC DSC DSP Algorithm Library

Whole bunch of other libraries: Microchip - Software Libraries
dougy... one of the arguments for the built in FFT functions is the twiddle factors, though?

#### dougy83

##### Well-Known Member
Whether you want to understand what they are is up to you, you can generate them with the following line or use a lookup table in program memory (table available in link following).
Code:
TwidFactorInit (LOG2_BLOCK_LENGTH, &twiddleFactors[0], 0);	/* We need to do this only once at start-up */
Have a look at some of their example code (e.g. http://ww1.microchip.com/downloads/en/DeviceDoc/CE018_FFT_DSPlib_101007.zip). You can use the above function to create them in RAM, or you could have them defined in program memory (see twiddleFactors.c in the above .zip).

#### krazy

##### New Member
Whether you want to understand what they are is up to you, you can generate them with the following line or use a lookup table in program memory (table available in link following).
Code:
TwidFactorInit (LOG2_BLOCK_LENGTH, &twiddleFactors[0], 0);	/* We need to do this only once at start-up */
Have a look at some of their example code (e.g. http://ww1.microchip.com/downloads/en/DeviceDoc/CE018_FFT_DSPlib_101007.zip). You can use the above function to create them in RAM, or you could have them defined in program memory (see twiddleFactors.c in the above .zip).
D'oh!

After looking through exactly that code for the past few hours, I thought TwidFactorInit was simply a function written to abstract the twiddle factor array load into the appropriate memory spots. I didn't realize it was an actual generate function.

Great! Thanks for the help!

#### dougy83

##### Well-Known Member
Status
Not open for further replies.