24

For my current project in C++ / Qt I need a library (LGPL is preferred) which can calculate a spectrogram from a signal ( basically an array of doubles ). I already use Qwt for the GUI part.

Any suggestions? Thanks.

gregseth
  • 12,952
  • 15
  • 63
  • 96
  • LGPL because you don't want to release source code? I know FFTW libraries can be used under alternative licence than the GPL version. – petantik Jan 25 '10 at 16:56
  • try to search on sourceforge site something about "digital signal processing". AFAIK on that site was some libraries.. – cybevnm Jan 26 '10 at 10:05
  • @gregseth, Did you finish this project? I have to do the same project and calculate a spectrogram from an array of doubles. I don't know how to start. Could you give me some hints. Merci – Jack Aug 14 '15 at 13:17
  • OpenCv is really nice library for that purposes. – Logman Aug 18 '15 at 00:31

4 Answers4

20

It would be fairly easy to put together your own spectrogram. The steps are:

  1. window function (fairly trivial, e.g. Hanning)
  2. FFT (FFTW would be a good choice but if licensing is an issue then go for Kiss FFT or similar)
  3. calculate log magnitude of frequency domain components (trivial: log(sqrt(re * re + im * im))
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 3
    Since log(sqrt(x)) = (1/2)log(x), you can make it run faster without sqrt() – DarenW Feb 11 '10 at 04:26
  • 2
    @DarenW -- indeed - since we are typically working with dB then instead of doing 20*log10(sqrt(x)) we can just do 10*log10(x). – Paul R Feb 11 '10 at 10:21
  • @PaulR , Could you please explain a bit more then how should I plot this data ? I mean I have followed your steps but now I am stuck? How do I plot this data ? I know spectrogram has frequency on Y-axis and time on X-Axis and Amplitude is shown by the intensity of color, but how do I plot it after getting step 3. – Khubaib Ahmad Apr 13 '20 at 13:32
  • 1
    @KhubaibAhmad: the answer to that would be specific to whatever OS, programming language, and graphics API you are using. But essentially you just want a suitable colour palette and then map your magnitudes to indices in the palette. – Paul R Apr 13 '20 at 16:07
12

"How do I create a frequency vs time plot?" lists several libraries, each of which can calculate a spectrogram from a signal.

Copied and pasted from my own answer:

Some source code to generate spectrograms / waterfall plots from audio data:

Image to Spectrogram goes in the reverse direction from the above utilities.

Community
  • 1
  • 1
David Cary
  • 5,250
  • 6
  • 53
  • 66
1

you could use fftw (fftw.org) to calculate the spectrogram, you would still need to plot the data, but that should not be a problem

hlovdal
  • 26,565
  • 10
  • 94
  • 165
ted
  • 4,791
  • 5
  • 38
  • 84
1

You can use FFT code from here. It uses C++ template metaprogramming for efficiency. The full source is provided by the author here.

It was suggested to include this code into Eigen for its use of templated (type friendly) code.

alle_meije
  • 2,424
  • 1
  • 19
  • 40