Coder Social home page Coder Social logo

Comments (24)

hp2020 avatar hp2020 commented on May 27, 2024 1

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.

hp2020 avatar hp2020 commented on May 27, 2024 1

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.

kosme avatar kosme commented on May 27, 2024

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.

kosme avatar kosme commented on May 27, 2024

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

kosme avatar kosme commented on May 27, 2024

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.

hp2020 avatar hp2020 commented on May 27, 2024

With the workaround it works perfectly, thank you for the very competent and quick problem solving.

from arduinofft.

kosme avatar kosme commented on May 27, 2024

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.

softhack007 avatar softhack007 commented on May 27, 2024

// The DC offset on the signal produces a spike on position 0 that should be
// eliminated to avoid issues.
vReal[0] = 0;

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

kosme avatar kosme commented on May 27, 2024

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

hp2020 avatar hp2020 commented on May 27, 2024

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.

kosme avatar kosme commented on May 27, 2024

@hp2020 I don't really understand your last comment. Could you elaborate? Which values range from 50 to 4000?

from arduinofft.

kosme avatar kosme commented on May 27, 2024

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

hp2020 avatar hp2020 commented on May 27, 2024

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.

kosme avatar kosme commented on May 27, 2024

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

kosme avatar kosme commented on May 27, 2024

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.

hp2020 avatar hp2020 commented on May 27, 2024

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.

kosme avatar kosme commented on May 27, 2024

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.

hp2020 avatar hp2020 commented on May 27, 2024

Ok, I hope this is the data you need.

Computed magnitudes_Data_Input_162.txt
Computed magnitudes_Data_Input_202.txt

from arduinofft.

kosme avatar kosme commented on May 27, 2024

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.

hp2020 avatar hp2020 commented on May 27, 2024

I didn't copy all of them but I can still add the missing ones, but they are all similar.

from arduinofft.

kosme avatar kosme commented on May 27, 2024

I need a full set to try to reproduce the problem.

from arduinofft.

hp2020 avatar hp2020 commented on May 27, 2024

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.

kosme avatar kosme commented on May 27, 2024

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.

hp2020 avatar hp2020 commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.