2

I'm trying to plot the spectrograms of audio samples. While I plot it using my code given below, it figures out to be weirder. However, I imported them into audacity which came out to be so nice. Suggest me the changes I need to make in order to replicate the same in python? I would like to know that is the colour map I need to use and what are the changes to be done so that I can acquire an image similar to audacity spectrograms.

Thanks in advance.

 from scipy import fft
 # other usual libraries 
 N = 8000
 K = 256
 Step = 4
 wind =  0.5*(1 -np.cos(np.array(range(K))*2*np.pi/(K-1) ))
 ffts = []
 S = data_hollow['collection_hollow'][0]
 Spectogram = []
 for j in range(int(Step*N/K)-Step):
    vec = S[int(j * K/Step) : int((j+Step) * K/Step)] * wind
    Spectogram.append(abs(fft(vec,K)[:int(K/2)]))
 Spectogram=np.asarray(Spectogram)
 plt.imshow(Spectogram.T,aspect='auto',origin='auto',cmap='spectral')
 plt.axis('off')

Python Spectogram:

enter image description here

Audacity Spectrogram:

enter image description here

satabios
  • 47
  • 11
  • "Other usual libraries" is very vague. No sure which color map audacity uses, but maybe it could help you to choose a non linear one or maybe take the logarithm of your values. – Ignacio Vergara Kausel Feb 06 '18 at 11:43
  • 2
    Apart from the colormap (and some smoothing) the images look pretty similar to me. What *similar* are you talking about exactly? You can find the available colormaps in matplotlib [here](https://matplotlib.org/examples/color/colormaps_reference.html). – MB-F Feb 06 '18 at 11:51
  • I agrree with @kazemakase , they look similar. Aside from colour maps maybe you can up your FFT size if you want it a little less pixelated. – Rampartisan Feb 06 '18 at 13:45

0 Answers0