Comments (24)
Also thank you for the great library,
I also have the same problem (microphone via ADC).
MajorPeak no longer works from version 2.0.
Thanks
from arduinofft.
I used the same program and the same (quiet) noise source for both versions.
Sample 512; Sample frequency 1000Hz, the microphone PIN goes to A0 with 12 bits.
from arduinofft.
That sounds very problematic. Can you give me more details regarding your code? Since you downgraded to 1.6.2, I assume you are using the pre-2.0 API. Based on the fact that you are using a microphone, I assume that you are sampling through the ADC and doing something similar to Example_03.
from arduinofft.
@hp2020 @Andrey-Se
I have some more questions that will help me figure out what the problem is.
- On 2.0, are you using the old API or the new one?
- What data type are you using?
- Are you using any of the
#define
optimizations? - What is the output that
MajorPeak
returns? - Is the output off target or is it zero?
I hope I can find the problem with that info. Otherwise, I may need a printout of the output of the previous steps, aka, windowing
, compute
, etc... to backtrack the issue.
from arduinofft.
Never mind the questions. I can confirm now that the bug is there. It is related to the signal only being composed of positive numbers. As a TEMPORARY WORKAROUND, make sure to use dcRemoval
after filling the vReal buffer. That should do the trick while I fix the issue.
from arduinofft.
With the workaround it works perfectly, thank you for the very competent and quick problem solving.
from arduinofft.
This should be fixed with the latest version of the code #95
Please check it thoroughly and let me know if the problem persists.
from arduinofft.
Lines 146 to 148 in 0da8851
@kosme I'm wondering if there is a better place to fix the problem 🤔 if you clear bin 0 directly after FFT, then a reverse FFT will have problems to reconstruct the signal - after all the DC is in the signal, and you just cleared the "real" part leaving vImag[0] intact. So complexToMagnitude() would still return the imaginary part.
Maybe people who don't want to see DC should use a low-cut filter before running FFT... .
It might be better to adjust majorPeak() and majorPeakParabola(), and make these functions ignore the content of vReal[0]?
from arduinofft.
@softhack007 You are right. Removing the spike generates a DC offset in the reconstructed signal after the IFFT. I will make the change to majorPeak()
and majorPeakParabola()
from arduinofft.
The problem still exists, in version 1.6.2 the values range from around 50 to 4000 depending on the tone. In version 2.0.2 around 8, in versions 2.0.0 and 2.0.1 around 1. In all 2.0. X versions with the workaround, the values are the same as in version 1.6.2.
from arduinofft.
@hp2020 I don't really understand your last comment. Could you elaborate? Which values range from 50 to 4000?
from arduinofft.
@hp2020 I guess your answer to the comment above is located here. I still don't understand what your point is. Could you please provide a printout of the spectrum after the complexToMagnitude
function for 1.6.2 and 2.0.x? Obviously, without using the workaround.
FFT.complexToMagnitude(); /* Compute magnitudes */ Serial.println("Computed magnitudes:"); PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
That would really help me understand your point.
from arduinofft.
Here are the results without a workaround.
Computed magnitudes_2.0X.txt
Computed magnitudes_162.txt
For my project (detection of harmful insects), the workaround is completely sufficient for me.
from arduinofft.
@hp2020 I have been checking the data you provided and I noticed that on 1.6.2 you have lots of negative values. Since they are the result of a square root, magnitudes are always positive. This tells me that you are working with really big positive numbers and most likely have an overflow.
from arduinofft.
Still looks quite weird. Please post, besides the spectrum, a printout of vReal after you finish capturing the data. I'll use that data to try to replicate, and hopefully solve, the problem.
from arduinofft.
Sorry, in the first printout I unfortunately had the following code in the program * FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD); *
This resulted in the negative values.
This has been cleaned up in the current printouts. The MajorPeak is 1.92 in the 2.02 version and 457.67 in the 1.62 version.
- peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY); *
Magnitudes_vReal_162.txt
Magnitudes_vReal_202.txt
from arduinofft.
Your computation results are very strange and different for something with a similar data input. As I said in my previous message, I would like to see the original data after capture and before windowing
and compute
and the spectrum aftercomplexToMagnitude
for comparison.
from arduinofft.
Ok, I hope this is the data you need.
Computed magnitudes_Data_Input_162.txt
Computed magnitudes_Data_Input_202.txt
from arduinofft.
So, based on the last files, you are saying that using those 66 samples for 1.6.2 and 64 samples for 2.0.2, you were able to produce the provided spectrums, each with 64 bins?? There is no way that is possible, it requires exactly 128 samples.
from arduinofft.
I didn't copy all of them but I can still add the missing ones, but they are all similar.
from arduinofft.
I need a full set to try to reproduce the problem.
from arduinofft.
Here is the data you want. But as I said, the workaround with * FFT.dcRemoval(vReal, SAMPLES); * is completely sufficient for my application.
Computed magnitudes_Data_Input_162.txt
Computed magnitudes_Data_Input_202.txt
from arduinofft.
The problem still exists, in version 1.6.2 the values range from around 50 to 4000 depending on the tone. In version 2.0.2 around 8, in versions 2.0.0 and 2.0.1 around 1. In all 2.0. X versions with the workaround, the values are the same as in version 1.6.2.
I cannot reproduce the problem with the data that you provided. Versions 2.0.2 and 1.6.2 identical outputs both for frequency and magnitude. The spectrum is not even remotely similar to the one you sent. Without further information, I cannot proceed with diagnostics.
from arduinofft.
Here is the original example FFT_03, only the values of majorPeak, in both versions. In version 2.02 the values are an order of magnitude lower and are largely unchangeable. In version 1.62 the values are changeable and are a power of ten higher.
The recording conditions from the microphone are very similar. (finger tapping on the tabletop)
FFT_03 only majorPeak every 5sec_202.txt
FFT_03 only majorPeak every 5sec_162.txt
from arduinofft.
Related Issues (20)
- Needs function to calculate octaves
- Implement C++ template HOT 5
- (improvement) use sqrtf() on ESP32 HOT 2
- Windowing / Weighing Factor HOT 1
- too much time cost for compute FFT on Esp32-C3 HOT 6
- Weird results while imag input other than 0 at example FFT_1 HOT 2
- I thought I was nearly there but can't quite get it over the line. HOT 5
- Updating Documentation and Examples HOT 1
- Performance++ HOT 10
- Needed FFT real time example HOT 1
- average FFT result HOT 1
- calc complex amplitude for only specific frequencies HOT 1
- What is the relation of the calculated magnitude to the original signal
- Windowing compensation factors HOT 1
- First two bins 0 Hz and 62.5 Hz always an order of magnitude larger than all other bins HOT 3
- Inverse function does not work correctly HOT 1
- FFT Uncertainty HOT 1
- Issue with library dictionary HOT 1
- Cannot detect frequency from sound sensor in v2 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinofft.