Joe
Joe

Reputation: 395

Get FFT waveform in python to match Adobe Audition Frequency Analysis

For the wav file found here, I wanted to match the spectrum shown in Adobe Audition:

enter image description here

Currently, with the code I use:

import scipy.io.wavfile as wavfile
import scipy
import scipy.fftpack
import numpy as np
from matplotlib import pyplot as plt


file1 = (r'G:/file1.wav')

fs_rate, signal = wavfile.read(file1)
print ("Frequency sampling", fs_rate)
l_audio = len(signal.shape)
print ("Channels", l_audio)
if l_audio == 2:
    signal = signal.sum(axis=1) / 2
N = signal.shape[0]
print ("Complete Samplings N", N)
secs = N / float(fs_rate)
print ("secs", secs)
Ts = 1.0/fs_rate # sampling interval in time
print ("Timestep between samples Ts", Ts)
t = np.arange(0, secs, Ts) # time vector as scipy arange field / numpy.ndarray
FFT = scipy.fftpack.fft(signal)
FFT_side = FFT[range(N//2)] # one side FFT range
freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])
fft_freqs = np.array(freqs)
freqs_side = freqs[range(N//2)] # one side frequency range
fft_freqs_side = np.array(freqs_side)

plt.plot(freqs_side/1000, 2.0/N * abs(FFT_side))
plt.xlabel('Frequency (kHz)')
plt.ylabel('Count single-sided')

plt.show()

I get this plot:

enter image description here

Can you help me to get the plot that is just like that shown in the Adobe Audition Frequency Analysis window?

Any help will be greatly appreciated!

Upvotes: 0

Views: 493

Answers (1)

Woodford
Woodford

Reputation: 4439

Using the example from scipy.signal.welch:

fs_rate, signal = wavfile.read(file1)
f, Pxx_den = scipy.signal.welch(signal, fs_rate, nperseg=512, window='blackmanharris')
plt.semilogy(f, Pxx_den)
plt.semilogx(f, Pxx_den)
plt.xlabel('frequency [Hz]')
plt.show()

The y-axis units are off, but this should get you started.

enter image description here

Upvotes: 2

Related Questions