I am using Delphi trying to make a very simple speech recognition system. The system collects raw data well, but I have a hard time turning the data into a spectrogram:

The system collects an array with $1024$ integer values for each $100$ ms.

I try to FFT this array into $(R, I)$, and plot time on the $x$-axis and $\sqrt{R^2 + I^2}$ on the $y$-axis, but no frequency bands appears.

Does anyone know what I should do in stead? Source code in any language is very welcome.

  • $\begingroup$ What you need is to implement the short-time Fourier transform. $\endgroup$
    – MBaz
    Jan 3 '17 at 17:17
  • $\begingroup$ Thank you. Your hint helped me further, even understanding the principle of uncertainty.. $\endgroup$ Jan 4 '17 at 9:27

In principle what you describe is reasonable. Here's an example in Python that implements your idea:

Fs = 44100
T = 100
t = np.arange(0, T, 1/Fs)
N = 1024
t = t[:N*int(len(t)/N)]

f = 0.7*t*t+2000

signal = np.sin(2*np.pi*f*t)  # generate some signal for our analysis

chunks = signal.reshape((-1, N))   # create chunks of the signal of length N
C = np.fft.fft(chunks, axis=1)     # perform FFT of each chunk
C = C[:, :N//2] # keep only positive frequencies

Spec = 10*np.log10(abs(C*C))      # draw the spectrum

enter image description here

I can only recommend to try out your DSP algorithms not in Delphi but in some scripting language like Python or Matlab, because you are much more flexible in your analysis and can try out new ideas much more quickly.

To improve the spectrum image, you can use a different window function (i.e. no rectangular window as I use here) and overlap the different chunks. Then, it would be closer to the short-time Fourier transform as noted by MBaz.

  • $\begingroup$ Thanks a lot. You are probably right regarding using a scripting language, your code is very compact and elegant. $\endgroup$ Jan 4 '17 at 9:31
  • $\begingroup$ Thanks! In case you like the answer or are satisfied with the solution, you might consider upvoting or clicking the checkmark to show your problem is solved. $\endgroup$ Jan 4 '17 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.