0

I am trying to use FFT to decode morse code, but I'm finding that when I examine the resulting frequency bin/bucket I'm interested in, the absolute value is varying quite significantly even when a constant tone is presented. This makes it impossible for me to use the rise and fall around a threshold and therefore decode audio morse. I've even tried the simple example that seems to be copied everywhere, but it also varies... I can't work out what I'm doing wrong, and my maths is not clever enough to understand all the formulas associated with FFT. I now it must be possible, but I can't find out how... can anyone help please?

  • 2
    Are you using a window function prior to the FFT ? – Paul R Apr 26 '18 at 18:27
  • Probably not, as I don't recognise the term. Basically, I'm declaring a RealDoubleFFT, reading the mic input (at 8000hz), feeding it into a buffer (after /32,768.0) in 512 chunks, and then calling .ft on the buffer. And then examining the results (in the returning buffer) at the frequency bucket associated with the tone I'm feeding to the mic – Robbie Robertson Apr 26 '18 at 18:55
  • OK - without a window function you will get all sorts of artefects in your spectrum, and in particular with regard to the amplitude of peaks with arbitrary frequency. See e.g. [this question](https://stackoverflow.com/q/7337709/253056). – Paul R Apr 26 '18 at 20:53
  • BTW, an FFT-based method is probably overkill for morse code decoding, and you'll probably need to use a lot of overlap between successive FFTs to get sufficient onset/offset resolution. – Paul R Apr 26 '18 at 20:57
  • Appreciate your help. I do have a working morse decoder that analysers the incoming audio, but I want to be able to select the desired signal from a 'waterfall' display (via fft spectrum). I have a good frequency resolution, but the magnitude of a selected bin is my problem. I'm wondering where I can find examples of how to apply windowing? – Robbie Robertson Apr 26 '18 at 21:40
  • Follow the links to window functions and spectral leakage in [my answer to the question I linked to above](https://stackoverflow.com/a/7339777/253056). Also try the search box here on StackOverflow, as this has come up many times before, so you should be able to find plenty of examples. Also read answers by [hotpaw2](https://stackoverflow.com/users/341750/hotpaw2) here on SO, as he has written morse code decoder apps or iPhone etc. – Paul R Apr 26 '18 at 21:43
  • Show your code. It is possible that you are coding the FFT input or output incorrectly. – hotpaw2 Apr 28 '18 at 14:59

1 Answers1

1

Make sure you are using the magnitude of the FFT result, not just the real or imaginary component of a complex result.

In general, when a longer constant amplitude sinusoid is fed to a series of shorter FFTs (windowed STFT), the magnitude result will only be constant if the period of the sinusoid is exactly integer periodic in the FFT length. e.g.

f_tone modulo (f_sampling_rate / FFT_length) == 0

If you are only interested in the magnitude of one selected tone frequency, the Goertzel algorithm would serve as a more efficient filter than a full FFT. And, depending on the setup and length restrictions required by your chosen FFT library, it may be easier to vary the length of a Goertzel to match the requirements for your target tone frequency, as well as the time/frequency resolution trade-off needed.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • That sounds very interesting, so maybe I could use a wide fft spectrogram to allow the user to selected the approximate frequency, then switch to Goertzel algorithm. I'll do some research on Goertzel, as I know nothing about it. Thanks. – Robbie Robertson Apr 30 '18 at 15:09