FFT in Cortex M0

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 Hi All,

   

I guess few of you would like to implement FFT in PSoC4. I have attached a PSoC Creator project which does the same.

   

I have computed 64 point FFT and the CPU consumes around 634.7us to perform the operation.

   

This has been done completely through firmware.

   

Regards,
Asha

19 Replies
Anonymous
Not applicable
        Hi, Interesting procedure. 0.6m.sec is very fast, Maybe have use integer FFT. I had been made by PSoC5 floating point that is takes 15m.sec 128points. Someday, the module could completed, I'll be upload it. Regards.   
0 Likes
Anonymous
Not applicable

I am getting results for integers but not for floating point. Can u suggest changes for floating point?

   

Thank u!

0 Likes
Anonymous
Not applicable

 Does this FFT work? Or has anybody fixed it?

   

I had to fix several things to make it compile without warnings.

   

The input array tries to initialize 128 locations but the array is only [64].

   

Twiddlereal and twiddleimg are [32], second stage tries to access [32] which is out of bounds.

   

Seventh stage accesses several arrays out of bounds.  I believe this stage isn't used for 64 point FFT.

   

Stage 1 code makes no sense at all.  It gets inputs beyond the array bounds.

   

Mike

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Asha, is the performance a reflection you used the HW multiplier in

   

PSOC 4 ?

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable
0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Consider filing a CASE and asking Cypress support to contact

   

Asha to see if it can  get updated.

   

 

   

    

   

          

   

To create a technical case at Cypress -

   

 

   

www.cypress.com

   

“Support”

   

“Technical Support”

   

“Create a Case”

   

 

   

You have to be registered on Cypress web site first.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi All,    

   

 

   

I'm attaching the PSoC 4 project (PSoC creator 3.2) for 64-point FFT computation.     

   

It uses about  ~1900 bytes of SRAM. In this example, a 64 pt array is initialized and used as data input for FFT. It completes the calculations in 484usec, when the compiler optimization is set to speed.    

   

Senthilnathan

0 Likes
Anonymous
Not applicable

 In the attached project(in my previous response), for the 64-point FFT, we need to comment out the lines after line 234 (seventh stage of fft computation, which is needed only for 128 point FFT calculations). 

   

As mentioned in the comment (line 234), that part of the code is for 128-point FFT computation. We need to change the parameter NUM_FFT to 128, when using the 128-point FFT (by changing line 6 - '#define NUM_FFT 128'). 

For 64-point FFT, that is not needed. And if it is there, memory location will be corrupted (overwritten) and will not be correct.

   

/Senthilnathan

0 Likes
Anonymous
Not applicable

 Hello Isen,

   

Thank you for posting code for FFT in PSoC 4. I have few questions:

   

1. You mentioned that code can be used with 128-point FFT. Does in mean that to try it, the samplep[NUM_FFT] array needs to be initialized with 128 values instead of 64?

   

2. My understanding is that the output of the calculations will be stored in two arrays - one that contains real values, and another one with imaginary. Can you explain why there are two pairs of arrays, not one? (real0/img0 + real1/img1). What is the difference between the two? Also, what information does twiddlereal and twiddleimg aray contain and do I need them to show FFT magnitude in a plot?

   

3. I am working on vibration detection project. I can generate more samples than 64/128 in the project if needed. How scalable this algorithm beyond 128-point is, and what if anything needs to be changed to go to higher number of points? Also, does it make sense going beyond 128-point FFT? I am doing desing on PRoC 4 BLE module so I don't have much resources to begin with.

   

Thank you for your help.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

@isen, did you use the internal single cycle 32 bit multiplier in PSO C 4 ?

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello Isen,

   

I have attached an Excel spreadsheet. It has two tabs. 

   

"Using Cypress Results" - For input, I have 64 values that were used in array initialization. I plotted them vs time and I do see a sine wave. I then added two tables. One has results of Real 0 and Img 0 array, and another has Real 1 and Img 1 arrays. I then calculated magnitude of each pair and plotted them. Neither of the plots shows the expected frequency at ~ 780Hz. 

   

"Excel Method" - I used the same input. I then used Excel built-in FFT calculator. I obtained complex part for every value and calculatued magnitude from there. I plotted, and I did see one spike around 853Hz (not quite 780Hz but close). Then, for some reason after 5KHz, the frequency floor went up and I saw another spike at 7.19KHz. Not sure why this happens but I think If I disregard for a moment frequencies over ~4KHz, the plot looks more like what I would expect than what I see when I plotted results obtained from running routine on PSoC 4. 

   


Would you please comment on my results, and also reply to my questions posted in the previous post?

   

Thanks,

0 Likes
Anonymous
Not applicable

Dear Starik,

   

concerning the Excel Method:

   

From a 64 pt. analog signal that goes into an FFT you'll get 32 frequency values. The frequency value at the begin of the graph is the DC offset. Than you can see 31 frequencies. From 33 on the frequency values are just mirrored.

   

Concering the worksheet Cypress results:

   

I can't see a spectrum there.

   

What does Cypress tells us about that?

   

Is the FFT function working propperly or not?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello Isen,

   

I just revisited the results obtained for img0/real0, img1/real1 and I ran the code again and noticed that results are different this time from what I have recorded yesterday. I put new numbers in my spreadsheet (see attached spreadsheet with words REVISED DATA at the end of the file name). The plot looks very different but still doesn't make sense.

0 Likes
lock attach
Attachments are accessible only for community members.
MuKa_284621
Level 3
Level 3

Hi everyone,

   

 

   

I just wanted to share Isen's project that I modified for my application. I kept the algorithm at 64-points although I had targeted 16-points. I added some more libraries to work with an OLED screen using I2C. I attach in a separate zip file some images and a short 5-sec video of the thing working.

   

 

   

It bugs me tho that a static sample gives different results every calculation cycle. Is it due to calculation error? If so, it could tally with Starik's observation.

   

 

   

Feel free to comment and try things out (if you have the screen: http://www.cytron.com.my/p-ds-oled-mod, looks like an Adafruit stuff).

   

 

   

Hazique,

0 Likes

And btw, I haven't used the whole hardware chain just yet, cause I wanted to try out different algorithms for the Fourier transform.

0 Likes
lock attach
Attachments are accessible only for community members.

Indeed the original code has several mistakes. I attach a corrected 16-bit version with quite some modifications.

   

 

   

Interesting to note that as soon as we get to stage 3 and above, the code is basically similar, except for several loop values, etc. This is due to the symmetricity of the calculation (I had drawn my own butterfly diagram to see this myself!). I think it could be easily scalable to more than 128, but for a device with limited memory, that's a different story.

0 Likes
Anonymous
Not applicable

Hello! What changes should be done if I have input as float or double?

   

Thanks in advance.

   

 

   

-Akshay

0 Likes
Anonymous
Not applicable

U can use complex numbers directly to calculate fft. But for psoc 4, this could be done only for 16 point fft due to memory issues.

0 Likes
lock attach
Attachments are accessible only for community members.
VlYe_281166
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

That all is very good of course, but no resources stayed for something usefull.
Here is my adaptation of arduino fix_fft lib for arm. It requires very low resources and works fine.
Use two arrays:
int8   data[128];    //input data
int8   im[128]={0};

and call
fix_fft(data, im, 7, 0);
results also in these arrays.

0 Likes