Using FFT_test.fcfx
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Thanks for letting us know about the problem your facing. I will investigate and see if I can work out what's going wrong.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Using FFT_test.fcfx
Hi Larry,
What kind of wave form is you input?
Best regards,
Jac
What kind of wave form is you input?
Best regards,
Jac
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Jac
Wave form is sine wave from a function generator. I tried 0 center and also 0 at the bottom on the sine wave with the same results in both cases. I also checked the input sine wave on a scope. Larry
Wave form is sine wave from a function generator. I tried 0 center and also 0 at the bottom on the sine wave with the same results in both cases. I also checked the input sine wave on a scope. Larry
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
I just noticed in the console that the Input buffer contains 32 pieces of data which is correct for the buffer size allocated, however after the FFT is processed the console shows 192 pieces of data for FFT_Real buffer and the same for FFT_imag buffer which also has 32 spaces allocated for each. This does not seem right to me. Perhaps, this points to the problem.
Larry
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hello,
I seem to be getting similar results so will continue this afternoon and see if I can find the source of the problem.
The console outputs any value written to the buffer, the FFT performs several passes as it re-orders the data and all of the passes will be shown on the console. Hence the extra values you are seeing.
I seem to be getting similar results so will continue this afternoon and see if I can find the source of the problem.
The console outputs any value written to the buffer, the FFT performs several passes as it re-orders the data and all of the passes will be shown on the console. Hence the extra values you are seeing.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
A solution would indeed be awesome. So far it is eluding me but I believe some progress has been made.
Red = Signal In
Green = FFT Output Real
Blue = FFT Output Imaginary
Black = FFT Output Frequency Banks
Red = Signal In
Green = FFT Output Real
Blue = FFT Output Imaginary
Black = FFT Output Frequency Banks
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hello,
I've spent most of the morning working on this issue and have made progress but don't seem to really be getting anywhere fast. So I will do some of my scheduled work and then jump back on this when I get some more free time.
Sorry the news couldn't be better. Is this for a commercial project and do you have a deadline you are working to?
I've spent most of the morning working on this issue and have made progress but don't seem to really be getting anywhere fast. So I will do some of my scheduled work and then jump back on this when I get some more free time.
Sorry the news couldn't be better. Is this for a commercial project and do you have a deadline you are working to?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
Yes commercial project.
I don't have a hard deadline but I am being pushed.
Larry
Yes commercial project.
I don't have a hard deadline but I am being pushed.
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Ok understood. I'm fairly certain the code is right but there is an overflow issue or something similar going on. I will do some more reading and check my maths is making sense.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
Thanks for the update. Eagerly awaiting a solution.
By the way, this is not a chip specific problem I hope, as I intend to migrate to 30F3012 (18 pin) as the final chip. I'm presently using the 4013 because of the extra peripherals to aid in the diagnostics as the program evolves.
Larry
Thanks for the update. Eagerly awaiting a solution.
By the way, this is not a chip specific problem I hope, as I intend to migrate to 30F3012 (18 pin) as the final chip. I'm presently using the 4013 because of the extra peripherals to aid in the diagnostics as the program evolves.
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hello Larry,
No it's not chip specific, it's a problem with the maths.
Progress...
I have started again in a blank Flowcode project and have now managed to get somewhere.
Here is a file which shows how I got it working. Depending on your application this file may be enough to allow you to continue.
I've not tried it on hardware yet but I'm hopeful.
Tomorrow I will take this code and place it back into the DSP component so hopefully this can function correctly too.
No it's not chip specific, it's a problem with the maths.
Progress...
I have started again in a blank Flowcode project and have now managed to get somewhere.
Here is a file which shows how I got it working. Depending on your application this file may be enough to allow you to continue.
I've not tried it on hardware yet but I'm hopeful.
Tomorrow I will take this code and place it back into the DSP component so hopefully this can function correctly too.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Using FFT_test.fcfx
Gents,
Please keep in mind you might get artefacts if the sample does not start and end at a zero crossing of the input sine. Using a window function (Hanning, Hamming or any of the others) will reduce that effect, but not eliminate it. Also I found I had to reduce the amplitude of samples by half to prevent overflow while working with FFT. (I'm using dsPIC FFT functions as used in my article wrapped in a FC6 component)
Best regards,
Jac
Please keep in mind you might get artefacts if the sample does not start and end at a zero crossing of the input sine. Using a window function (Hanning, Hamming or any of the others) will reduce that effect, but not eliminate it. Also I found I had to reduce the amplitude of samples by half to prevent overflow while working with FFT. (I'm using dsPIC FFT functions as used in my article wrapped in a FC6 component)
Best regards,
Jac
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hello,
I've managed to make some progress and route out a few bugs.
Here is my test program.
This is working great in simulation and on hardware. I've just tried with some real world data and this also seems ok though still not perfect. This could be down to what Jac also noticed. I will see if we can add a simple windowing filter on the data before we run the FFT calculations to see if this improves things.
Let me know how your getting on.
I've managed to make some progress and route out a few bugs.
Here is my test program.
This is working great in simulation and on hardware. I've just tried with some real world data and this also seems ok though still not perfect. This could be down to what Jac also noticed. I will see if we can add a simple windowing filter on the data before we run the FFT calculations to see if this improves things.
Let me know how your getting on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
I played with it and still don't get useful output data from the bins. My program will be making decisions based on certain bin content and will not be reconstructing any of the output as it has no use after the bin data evaluation.
I noticed that your clock is set at 96Mhz and timer-1 set at 16khz and FFT sampling at 8khz. Should those numbers be significant to me, or is that just where you left them for your testing purposes?
Larry
I played with it and still don't get useful output data from the bins. My program will be making decisions based on certain bin content and will not be reconstructing any of the output as it has no use after the bin data evaluation.
I noticed that your clock is set at 96Mhz and timer-1 set at 16khz and FFT sampling at 8khz. Should those numbers be significant to me, or is that just where you left them for your testing purposes?
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hi Larry,
I have now added a filter property to automatically do a window filter on the data and this is now giving me a very nice frequency spike.
I have now added a filter property to automatically do a window filter on the data and this is now giving me a very nice frequency spike.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
Seems to be very much improved. I am getting some usable results.Is it now complete, or is there more tweaking to do?
I will be doing more experiments today.
Larry
Seems to be very much improved. I am getting some usable results.Is it now complete, or is there more tweaking to do?
I will be doing more experiments today.
Larry
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
It seems that discrimination between frequencies is poor. For instance, I set up to read the 500hz bin and get a a level of 120 from that bin with 500hz signal applied, then I take the freq on the function generator up to higher frequencies in 100hz steps up to 1khz and still get 120 and higher from the 500hz bin. I would expect that as I move away from the frequency designated for that bin, that the number in the bin would diminish substantially.
I am using a sample rate of 2000 with sample count of 32 so I get 16 bins 63hz per bin.
Larry
It seems that discrimination between frequencies is poor. For instance, I set up to read the 500hz bin and get a a level of 120 from that bin with 500hz signal applied, then I take the freq on the function generator up to higher frequencies in 100hz steps up to 1khz and still get 120 and higher from the 500hz bin. I would expect that as I move away from the frequency designated for that bin, that the number in the bin would diminish substantially.
I am using a sample rate of 2000 with sample count of 32 so I get 16 bins 63hz per bin.
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hi Larry,
Can you attach your program or a simplified version which exhibits the problem and I will investigate for you.
Can you attach your program or a simplified version which exhibits the problem and I will investigate for you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
Here is the latest version of my program, as it seems to change minute by minute. Presently, I am getting values in the #9 bin at frequencies 250hz, 650hz and 750hz. These are the frequencies I input from a function generator with clean sine wave as shown in the photo of my scope in a previous post several above this one.
I am sampling at a rate of 2000 for 32 samples, so that I get 16 bins of final FFT data. Input is 1volt p-p with 0 center.
Larry
Update: As I was writing this post, I tested with function generator set to 0 at the bottom of the sine wave and was able to get better discrimination.
Here is the latest version of my program, as it seems to change minute by minute. Presently, I am getting values in the #9 bin at frequencies 250hz, 650hz and 750hz. These are the frequencies I input from a function generator with clean sine wave as shown in the photo of my scope in a previous post several above this one.
I am sampling at a rate of 2000 for 32 samples, so that I get 16 bins of final FFT data. Input is 1volt p-p with 0 center.
Larry
Update: As I was writing this post, I tested with function generator set to 0 at the bottom of the sine wave and was able to get better discrimination.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hi Larry,
Aha yes that might explain things. The ADC input has to be positive, negative voltages will just be read by the micro as 0's. You then subtract an offset from the value in software to get the signal centred around the 0 position. The closer you can get this offset the better frequency discrimination you should achieve.
For example input voltage = 5V peak to peak sinewave, centred around 2.5V
The ADC reads the value as 10-bit Int to give the value 0-1023.
Subtracting 512 from the ADC input will give you -512-511 with the mid point at 0.
...
If the input voltage is instead 2V peak to peak sinewave, centred around 1V
The ADC reads the value as 10-bit Int to give the value 0-409.
Subtracting 205 from the ADC input will give you -205-204 with the mid point at 0.
You could do automatic level detection in your program by using the DSP level component and collecting the max and min values from the input buffer before subtracting the offset and running the FFT.
Offset = (Max - Min) / 2
Signal = Signal - (Offset + Min)
Aha yes that might explain things. The ADC input has to be positive, negative voltages will just be read by the micro as 0's. You then subtract an offset from the value in software to get the signal centred around the 0 position. The closer you can get this offset the better frequency discrimination you should achieve.
For example input voltage = 5V peak to peak sinewave, centred around 2.5V
The ADC reads the value as 10-bit Int to give the value 0-1023.
Subtracting 512 from the ADC input will give you -512-511 with the mid point at 0.
...
If the input voltage is instead 2V peak to peak sinewave, centred around 1V
The ADC reads the value as 10-bit Int to give the value 0-409.
Subtracting 205 from the ADC input will give you -205-204 with the mid point at 0.
You could do automatic level detection in your program by using the DSP level component and collecting the max and min values from the input buffer before subtracting the offset and running the FFT.
Offset = (Max - Min) / 2
Signal = Signal - (Offset + Min)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Here is an example with my attempt at auto levelling.
It doesn't work as well as I was hoping. Could be that auto levelling is a bad idea and instead you need to get the levels from the average of several buffers to get a true idea of the actual min and max.
Luckily the DSP Level component has a property to allow you to do just that
Upping the decay to 10 does seem to be better but still not as good as simply subtracting the fixed offset.
A decay of 25 seems better again.
It doesn't work as well as I was hoping. Could be that auto levelling is a bad idea and instead you need to get the levels from the average of several buffers to get a true idea of the actual min and max.
Luckily the DSP Level component has a property to allow you to do just that
Upping the decay to 10 does seem to be better but still not as good as simply subtracting the fixed offset.
A decay of 25 seems better again.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Thu Feb 10, 2011 4:39 am
- Location: Las Vegas, Nevada USA
- Has thanked: 40 times
- Been thanked: 19 times
Re: Using FFT_test.fcfx
Hi Ben
Thank you for the response.
I believe the adc on the 30F3012 is 12bit, so full scale 4095. If this is correct I can adjust what you said above to this value. Please comment.
Larry
Thank you for the response.
I believe the adc on the 30F3012 is 12bit, so full scale 4095. If this is correct I can adjust what you said above to this value. Please comment.
Larry
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using FFT_test.fcfx
Hi Larry,
Yep 12-bit ADC = 0-4095
For example input voltage = 5V peak to peak sinewave, centred around 2.5V
Subtracting 2048 from the ADC input will give you -2048-2047 with the mid point at 0.
...
If the input voltage is instead 2V peak to peak sinewave, centred around 1V
The ADC reads the value as 12-bit Int to give the value 0-1638.
Subtracting 819 from the ADC input will give you -819-819 with the mid point at 0.
Yep 12-bit ADC = 0-4095
For example input voltage = 5V peak to peak sinewave, centred around 2.5V
Subtracting 2048 from the ADC input will give you -2048-2047 with the mid point at 0.
...
If the input voltage is instead 2V peak to peak sinewave, centred around 1V
The ADC reads the value as 12-bit Int to give the value 0-1638.
Subtracting 819 from the ADC input will give you -819-819 with the mid point at 0.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel