Clear[spectrogram, Hanning, Hamming, Rectangular]
Rectangular = (Function[{n, N}, 1]);
Hanning = (0.5 (1 - Cos[2 \[Pi] #1 / #2]) &);
Hamming = ((0.08 + 0.46 (1 - Cos[2 \[Pi] #1/#2])) &);
spectrogram[x_List, npts_Integer, rate_, lag_: 0, w_: Rectangular] :=
Block[{window = Array[w[#, npts] &, npts]},
Abs[Fourier[#*window, FourierParameters -> {1, -1}]][[
Range[1, Min[npts/2, rate/2]] ]] & /@
Partition[x, npts, npts - lag, {1, 1}, 0] // Transpose
]