Exemple #1
0
    peaker = loudia.PeakDetectionComplex(
        maxPeakCount, loudia.PeakDetectionComplex.BYMAGNITUDE, minPeakWidth)
    peakInterp = loudia.PeakInterpolationComplex()
    tracker = loudia.PeakTracking(maxTrajCount, maxFreqBinChange, silentFrames)
    filt = loudia.BandFilter()

trajsLocs = []
trajsMags = []
specs = []
filtereds = []

for frame in stream:
    samples = frame
    fft = ffter.process(windower.process(frame))[0, :]
    spec = loudia.magToDb(abs(fft))[0, :plotSize]

    if set(['phase', 'peak_phases']) | all_processes:
        phase = scipy.angle(fft)

    if set(['peak_mags', 'peak_phases']) | all_processes:

        peakLocs, peakMags, peakPhases = peaker.process(fft)

        peakiLocs, peakiMags, peakiPhases = peakInterp.process(
            fft, peakLocs, peakMags, peakPhases)

        trajLocs, trajMags = tracker.process(fft, peakiLocs, peakiMags)

        filtered = scipy.reshape(samples, (samples.shape[0], 1))
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.plot(w[npoints/2:], loudia.magToDb(abs(d[npoints/2:,:])), c = 'black')

pylab.hold(True)

suma = abs(d[npoints/2:,:]).sum(axis=1)
suma.resize((suma.shape[0], 1))
pylab.plot(w[npoints/2:], loudia.magToDb(suma), c = 'red')

ax = pylab.gca()

# Show half of the spectrum
ax.set_xlim([0, scipy.pi])

# Set the ticks units to radians per second
Exemple #3
0
#!/usr/bin/env python

import loudia
import scipy
import scipy.signal

# Test the magToDb <-> dbToMag
i = scipy.arange(1, 7, dtype = 'f4')
a = loudia.magToDb(i)
o = loudia.dbToMag(a)

print 'magToDb/dbToMag:', scipy.allclose(i, o)

# Test the transform of windows
transf = loudia.hammingTransform(24, 10, 1024, 4096)


# Test the poly function
a = scipy.array([1, 2, 3, 4, 5])

rr = loudia.poly( a )
rs = scipy.poly( a )

print 'poly:', scipy.allclose(rr, rs)

a = scipy.array([2, 0])

rr = loudia.poly( a )
rs = scipy.poly( a[:-1] )

print 'poly, plus zero:', scipy.allclose(rr[0,:-1], rs)
Exemple #4
0
import scipy
from common import *
import pylab
import loudia
import sys

filename = sys.argv[1]

frameSize = 256 
frameStep = 256

fftSize = frameSize * (2**3)

analysisLimit = 1000.0

plotSize = fftSize / 4

stream, sampleRate, nframes, nchannels, loader = get_framer_audio(filename, frameSize, frameStep)

windower = loudia.Window( frameSize, loudia.Window.HAMMING )
ffter = loudia.FFT( fftSize )

pylab.figure()
for ind, frame in enumerate(stream):
    if ind == 34:
        fft = ffter.process( windower.process( frame ) )
        spec =  loudia.magToDb( abs( fft ) )

        pylab.plot( spec[0, :plotSize] )
        pylab.show()
Exemple #5
0
    peaker = loudia.PeakDetectionComplex( maxPeakCount, loudia.PeakDetectionComplex.BYMAGNITUDE, minPeakWidth )
    peakInterp = loudia.PeakInterpolationComplex( )
    tracker = loudia.PeakTracking( maxTrajCount, maxFreqBinChange, silentFrames )
    peakSynth = loudia.PeakSynthesize( frameSize/6, fftSize, windowType )

trajsLocs = []
trajsMags = []
specs = []
specsSynth = []
specsResid = []
specsMagsResid = []

