Beruflich Dokumente
Kultur Dokumente
ECE 515 FL
ACTIVITY No. 4
AUDIO SYNTHESIS
SUBMITTED BY:
ACANTILADO, Michelle Charmaine Y.
OCAMPO, Cyrus Eurl L.
ECE 515FL 7:30 10:30 T H306
SUBMITTED TO:
ENGR. JACQUELINE C. FLORES
05 October 2017
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
Activity No. 4
Audio Synthesis Using SCILAB
I. OBJECTIVES
II. BACKGROUND
Audio or sound synthesis is the technique of generating sound, using electronic hardware
or software, from scratch. The most common use of audio synthesis is musical, where electronic
instruments are used to generate sound similar to a wide array of musical instruments. Audio
synthesis has many applications such as generation of unique sounds that are difficult to produce
acoustically, recreation of real-world instruments and sounds, and generation of ideal test signals.
Audio signal synthesis involves the use of computational algorithms to compute the samples of a
signal, at a specified sampling frequency, based on their mathematical models. Then, the samples
are sent as input to a DAC to produce the audio signal.
Generally, the samples are computed by evaluating a continuous-time model of the signal
at instants of time corresponding to the sampling points. For example, the equation for the
instantaneous values of a pure tone with a frequency of 10Hz and an amplitude of 1 volt is
x(t) = sin(2ft) = sin(20t). For a sampling frequency Fs=100 samples per second, the samples are
taken at 10ms intervals. Assuming the sampling starts at t=0, then the sampling instants would be
at 0, 10ms, 20ms, 30ms and so on. Thus, to generate the samples of the tone, the equation for x(t)
is evaluated at the sampling instants.
When using Scilab, the samples should have values between -1 and 1 to avoid signal
clipping that results to distorted reproduction.
SLU ECE 2
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
Understand and then execute the following Scilab programs that synthesize some common
signals.
1. Tone Generation
The mathematical model for a tone is x(t) = Asin(2ft), where A is the amplitude or peak
value and f is the frequency in Hz.
To generate a 250Hz tone of 3 seconds duration
Fs=22050; //Fs - sampling frequency
f=250; //f - signal frequency;
t=0:1/Fs:3; //Generate the values for time t for 3 seconds
sine=sin(2*%pi*f*t); //Compute the samples for the 250Hz tone
playsnd(sine,Fs); //playback the 500Hz tone
SLU ECE 3
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
Fs=11025;
f=500; //f -pitch of the bell sound;
t=0:1/Fs:1;
bell=exp(-25*t).*sin(2*%pi*f*t); //Generate the samples for the bell sound
clf;plot2d(t,bell);xgrid; //Plot the waveform of the bell sound
playsnd(bell,Fs); //Playback the bell sound
SLU ECE 4
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
SLU ECE 5
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
The following SCILAB function generates the samples of the triangular wave given the
amplitude A, fundamental frequency f (in Hz), the sampling frequency Fs (in samples/second),
and the duration tdur of the triangular wave.
function [x]=trigen(A,f,Fs,tdur)
//Function that generates a triangular waveform
//where: A - amplitude
// f - fundamental frequency
// Fs - sampling frequency
// tdur - time duration
T=1/f; // T - period of the triangular wave
x=[];
for t=0:1/Fs:tdur
tcor = t- floor(t/T)*T; //reflect the time t to an equivalent time between 0 and T
if tcor >= 0 & tcor < (T/2) then
x_temp = -A +(4*A/T)*tcor;
SLU ECE 6
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
end;
if tcor >= (T/2) & tcor <T then
x_temp = 3*A + (4*A/T)*tcor;
end
x = [x, x_temp];
end;
endfunction;
To generate a 500Hz triangular wave with amplitude values varying from -0,5 to 0.5
and for a duration of 5 seconds, the following command lines are used
x=trigen(0.5,500,8000,5);
playsnd(x,8000);
1. Open and run the Scilab program music_player_demo.sce. Understand the program. Edit the
program to synthesize and playback the musical piece Sonatina by Theodore Latour. (You
may have to research on how to read musical pieces to determine the notes!). The playback
should be in stereo such that the melody part is played as the right channel signal and the bass
part is played as the left channel signal. Save the SCILAB program as Sonatina_stereo.sce.
SLU ECE 7
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
dol w so q
sol q fa q
fal q mi q
sol q so q
fal q fa q
sol q mi q
fal q re q
mil q fa q
rel q mi q
dol w re q
mil w do h
sol h rest h];
fal h
mil w [m,n]=size(music);
rel w tune=[];
dol w for k=1:m
f=music(k,1);
td=music(k,2);
sol h tune=[tune, note_gen(f,td,Fs)];
sol h end;
dol h treble=tune;
rest h];
[m,n]=size(music); playsnd([bass;treble],Fs);
tune=[];
for k=1:m
f=music(k,1);
td=music(k,2);
tune=[tune, note_gen(f,td,Fs)];
end;
bass=tune;
2. Revise the program in (1) so that the musical piece is played in mono. Save the SCILAB program as
Sonatina_mono.sce.
SLU ECE 9
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
sol h mi q
fal h so q
mil w fa q
rel w mi q
dol w re q
sol q fa q
fal q mi q
sol q re q
fal q do h
sol q rest h];
fal q
mil q [m,n]=size(music);
rel q tune=[];
dol w for k=1:m
mil w f=music(k,1);
sol h td=music(k,2);
fal h tune=[tune, note_gen(f,td,Fs)];
mil w end;
rel w treble=tune;
dol w sonatina=0.5*(treble+bass);
sol h playsnd(sonatina,Fs);
sol h
dol h
rest h];
[m,n]=size(music);
tune=[];
for k=1:m
f=music(k,1);
td=music(k,2);
tune=[tune, note_gen(f,td,Fs)];
end;
bass=tune;
SLU ECE
11
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
PROGRAM:
function [x]=sawgen(A, f, Fs, tdur)
T=1/f;
x=[];
for t=0:1/Fs:tdur
tcor = t- floor(t/T)*T; if tcor >= 0 & tcor < (T/2) then
x_temp = -A + (2*A/T)*tcor;
end;
if tcor >= (T/2) & tcor <T then
x_temp = -A + (2*A/T)*tcor;
end
x = [x, x_temp];
end;
endfunction;
x=sawgen(1,250,44100,5);
wavwrite(x,44100,'C:\Users\Desktop\sawtooth')
SLU ECE
12
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
(b) Full-wave rectified sine wave with peak of 1, fundamental frequency of 250Hz, and
duration of 5 seconds. Use Fs=44100Hz. Save the audio file as FWsine.wav. Open the
audio file with Goldwave to verify the waveform, amplitude and frequency.
function [x]=FWsingen(A, f, Fs, tdur)
T=1/f;
x=[];
for t=0:1/Fs:tdur
tcor = t- floor(t/T)*T;
if tcor >= 0 & tcor < (T/2) then
(c) Square wave signal whose amplitude toggles between -1 and 1 with a fundamental
frequency of 250Hz and duration of 5 seconds. Use Fs=44100Hz. Save the audio file as
FWsine.wav. Open the audio file with Goldwave to verify the waveform, amplitude and
frequency.
Save the program as wavegen.sce.
PROGRAM:
function [x]=squaregen(A, f, Fs, tdur)
T=1/f;
x=[];
for t=0:1/Fs:tdur
tcor = t- floor(t/T)*T;
if tcor >= 0 & tcor < (T/2) then
x_temp = A;
end;
if tcor >= (T/2) & tcor <T then
x_temp = -A;
end
x = [x, x_temp];
end;
SLU ECE
13
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
endfunction;
x=squaregen(1,250,44100,5);
wavwrite(x,44100,'C:\Users\Desktop\wavegen');
4. Write a Scilab program to generate the DTMF signal corresponding to the dialed numbers
077-423-2195. For DTMF signaling, for each number dialed the sum of two tones is generated
and transmitted. The frequencies of the two tones are determined using the DTMF frequency
matrix. If the number 6 is dialed, the frequencies of the two tones are 770Hz and 1477Hz.
1209 Hz 1336 Hz 1477 Hz 1663 Hz
-------------------------------------------------
697 Hz 1 2 3 A
770 Hz 4 5 6 B
852 Hz 7 8 9 C
941 Hz * 0 # D
Use Fs=8000Hz. Save the DTMF signal as DTMF.wav. Save the program as DTMF.sce.
PROGRAM:
fl1=697; fl2=770; fl3=852; fl4=941;
fh1=1209; fh2=1336; fh3=1477; fh4=1633;
Fs=8000;
t1=0:1/Fs:0.200;
t2=0:1/Fs:0.150;
break=zeros(t2);
one= (sin(2*%pi*fl1*t1)+sin(2*%pi*fh1*t1))/2;
two= (sin(2*%pi*fl1*t1)+sin(2*%pi*fh2*t1))/2;
three=(sin(2*%pi*fl1*t1)+sin(2*%pi*fh3*t1))/2;
four= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh1*t1))/2;
five= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh2*t1))/2;
SLU ECE
14
ECE 515 FL
Digital Signal Processing Laboratory Activity 4: Audio Synthesis Using SCILAB
six= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh3*t1))/2;
seven=(sin(2*%pi*fl3*t1)+sin(2*%pi*fh1*t1))/2;
eigth=(sin(2*%pi*fl3*t1)+sin(2*%pi*fh2*t1))/2;
nine= (sin(2*%pi*fl3*t1)+sin(2*%pi*fh3*t1))/2;
zero= (sin(2*%pi*fl4*t1)+sin(2*%pi*fh1*t1))/2;
dialled_number=[break zero break seven break seven break four break two break three break two break one
break nine break five break];
playsnd(dialled_number,Fs);
wavwrite(dialled_number,Fs, D:\DSP Lab Files\DTMF.wav');
clf; plot2d(diallled_number);
V. CONCLUSION
In this activity, we have learned about the basic concepts of synthesis of audio and with these
basic concepts we are able to generate musical tunes, periodic signals and even DTMF signals using Scilab.
Using the concepts as basis we are able to create music through Scilab programming.
.
SLU ECE
15