In [1]:
# PLCA Example
import os
import os.path
import bregman
from bregman.suite import *
In [2]:
examples_path = os.path.split(bregman.__file__)[0]+os.sep+'examples'+os.sep+'5_plca.py'
execfile(examples_path)
In [3]:
play(x) # the amen break is loaded for you
p # inspect the feature parameters
Out[3]:
In [4]:
#1. PLCA, run the following examples
#help ex_1a()
w,z,h = ex_1a(x, p, n=4)
In [ ]:
#help ex_1b()
#try the following with different values of alphaZ, alphaH, n
w,z,h = ex_1b(x, p, n=4, alphaZ=-0.01, alphaH=-0.00001)
In [5]:
#2. Shift invariant PLCA (time-shift only)
#Using a 2D basis with a 1D convolution kenel for each component
#help ex_2a()
# Try the following with different values of n and win
w,z,h = ex_2a(x, p, n=4, win=5)
imagesc(w[:,0,:]) # show first basis function
imagesc(w[:,0,:]) # show second basis function
# etc..
figure()
plot(h[0,:]) # plot first time kernel
plot(h[1,:]) # plot second time kernel
Out[5]:
In [ ]:
#help ex_2b()
# Try the following with different values of alphaZ, alphaH, win
w,z,h = ex_2b(x, p, n=10, win=5, alphaZ=-0.01, alphaH=-0.00001)
In [ ]:
#3. 2D shift-invariant PLCA, no shift in frequency
#help ex_3a
# Try the following with different values of n and win=(1,10) and (1,3)
w,z,h = ex_3a(x, p, n=4, win=(1,5))
imagesc(w[:,0,:]) # show first basis function
imagesc(h[0,:,:]) # show first 2D convolution kernel (actually 1D, no freq shif\
t)
In [6]:
#help ex_3b()
w,z,h = ex_3b(x, p, n=1, win=(24,5))
imagesc(w[:,0,:]) # show only basis function
imagesc(h[0,:,:]) # show only 2D convolution kernel (with freq shifts)
In [7]:
# 4. Doing it on a pitched example
audio_file = audio_dir+os.sep+'gmin.wav'
x, sr, fmt = wavread(audio_file)
p['nbpo'] = 36 # increase CQFT frequency resolution
w,z,h = ex_3b(x, p, n=6, win=(36,5))
imagesc(w[:,0,:]) # show only basis function
imagesc(h[0,:,:]) # show only 2D convolution kernel (with freq shifts)
# The latter is a piono roll transcription, with wrapping at the extremes of the pitch range
# So, we have essentially achived an automatic transcription.
In [6]:
# Reconstruction
F = LogFrequencySpectrum(x, **p)
X = SIPLCA2.reconstruct(w,z,h, circular=False)
F.X = X
In [7]:
x_hat = F.inverse(usewin=True)
play(balance_signal(x_hat))
In [8]:
# 5.
# For a 20s-30s piece of music of your choosing, perform a 2D shift-invariant analysis
# optimize the parameters so that your analysis "makes sense"
# Be prepared to present your analysis, and any interesting conclusions, in class. Make a 2-3 page writeup of your analysis,
# with figures.
#
# Some Ideas: finding riffs in pop music, analysis of sound objects in Musique Concrete, analysis of texture in Ligeti or Lachemann
#
In [ ]: