Digital Signal Processing Reference
In-Depth Information
Programmbeispiel 2-2 Audiosignal „Prélude“
% Audio signal prelude by Marc-Antoine Charpentier (1634-1704)
% dsplab2_3.m * mw * 19Aug2010
A = 440;
% pitch in Hz
Dh = A*2^(5/12);
% high
C = A*2^(3/12); B = A*2^(2/12); G = A*2^(-2/12);
Fis = A*2^(-3/12); E = A*2^(-5/12); D = A*2^(-7/12);
pitch = [D G G A B G Dh B B C Dh C B C Dh A G A B A];
duration = [2 2 1 1 2 2 4 3 1 2 1 1 1 1 2 1 1 1 1 2];
Sc = 1/4;
% time scaling
fs = 8000;
% sampling frequency
audiosig = [];
% define variable for audio signal
for k = 1:length(pitch)
% for loop
L = Sc*fs*duration(k);
% number of samples per tone
n = 0:L-1;
% normalized time
w = (2*pi/fs)*pitch(k);
% normalized radian frequency
s = sin(w*n);
% sinusoidal tone
audiosig = [audiosig s];
% concatenate audio signal
end
soundsc(audiosig,fs,16);
% sound card output
Programmbeispiel 2-3 ADSR-Profil
function env = adsr_profile(N,tA,tD,tS,ED,ES)
% dsp laboratory - assignment 2
% computation of envelope signal with ADSR profile for shaping pure
tones
% env = adsr_profile(N,tA,tD,tS,EA,ED,ES)
% N : number of signal samples (duration)
% tA : relative duration of attack phase
% tD : relative duration of delay phase, tD - tA
% tS : relative duration of sustain phase, tS - tD
% ED : relative amplitude of profile at time tD
% ES : relative amplitude of profile at time tS
% env : envelope signal with ADSR profile
% adsr_profile.m * mw * 19Aug2010
env = zeros(1,N); % allocate memory for envelope signal
% Attack phase
NA = floor(tA*N)+1; % number of samples in attack phase
A = 1/(NA-1); % envelope increment
for k = 2:NA
env(k) = env(k-1) + A;
end
% Delay phase
ND = floor((tD-tA)*N); % number of samples in delay phase
D = (1-ED)/ND; % envelope decrement
for k = NA+1:NA+ND
env(k) = env(k-1) - D;
end
% Sustain phase
NS = floor((tS-tD)*N); % number of samples in sustain phase
S = (ED-ES)/NS; % envelope decrement
for k = NA+ND+1:NA+ND+NS
env(k) = env(k-1) - S;
end
Search WWH ::




Custom Search