Coder Social home page Coder Social logo

Comments (5)

DrJaymz avatar DrJaymz commented on June 29, 2024 1

micDataImag = 0; <--- duh.
micDataImag[i] = 0;

from arduinofft.

DrJaymz avatar DrJaymz commented on June 29, 2024 1

The sampling frequency is 64000hz. I am using the m5stack core 2 built in spm1423 microphone. I tried 22000, then 44100 and 48000 and at 64000 I got the best sound. My window size is 512 samples.
The microphone is a PDM microphone not PCM, but I'm told that the I2S driver interface takes care of that weird format and all I need to do is just read. I couldn't find any useable documentation on any of that - but I found a demo someone else had done also using 64000 and used the same settings. Whether or not PDM leads to different effective sample rates than PCM I have no idea. But the fundamental frequency emitted from ardiuinoFFT when I use a 1kHz tone is 1.000Khz. So - guess it must be correct.

from arduinofft.

blaz-r avatar blaz-r commented on June 29, 2024

Hello,
so with this fix, the code is working as it should now?

Also, if you are doing this in a loop, it might be worth initializing memory outside of it, so you don't allocate and free every iteration, as that is just wasting time. Also, you can use new in c++ and then delete[] to deallocate it, which is a bit nicer than malloc. Or you can init array on stack/data segment without malloc or new if you know the size beforehand, like: double data[size];

from arduinofft.

DrJaymz avatar DrJaymz commented on June 29, 2024

Well not really with that code. I found that it worked if I specified on the constructor as below but not as I showed it there;

double vReal[512];
double vImag[512];
arduinoFFT FFT = arduinoFFT(vReal, vImag, 512, 64000);

Then call:

  FFT.Compute(FFT_FORWARD);
  FFT.ComplexToMagnitude();
  double peak = FFT.MajorPeakParabola(); 

Then I get something sensible. I wasn't sure what FFT functions I needed to call before FFT.MajorPeakParabola();
But this seemed to work. No idea if I needed to remove DC or not beforehand, but I don't think it changes anything.

There were other problems with the I2S sampling. I just wanted to get to the point where the mic was being sampled via I2s continually and I could just drop in when I felt like it and grab 512 samples and get the most dominant frequency.
I have it working but its a bit messy to integrate with my existing code right now.

What I really need is a bandpass filter, which I think I will can do on the samples directly before passing into fft.

from arduinofft.

kosme avatar kosme commented on June 29, 2024

@DrJaymz, I see a problem with the setup you describe. The sampling rate should be at least twice the highest expected frequency. Since you mention that you can hear yourself speaking, I infer you are dealing with audio. Therefore, the sampling frequency should be at least 44000.

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.