I have a program in MATLAB that I want to pass to Python. The problem is that I use the built-in function in it spectrogram, and although the matplotlib function specgramseems identical, I get different results when I run both.
This is the code that I ran.
MATLAB:
data = 1:999; %Dummy data. Just for testing.
Fs = 8000; % All the songs we'll be working on will be sampled at an 8KHz rate
tWindow = 64e-3; % The window must be long enough to get 64ms of the signal
NWindow = Fs*tWindow; % Number of elements the window must have
window = hamming(NWindow); % Window used in the spectrogram
NFFT = 512;
NOverlap = NWindow/2; % We want a 50% overlap
[S, F, T] = spectrogram(data, window, NOverlap, NFFT, Fs);
Python:
import numpy as np
from matplotlib import mlab
data = range(1,1000)
Fs = 8000
tWindow = 64e-3
NWindow = Fs*tWindow
window = np.hamming(NWindow)
NFFT = 512
NOverlap = NWindow/2
[s, f, t] = mlab.specgram(data, NFFT = NFFT, Fs = Fs, window = window, noverlap = NOverlap)
And this is the result that I get in both versions:
http://i.imgur.com/QSPvYsC.png
(In both programs, the variables F and T are the same)
Obviously they are different; in fact, Python execution does not even return complex numbers. What could be the problem? Is there a way to fix this, or should I use a different spectrogram function?
Thank you so much for your help.