# Raw speech data into spectrogram

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.

• What you need is to implement the short-time Fourier transform. – MBaz Jan 3 '17 at 17:17
• Thank you. Your hint helped me further, even understanding the principle of uncertainty.. – Thomas Riedel 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
plt.imshow(Spec.T);


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.

• Thanks a lot. You are probably right regarding using a scripting language, your code is very compact and elegant. – Thomas Riedel Jan 4 '17 at 9:31
• 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. – Maximilian Matthé Jan 4 '17 at 9:42