1 2 Previous Next 19 Replies Latest reply on Sep 21, 2016 11:10 PM by akshay.datar

    FFT in Cortex M0


       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.



        • 1. Re: FFT in Cortex M0
                  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.   
          • 2. Re: FFT in Cortex M0

             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.



            • 3. Re: FFT in Cortex M0

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


              PSOC 4 ?




              Regards, Dana.

              • 5. Re: FFT in Cortex M0

                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 -








                “Technical Support”


                “Create a Case”




                You have to be registered on Cypress web site first.




                Regards, Dana.

                • 6. Re: FFT in Cortex M0

                  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.    




                  • 7. Re: FFT in Cortex M0

                     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.



                    • 8. Re: FFT in Cortex M0

                       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.

                      • 9. Re: FFT in Cortex M0

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




                        Regards, Dana.

                        • 10. Re: FFT in Cortex M0

                          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?



                          • 11. Re: FFT in Cortex M0

                            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.

                            • 12. Re: FFT in Cortex M0

                              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?

                              • 13. Re: FFT in Cortex M0

                                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).





                                • 14. Re: FFT in Cortex M0

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

                                  1 2 Previous Next