def plot_freqz(b, a, w=None, npoints=None, title='', db=False, createFigure=True, label=''): # Create the omega array if necessary if npoints is None: npoints = 1000 if w is None: w = scipy.arange(-scipy.pi, scipy.pi, 2 * scipy.pi / (npoints)) # Calculate the frequency response d = loudia.freqz(b.T, a.T, w) if db: mag = 20.0 * scipy.log10(abs(d[:, 0])) else: mag = abs(d[:, 0]) import pylab if createFigure: pylab.figure() pylab.subplot(2, 1, 1) pylab.plot(w, mag, label=label) pylab.title('%s \n Magnitude of the Frequency Response' % title) pylab.subplot(2, 1, 2) pylab.plot(w, scipy.angle(d[:, 0]), label=label) pylab.title('Angle of the Frequency Response')
def plot_freqz(b, a, w = None, npoints = None, title = '', db = False, createFigure = True, label = ''): # Create the omega array if necessary if npoints is None: npoints = 1000 if w is None: w = scipy.arange(-scipy.pi, scipy.pi, 2*scipy.pi/(npoints)) # Calculate the frequency response d = loudia.freqz(b.T, a.T, w) if db: mag = 20.0 * scipy.log10(abs(d[:,0])) else: mag = abs(d[:,0]) import pylab if createFigure: pylab.figure() pylab.subplot(2,1,1) pylab.plot(w, mag, label = label) pylab.title('%s \n Magnitude of the Frequency Response' % title) pylab.subplot(2,1,2) pylab.plot(w, scipy.angle(d[:,0]), label = label) pylab.title('Angle of the Frequency Response')
# -------------------------------------------------------- # import loudia coeffsB1 = scipy.vstack((B0, B11, B2)) / gain coeffsB2 = scipy.vstack((B0, B12, B2)) coeffsB3 = scipy.vstack((B0, B13, B2)) coeffsB4 = scipy.vstack((B0, B14, B2)) coeffsA = scipy.vstack((A0, A1, A2)) npoints = 10000 w = scipy.arange(-scipy.pi, scipy.pi, 2*scipy.pi/npoints) d1 = loudia.freqz(coeffsB1, coeffsA, w) d2 = loudia.freqz(coeffsB2, coeffsA, w) d3 = loudia.freqz(coeffsB3, coeffsA, w) d4 = loudia.freqz(coeffsB4, coeffsA, w) d = d1 * d2 * d3 * d4 # Plot the frequency response import pylab subplots = 2 if plotAngle else 1; pylab.subplot(subplots,1,1) if plotColor: pylab.plot(w[npoints/2:], loudia.magToDb(abs(d[npoints/2:,:])))
import scipy # Create the omega array npoints = 1000 w = scipy.arange(-scipy.pi, scipy.pi, 2.0 * scipy.pi / npoints) # Create the coefficients of the filter nbcoeffs = 10 b = scipy.ones((nbcoeffs, 1)) / nbcoeffs a = scipy.ones((1, 1)) print b print a print w # Calculate the frequency response d = loudia.freqz(b, a, w) # Plot the frequency response import pylab pylab.subplot(2, 1, 1) pylab.plot(w, abs(d[:, 0])) pylab.title('Magnitude of the Frequency Response') pylab.subplot(2, 1, 2) pylab.plot(w, scipy.angle(d[:, 0])) pylab.title('Angle of the Frequency Response') pylab.show()
if interactivePlot: pylab.ion() pylab.figure() pylab.title('Interactive plot of the FFT vs LPC frequency response') pylab.gca().set_ylim([-100, 40]) pylab.gca().set_autoscale_on(False) for frame in stream: fft = ffter.process( windower.process( frame ) )[0, :] spec = loudia.magToDb( abs( fft ) ) lpcCoeffs, reflection, error = lpc.process( frame ) lpcResidual = lpcr.process( frame, lpcCoeffs ) freqResp = loudia.magToDb( abs( loudia.freqz( b * scipy.sqrt( abs( error[0] ) ), lpcCoeffs.T, w ) ).T ) if interactivePlot: pylab.subplot( 211 ) pylab.hold( False ) pylab.plot( frame ) #pylab.hold( True ) #pylab.plot( lpcResidual[0,:] ) pylab.subplot( 212 ) pylab.hold( False ) pylab.plot( w, spec[0, :], label = 'FFT' ) pylab.hold( True ) pylab.plot( w, freqResp[0, :], label = 'LPC' ) specs.append( spec[0, :plotSize] )
import scipy # Create the omega array npoints = 1000 w = scipy.arange(-scipy.pi, scipy.pi, 2.0*scipy.pi/npoints) # Create the coefficients of the filter nbcoeffs = 10 b = scipy.ones((nbcoeffs, 1)) / nbcoeffs a = scipy.ones((1, 1)) print b print a print w # Calculate the frequency response d = loudia.freqz(b, a, w) # Plot the frequency response import pylab pylab.subplot(2,1,1) pylab.plot(w, abs(d[:,0])) pylab.title('Magnitude of the Frequency Response') pylab.subplot(2,1,2) pylab.plot(w, scipy.angle(d[:,0])) pylab.title('Angle of the Frequency Response') pylab.show()
gain) = filter_coeffs_gammatone(freqs, B, sampleRate) # -------------------------------------------------------- # import loudia coeffsB1 = scipy.vstack((B0, B11, B2)) / gain coeffsB2 = scipy.vstack((B0, B12, B2)) coeffsB3 = scipy.vstack((B0, B13, B2)) coeffsB4 = scipy.vstack((B0, B14, B2)) coeffsA = scipy.vstack((A0, A1, A2)) npoints = 10000 w = scipy.arange(-scipy.pi, scipy.pi, 2 * scipy.pi / npoints) d1 = loudia.freqz(coeffsB1, coeffsA, w) d2 = loudia.freqz(coeffsB2, coeffsA, w) d3 = loudia.freqz(coeffsB3, coeffsA, w) d4 = loudia.freqz(coeffsB4, coeffsA, w) d = d1 * d2 * d3 * d4 # Plot the frequency response import pylab subplots = 2 if plotAngle else 1 pylab.subplot(subplots, 1, 1) if plotColor: pylab.plot(w[npoints / 2:], loudia.magToDb(abs(d[npoints / 2:, :]))) else:
pylab.ion() pylab.figure() pylab.title('Interactive plot of the FFT vs LPC frequency response') pylab.gca().set_ylim([-100, 40]) pylab.gca().set_autoscale_on(False) for frame in stream: fft = ffter.process(windower.process(frame))[0, :] spec = loudia.magToDb(abs(fft)) lpcCoeffs, reflection, error = lpc.process(frame) lpcResidual = lpcr.process(frame, lpcCoeffs) freqResp = loudia.magToDb( abs(loudia.freqz(b * scipy.sqrt(abs(error[0])), lpcCoeffs.T, w)).T) if interactivePlot: pylab.subplot(211) pylab.hold(False) pylab.plot(frame) #pylab.hold( True ) #pylab.plot( lpcResidual[0,:] ) pylab.subplot(212) pylab.hold(False) pylab.plot(w, spec[0, :], label='FFT') pylab.hold(True) pylab.plot(w, freqResp[0, :], label='LPC') specs.append(spec[0, :plotSize])