Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Matlab starter code

%% For sinusoidal modeling, additive synthesis, 
%% and noise reduction lab.
clear all;
[x,fs] = wavread('wrenpn1.wav');
x = x/max(abs(x)); sound(x,fs); nx = length(x);

%% ANALYSIS PARAMETERS
frameRate =200;  % Hz
R = floor(fs/frameRate);  
M = 2*R;  % Exact COLA not required
nFrames = floor(nx/M)*2;
N = 2^(1+floor(log2(5*R+1))); % FFT length, zero-padding by 5+

maxPeaks = 1; % Up to this many sinusoidal peaks (pure birdsong)

%% VECTOR VARIABLES DECLARATION
amps = zeros(maxPeaks,nFrames);
freqs = zeros(maxPeaks,nFrames);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ANALYSIS
%%
w = hanning(M);
for m=1:nFrames
        tt = (m-1)*R+1:(m-1)*R+M; 
        xw = w .* x(tt);
        Xw = fft(xw,N); % window phase inconsequential
        [ampsm,freqsm] = findpeaks(Xw,maxpeaks); % Write this!
        amps(:,m) = ampsm;
        freqs(:,m) = freqsm;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SYNTHESIS

y = zeros(1,(nFrames+1)*R);
for m=1:nFrames
        tt = (m-1)*R+1:(m-1)*R+R;  % Write the following too:
        [y(tt),state] = 
          additivesynth(amps(:,m),freqs(:,m),tt,state);
end
% Add a frame of silence to make sure amps ramp down to zero:
tt = nFrames*R+(1:R);
y(tt) = additivesynth(zeros(maxpeaks,1),freqs(:,nFrames),state);
y = y/max(abs(y)); sound(y,fs);


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]

``Spectral Audio Signal Processing'', by Julius O. Smith III, (March 2007 Draft).
Copyright © 2008-05-20 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA  [About the Automatic Links]