Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Ads

Chapters

Chapter Contents:

Search Spectral Audio Signal Processing

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

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);


Order a Hardcopy of Spectral Audio Signal Processing

Previous: FM Synthesis
Next: Overlap-Add (OLA) STFT Processing

written by Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


No comments yet for this page


Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )