- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am getting results for integers but not for floating point. Can u suggest changes for floating point?
Thank u!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Asha, is the performance a reflection you used the HW multiplier in
PSOC 4 ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 -
“Support”
“Technical Support”
“Create a Case”
You have to be registered on Cypress web site first.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@isen, did you use the internal single cycle 32 bit multiplier in PSO C 4 ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And btw, I haven't used the whole hardware chain just yet, cause I wanted to try out different algorithms for the Fourier transform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello! What changes should be done if I have input as float or double?
Thanks in advance.
-Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.