I am calculating spectrogram of a audio file of 36 second using the following code snippet:
window = np.hamming(window_width)
length = signal.size
count = 0
for i in range(0, length-window_width, window_overlap):
cur_frame = signal[i:i+window_width]
window_frame = cur_frame*window
spec = sp.fft(window_frame)
if(i == 0):
width = int(length/window_overlap)
height = int(spec.size)
specgram = np.empty([height, width])
energy = np.empty(width)
energy[count] = getEnergy(spec)
for j in range(height):
val = spec[j]
specgram[j, count] = math.sqrt(math.pow(val.real, 2)+math.pow(val.imag, 2))
count = count+1
print abs(specgram).max()
I get a ndarray of shape (4000L, 1008L)
but when i calculate spectrogram using Pylab:
Pxx, freqs, bins, im=pylab.specgram(sound_info, Fs=frame_rate)
I get ndarray of dimension: (129L, 125999L).
Actually I need to get the spectrogram which is the dimension of (frequency,nframes)
Thank you in advance.