2

I have a single-channel wave coming in at an 8000 Hz sampling rate.

I need to analyze frequencies that are between 5 Hz and 300 Hz in real-time, with emphasis on signals from 10 to 60 Hz.

My thought initially is to run the 8000 Hz sample into a buffer, collecting about 32000 samples. Then, run a 32000 window-sized fourier transform on it.

The reasoning here is that for lower-frequency signals, you need a larger window size (right?)

However, if I'm trying to display this signal in real-time, it seems like the AudioAnalyserNode might not be a good choice here. I know the WebAudio API would allow me to get the raw data, but ideally the AudioAnalyserNode would be able to run a new fft based on the previous 32000 samples, even if a smaller amount of samples have become newly available. At this point, it seems like the fft data is only updating once every four seconds.

Do I have to create a special "running bin" so that the display updates more frequently than once every 4 seconds? Or, what's the smallest window size I can use to still get reasonable values in this range? Is 32000 a large enough window size?

I am using the WebAudio API analyser node in javascript, but if I have to get the raw data, I'm also willing to change libraries to another one in javascript.

Brad
  • 159,648
  • 54
  • 349
  • 530
Kevin
  • 61
  • 5
  • 1
    I'm curious what your specific application is. It sounds similar to some BCI/EEG work I did awhile back, in which I found the Goertzel algorithm to be much more useful and performant for the task. – Brad Jun 12 '18 at 00:52
  • It is a BCI/EEG! But, I'm interested in a wider frequency range than traditional EEG researchers have been. Do you think a Goertzel algorithm would be able to handle 5 Hz intervals from 5 Hz to 300 Hz? (60 frequencies total). I will probably try it, i just found a javascript library that can do it, compatible with the WebAudio API: https://github.com/notthetup/goertzel-node – Kevin Jun 12 '18 at 00:54
  • 1
    No, the Goertzel algorithm's purpose was to save CPU if you only needed a couple bands. I used it for this project: https://www.youtube.com/watch?v=u5eWTEGhZlc If you actually *need* all of that data, FFT is the way to go. And, as you have noted, you do need larger window sizes since the frequencies are relatively low compared to audio. In my project, I did in fact use a rolling window if I remember correctly. – Brad Jun 12 '18 at 00:58
  • That video was so cool. My application is to build a spectrogram app for ios/android specifically for recognizing brainwaves over a dual tACS / EEG device that i built. I have spent a couple years designing some new electrodes and i want to see which of them produce the best frequencies in this range, and whether some tACS frequencies might affect brainwave recordings. When I finish it (it's open source) i will be sure to come back and link it here. – Kevin Jun 12 '18 at 01:08
  • 1
    Drop me an email some time, brad@musatcha.com. I'd love to hear more about your project. I've been thinking about rebuilding my MIDI/DMX software to work with the newer hardware available today. – Brad Jun 12 '18 at 03:52

1 Answers1

1

Using an AnalyserNode, you can call getFloatFrequencyData as often as you like. This will return the FFT of the last fftSize samples. These get smoothed together. For full details, see AnalyserNode Interface

Also, the WebAudio spec allows you to construct an AudioContext with a user-selectable sample rate. You could set your sample rate to 8000 Hz. Then your FFTs can have finer resolution with less complexity.

However, I don't think any browser has implemented this capability yet.

An alternative would be to get a supported audio card that allows a sample rate of 8000 Hz and set up your system to use that as the default audio output device, Then the audio context will have a sample rate of 8000 Hz.

Raymond Toy
  • 5,490
  • 10
  • 13