for frame in stream:
    samples = frame
    fft = ffter.process( windower.process( frame ) )[0, :plotSize]
    spec =  loudia.magToDb( abs( fft ) )[0, :plotSize]

    if set(['phase', 'peak_phases']) | all_processes:
        phase =  scipy.angle( fft )

    if set(['peak_mags', 'peak_phases']) | all_processes:
        fft = scipy.reshape(fft, (1, plotSize))

        peakLocs, peakMags, peakPhases =  peaker.process( fft )

        peakiLocs, peakiMags, peakiPhases = peakInterp.process( fft,
                                                               peakLocs,
                                                               peakMags,
                                                               peakPhases )
        
        trajLocs, trajMags = tracker.process( fft,
Exemple #6
0
errors = []

npoints = 1024
w = scipy.arange(0, scipy.pi, scipy.pi/(fftSize/2. + 1))
b = scipy.array([[1]])

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 )
Exemple #7
0
specs = []
wspecs = []
pitches = []
saliencies = []

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))
    spec = loudia.magToDb(abs(fft))

    wspec = whitening.process(spec)
    pitch, saliency = pitchACF.process(wspec)

    if interactivePlot:
        pylab.subplot(211)
        pylab.hold(False)
        pylab.plot(wspec[0, :plotSize])

        acorred = acorr.process(wspec)

        pylab.subplot(212)
        pylab.hold(False)
        pylab.plot(acorred[0, :plotSize], label='Noise Suppressed Spectrum')
        pylab.hold(True)
saliencies = []
freqss = []

frameNumber = 200

if interactivePlot:
    pylab.ion()
    pylab.figure()
    pylab.title('Interactive plot of the frequency likelihood')
    pylab.gca().set_ylim([-100, 40])
    pylab.gca().set_autoscale_on(False)
    
for frame in stream:
    samples = frame
    fft = ffter.process( windower.process( frame ) )
    spec =  loudia.magToDb( abs( fft ) )
    
    wspec = whitening.process( spec )
    #wspec = spec
    pitch, saliency, freqs = pitchInverseProblem.process( spec )

    frameNumber -= 1
    
    if interactivePlot:
        if frameNumber == 0:
            maxFreq = freqs[0,:].argmax()
            
            pylab.subplot(211)
            pylab.hold(True)
            pylab.plot( spec[0, :plotSize] )
            pylab.plot(loudia.magToDb(a)[:, maxFreq] + 40)
wspecs = []
pitches = []
saliencies = []
freqss = []

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:
    samples = frame
    fft = ffter.process( windower.process( frame ) )[0, :plotSize]
    spec =  loudia.magToDb( abs( fft ) )[0, :plotSize]
    
    wspec = whitening.process( spec )
    pitch, saliency, freqs = pitchInverseProblem.process( wspec )
    
    if interactivePlot:
        pylab.subplot(211)
        pylab.hold(False)
        pylab.plot( wspec[0, :plotSize] )

        pylab.subplot(212)
        pylab.hold(False)
        pylab.plot(freqs[0,:plotSize], label = 'Noise Suppressed Spectrum')
        #pylab.hold(True)
        #pylab.stem( pitch/sampleRate*fftSize, saliency )
        
Exemple #10
0
pylab.figure()
for band in range(m.bands()):
    pylab.hold(True)

    weight = m.bandWeights( band ).T
    start = starts[band]

    suma[start:start+weight.shape[1]] = suma[start:start+weight.shape[1]] + weight.T

    x = scipy.arange(start-1, start + weight.shape[1]+1)
    y = [0] + list(weight[0,:])  + [0]

    y = scipy.array(y, dtype = 'f4')
    y.resize((y.shape[0], 1))

    pylab.plot(x, loudia.magToDb(y), color = 'black')

    ax = pylab.gca()

    # Show half of the spectrum
    ax.set_xlim([0, spectrumSize / 2])
    ax.set_ylim([0.0, 1.1])

    # Set the ticks units to radians per second
    ticks = ax.get_xticks()
    ax.set_xticklabels(['%.2f' % (float(tick) / spectrumSize) for tick in ticks])

    # Set the title and labels
    pylab.title('Magnitude of the Frequency Response of a \n Mel Bands implementation')
    pylab.xlabel('Normalized Frequency')
    pylab.ylabel('|H(w)| (no unit)')
Exemple #11
0
#!/usr/bin/env python

import loudia
import scipy
import scipy.signal

