Exemple #1
0
import numpy as np
import matplotlib.pyplot as plt
lap("Import")

# Load and do basic AR to reconstruct the spectrum
pcm = ssp.PulseCodeModulation()
wav = pcm.WavSource(file)
print("File:", file, "rate:", pcm.rate, "size:", wav.size)
if ssp.parameter("ZF", 0) == 1:
    wav = ssp.ZeroFilter(wav)
f = ssp.Frame(wav, size=256, period=128)
f = ssp.Window(f, np.hanning(256))
print("frame:", f.shape[0], "x", f.shape[1])
lap("Frame")
e = ssp.Energy(f)
p = ssp.Periodogram(f)
lap("Periodogram")
order = pcm.speech_ar_order()
a = ssp.Autocorrelation(f)
a, g = ssp.ARLevinson(a, order)
lap("Levinson")
ls = ssp.ARSpectrum(a, g, nSpec=128)
lap("Spectrum")

# Now do some esoteric AR
t = ssp.parameter('AR', 'matrix')
if t == 'matrix':
    wa, wg = ssp.ARMatrix(f, order, method=ssp.parameter('Method', 'matrix'))
if t == 'arwarp':
    wa, wg = ssp.ARAllPassWarp(a, g, alpha=ssp.mel[pcm.rate])
elif t == 'acwarp':
Exemple #2
0
import numpy as np

# Load and process
pcm = ssp.PulseCodeModulation()
a = pcm.WavSource(file)
if (ssp.parameter('Pre', None)):
    a = ssp.ZeroFilter(a)
framePeriod = pcm.seconds_to_period(0.01)
frameSize = pcm.seconds_to_period(0.02, 'atleast')
f = ssp.Frame(a, size=frameSize, period=framePeriod)
w = ssp.nuttall(frameSize+1)
w = np.delete(w, -1)
wf = ssp.Window(f, w)
type = ssp.parameter('Type', 'psd')
if type == 'psd':
    p = ssp.Periodogram(wf)
    p = p[:,:p.shape[1]/2+1]
elif type == 'ar':
    a = ssp.Autocorrelation(wf)
    a, g = ssp.ARLevinson(a, pcm.speech_ar_order())
    p = ssp.ARSpectrum(a, g, nSpec=128)
elif type == 'snr':
    p = ssp.Periodogram(wf)
    n = ssp.Noise(p)
    p = ssp.SNRSpectrum(p, n)
    p = p[:,:p.shape[1]/2+1]

# Draw it
fig = ssp.Figure(2, 1)
p1 = fig.SpectrumPlot(p, pcm)
p2 = fig.EnergyPlot(f, pcm)