Tuesday, October 30, 2007

Class of Oct-29

The solution to the chirp exercise and the diary are given below.
To sum up what we did:
1 - described a matlab function (m-file), its input and output
parameters, comments and help, and simple way to set up default
parameter values using nargin.
2 - used the CepsAna from CATbox to demonstrate homomorphic
decomposition (source - filter) and used imagesc to display the
figures. Also showed how multiple plots can be put on one figure
using subplot command and how figure and axes properties can be
changed using set command. Printing formats were mentioned for the
print command.
3 - introduced the miditoolbox and readmidi command. Explain the
basic note matrix structure and showed how playmidi , nmat2snd and
playsound work. Mentioned some of the toolbox functions, such as KK
tonality estimation. Displaying midi can be done using pianoroll
command.
4 - Ben demonstrated some timbral transformations using Loris.

Next week we will proceed to FactorOracle and discuss projects.

---
function [x,t,fs] = chirp(f0,T,fs)
% [x,t,fs] = chirp(f0,T,fs)
% create a changing frequency sound
% f0 is a two dimensional vector of start and end frequency
% T duration in seconds
% fs is sampling frequency
% x - sound vector
% t - time vecotr

if nargin < 1
f0 = 220;
end

if nargin < 2,
T = 1;
end

if nargin < 3,
fs = 8000;
end

if length(f0) == 1,
f0 = [f0; f0];
end

dt = 1/fs;
t = [0:dt:T];

f0i = linspace(f0(1),f0(2),length(t));

% to generalize it into a breakpoint list of f0 and T.
%f0i = interp1(f0,T,t);

Theta = 2*pi*cumsum(f0i)*dt;
%Theta = 2*pi*f0i.*t; %this is the wrong way to do it.

x = sin(Theta);

----
diary

[x,fs] = wavread('svega.wav');
[C,S,E] = cepsana(x);
Warning: Function call cepsana invokes inexact match
/Users/sdubnov/Documents/Research/Computer
Audition/CATbox/Publish/CATbox v0.1/Ceps/CepsAna.m.

whos
Name Size Bytes Class

A 2x3 48 double array
C 512x608 2490368 double array
E 257x608 2500096 double array (complex)
S 257x608 2500096 double array (complex)
T 1x1 8 double array
Theta 1x16001 128008 double array
ans 1x73 146 char array
f0 1x1 8 double array
fs 1x1 8 double array
t 1x16001 128008 double array
x 156160x1 1249280 double array
x1 1x16001 128008 double array

Grand total is 828053 elements using 9124082 bytes

close all
imagesc(E)
??? Error using ==> image
Error using ==> image
Image CData can not be complex.

Error in ==> <a
href="error:/Applications/MATLAB7/toolbox/matlab/specgraph/imagesc.m,18,1">imagesc
at 18</a>
hh = image(varargin{1},'CDataMapping','scaled');

imagesc(real(E))

imagesc(log(real(E))); axis xy
figure
imagesc(log(real(S))); axis xy
figure
specgram(x)
figure
subplot(3,1,1)
specgram(x)
title('Spectrum')
subplot(3,1,2)
imagesc(log(real(S))); axis xy
title('Envelope')
subplot(3,1,3)
imagesc(log(real(E))); axis xy
title('Excitation')

t3 = title('Excitation')

t3 =

622.0006

get(t3)
BackgroundColor = none
Color = [0 0 0]
EdgeColor = none
EraseMode = normal
Editing = off
Extent = [ (1 by 4) double array]
FontAngle = normal
FontName = Helvetica
FontSize = [10]
FontUnits = points
FontWeight = normal
HorizontalAlignment = center
LineStyle = -
LineWidth = [0.5]
Margin = [2]
Position = [303.732 272.519 1.00005]
Rotation = [0]
String = Excitation
Units = data
Interpreter = tex
VerticalAlignment = bottom

BeingDeleted = off
ButtonDownFcn =
Children = []
Clipping = off
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = off
HitTest = on
Interruptible = on
Parent = [620]
Selected = off
SelectionHighlight = on
Tag =
Type = text
UIContextMenu = []
UserData = []
Visible = on

set(t3,'FontSize',16)
set(t3,'FontSize',24)

nmat = readmidi('donna.mid');
size(nmat)

ans =

4862 7


nmat(1:10,:)

ans =

Columns 1 through 5

4.0000 0.6250 1.0000 58.0000 98.0000
4.0000 0.6979 1.0000 63.0000 115.0000
4.0000 0.6042 1.0000 55.0000 127.0000
4.0104 0.6250 1.0000 44.0000 115.0000
4.0104 0.6354 1.0000 60.0000 108.0000
4.0208 0.6146 1.0000 32.0000 115.0000
4.1667 0.9375 10.0000 46.0000 83.0000
5.0625 0.2604 10.0000 42.0000 72.0000
5.7708 0.2396 10.0000 42.0000 72.0000
5.9896 0.3646 1.0000 79.0000 124.0000

Columns 6 through 7

1.0000 0.1562
1.0000 0.1745
1.0000 0.1510
1.0026 0.1562
1.0026 0.1589
1.0052 0.1536
1.0417 0.2344
1.2656 0.0651
1.4427 0.0599
1.4974 0.0911


playmidi(nmat(1:100,:))
Press space bar to listen to the MIDI file.
Close the Quicktime Player window after listening.

playmidi(nmat(1:100,:),200)
Press space bar to listen to the MIDI file.
Close the Quicktime Player window after listening.


x = nmat2snd(nmat(1:100,:));
38.15K samples
fs = 8192;
soundsc(x,fs)

diary

Thursday, October 11, 2007

Music in Matlab Oct. 8 summary

This is a summary of what we did last week...

We continued going over the slides of the Compute Audition Tutorial
and CATbox and talked about the following topics:

1. Difference between Narrow Band and Wide Band spectrograms and mentioned the Bell Labs 1939 VODER as an example of a Wide Band model with synthetic voice input.
2. Mentioned the difference between perfect reconstruction with ISTFT
and Least Square Error reconstruction with ISTFTW2 in STFT folder.
3. Mentioned briefly constant Q transform. Code can be found in ConstQ folder.
4. introduced the notion of instantaneous frequency and spoke about
the hop one trick. Code is in InstFreq folder.
5. Spoke about phase-less reconstruction and spectral-magnitude to
sound conversion. We showed 1940 Haskin's lab pattern playback and
played with Pollock picture. Code is in LSEE folder.

Reference to the theory of LSEE and phase-less reconstruction is the
Griffin and Lim paper, to be found in the CATbox/Publish/Reader
folder.

We mentioned several possible projects related to this material:
1 - Any project that ports something to Octave - may be miditoolbox...
2 - In case anyone would like to learn the theory of LSEE and better
ways of initializing phase. There are some more recent papers on that
also.
3 - Working out a meaningful way of converting images into sound (the
Pollock example).

An additional project that I did not mention in class but that could
be interesting is writing an additive resynthesis program that uses
amplitude and instantaneous frequency from instf as parameters.

In terms of Matlab skills, we mentioned the following commands:
a*b as a vector or matrix product. Requires taking care of row -
column dimensions.
a.*b as a component-wise multiplication.
gave an example of for loop

For our next class I will try to go over LPC and YASA. Those
interested should take a look at the icmc06 paper in the YASA v1.0
folder.

A copy of this email should be logged on http://musicinmatlab.blogspot.com
Please keep the address for future postings.

Shlomo