# Test the magToDb <-> dbToMag
i = scipy.arange(1, 7, dtype='f4')
a = loudia.magToDb(i)
o = loudia.dbToMag(a)

print 'magToDb/dbToMag:', scipy.allclose(i, o)

# Test the transform of windows
transf = loudia.hammingTransform(24, 10, 1024, 4096)

# Test the poly function
a = scipy.array([1, 2, 3, 4, 5])

rr = loudia.poly(a)
rs = scipy.poly(a)

print 'poly:', scipy.allclose(rr, rs)

a = scipy.array([2, 0])

rr = loudia.poly(a)
rs = scipy.poly(a[:-1])

print 'poly, plus zero:', scipy.allclose(rr[0, :-1], rs)
windower = loudia.Window(frameSize, loudia.Window.HAMMING)
ffter = loudia.FFT(fftSize)
supprnoise = loudia.SpectralNoiseSuppression(fftSize, 50.0, 6000.0, sampleRate)

specs = []
results = []
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))
    spec = loudia.magToDb(abs(fft))

    noise, result = supprnoise.process(abs(fft))

    if interactivePlot:
        pylab.subplot(211)
        pylab.hold(False)

        specdb = loudia.magToDb(spec)
        noisedb = loudia.magToDb(noise)

        pylab.plot(specdb[0, :], label='Spectrum')
        pylab.hold(True)
        pylab.plot(noisedb[0, :], label='Noise')

        resultdb = loudia.magToDb(result)
Exemple #13
0
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.plot(w[npoints / 2:],
               loudia.magToDb(abs(d[npoints / 2:, :])),
               c='black')

pylab.hold(True)

suma = abs(d[npoints / 2:, :]).sum(axis=1)
suma.resize((suma.shape[0], 1))
pylab.plot(w[npoints / 2:], loudia.magToDb(suma), c='red')

ax = pylab.gca()

# Show half of the spectrum
ax.set_xlim([0, scipy.pi])
windower = loudia.Window( frameSize, loudia.Window.HAMMING )
ffter = loudia.FFT( fftSize )
supprnoise = loudia.SpectralNoiseSuppression(fftSize, 50.0, 6000.0, sampleRate)

specs = []
results = []
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 ) )
    spec =  loudia.magToDb( abs( fft ) )

    noise, result = supprnoise.process( abs( fft ) )

    if interactivePlot:
        pylab.subplot( 211 )
        pylab.hold( False )
        
        specdb = loudia.magToDb( spec )
        noisedb = loudia.magToDb( noise )

        pylab.plot( specdb[0,:], label = 'Spectrum' )
        pylab.hold( True )
        pylab.plot( noisedb[0,:], label = 'Noise' )

        resultdb = loudia.magToDb( result )
Exemple #15
0
errors = []

npoints = 1024
w = scipy.arange(0, scipy.pi, scipy.pi / (fftSize / 2. + 1))
b = scipy.array([[1]])

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,:] )
    predicted = 2*angsUnwrapped[1,:] - angsUnwrapped[0,:]

    error_linearity = abs(predicted - angsUnwrapped[2,:])

    error_slope = abs((angsUnwrapped[1,:] + 2 * scipy.pi * scipy.arange(angsUnwrapped.shape[1])/(angsUnwrapped.shape[1]-1) * miniHopSize/2.0) - angsUnwrapped[2,:]) % (2*scipy.pi)

    error_linearity = mapError(error_linearity)
    error_slope = mapError(error_slope)

    errors.append(error_linearity + error_slope)

    # The prediction error will be the inverse of the sinusoidity
    if frameCount == 40:
        pylab.figure()
        pylab.subplot(311)
        pylab.plot(loudia.magToDb(cAbs)[0, :plotSize])
        pylab.subplot(312)
        pylab.plot(angsUnwrapped[-1, :plotSize])
        pylab.subplot(313)
        pylab.plot(error_linearity[:plotSize], label='linearity')
        pylab.hold(True)
        pylab.plot(error_slope[:plotSize], label='slope', c='g')

    frameCount += 1

    cursor += hopSize

errors = scipy.array( errors )

import numpy
def smooth(x,window_len=11,window='hanning'):