0

I'm taking a math class that requires us to use python. But my coding skills in python are basic at best. So I need help if anyone is willing. I created this code to display the file 'onefreq.wav' and it worked great, but I need to add 2 more wav files on the same plot and I'm at a complete loss on how to do that.

from scipy import *
from matplotlib.pyplot import *
from scipy import fftpack
from scipy.io import wavfile

close('all')

fs, sig = wavfile.read('onefreq.wav')
N = sig.size
dt = 1/fs
time = arange(0, N*dt, dt)

sample_freq = fftpack.fftfreq(N, dt)
sig_fft = fftpack.fft(sig)
pidxs = where(sample_freq > 0)
freqs = sample_freq[pidxs]
power = abs(sig_fft)[pidxs]

L2sigfft = sum(power**2)/(N/2)
power = power/L2sigfft

figure(1)
semilogx(freqs,10*log10(power))
xlabel('frequency (Hz)')
ylabel('dB')
grid('on')
title('Spectrum of onefreq.wav')

0 Answers0