1

I'm reading data from the microphone and want to perform some analysis on it. I'm attempting to generate a spectrum analyser something like this:

Spectrum Analyser

What I have at the moment is this:

Input from microphone

My understanding is that I need to perform a Fourier analysis - a Fast Fourier Transform ? - to extract the component frequencies and their amplitudes.

Can someone confirm my understanding is correct and exactly what type of Fourier transform I need to apply?

At the moment, I'm getting frames containing 4k samples from the mic (using NAudio). The buffer I've got is 16bits/sample (Signed Short). For reference, the above plot shows approx half a frame

I'm coding in VB so any .Net libraries/examples (preferably on NuGet) would be of most use. I believe implementations vary considerably so the less I have to massage my data, the better.

Basic
  • 26,321
  • 24
  • 115
  • 201
  • 1
    Numerous duplicates, e.g. [Spectrogram and what it is](http://stackoverflow.com/questions/8781556/spectrogram-and-what-it-is), [Spectrogram C++ library](http://stackoverflow.com/questions/2133651/spectrogram-c-library), [Sound spectrogram](http://stackoverflow.com/questions/5730778/sound-spectrogram), [Audio spectrum analysis using FFT algorithm in Java](http://stackoverflow.com/questions/6627288/audio-spectrum-analysis-using-fft-algorithm-in-java/6633679#6633679), etc - try searching for "spectrogram". – Paul R May 02 '12 at 07:02
  • @Paul R - I disagree. The first link is merely describing a spectrogram and the others provide only very high level overviews of the steps for a FFT - Specifically, how is the data windowed and the bits reordered? Why FFTW over Kiss FFT? etc... There may duplicates out there but I don't think any of those is it – Basic May 02 '12 at 09:13
  • Please search for "fft" and "spectrogram" on SO and read some of the previous answers - all your questions have already been answered numerous times, by myself and others - you might also want to take a look at http://DSP.stackexchange.com – Paul R May 02 '12 at 09:23
  • @Paul thanks for the DSP link - I hadn't seen that on A51 – Basic May 02 '12 at 10:24

1 Answers1

2

The top plot is that of a spectrograph, where each vertical time line is colored based on the magnitudes of the result from an FFT (likely windowed) of a slice in time (possibly overlapped) of the input waveform. The number of vertical points to plot (the frequency resolution) is related to the length of the FFT. Almost any FFT will do. If you use the most common complex-to-complex FFT, just set the imaginary portion of each complex input sample to zero, copy a slice in time of samples of your input waveform to the "real" part, FFT, and take the magnitude or log magnitude of each complex result bin, then map these values to colors per your preference.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Thanks for replying - I understand the principles behind plotting the spectrograph, it's the application of the FFT that I haven't done before. Which is the "most common complex-complex FFT"? Are you speaking generally or is there a standard implementation? I've tried Accord.Audio but the FFT implementation is incomplete. The DirectX implementation makes assumptions invalid in my case (eg using DX to grab the input buffer)/ Mathnet seems to be missing the `Mathnet.numerics.Transofrmations` namespace... – Basic May 02 '12 at 06:57
  • If you can't find a working FFT in some library, there are hundreds of DSP textbooks and websites with example radix-2 FFTs (many including derivation). It's less than 1 page of code that can be translated to almost any computer language. – hotpaw2 May 02 '12 at 08:29
  • Thanks - radix-2 might've been the hint I was after. I'll do some reading – Basic May 02 '12 at 08:50