Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Activity 4:
Audio Synthesis
Submitted to:
Engr. Jacqueline Flores
Instructor
Submitted by:
DOMINGUEZ, ARRIS ADRIAN P.
IGNACIO, MELODY M.
ECE515FL 7:30-10:30 T H306
Date performed: OCTOBER 03, 2017
Date submitted: OCTOBER 05, 2017
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
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 1: ADC and DAC
SLU ECE 3
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
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 1: ADC and DAC
SLU ECE 5
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
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;
end;
if tcor >= (T/2) & tcor <T then
SLU ECE 6
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
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.
clear;clc; Fs=8000;
//FREQUENCY TABLE (in Hz)
do=261.63; dol=do/2; doh=2*do; exec('PATH\music_player_demo.sci');
re=293.67; rel=re/2; reh=2*re; exec('PATH\sonatina_bass.sci');
mi=329.63; mil=mi/2; mih=2*mi; exec('PATH\sonatina_treble.sci');
fa=349.23; fal=fa/2; fah=2*fa;
so=392; sol=so/2; soh=2*do; [m,n]=size(musict);
la=440; lal=la/2; lah=2*la; treble=[];
ti=493.9; til=ti/2; tih=2*ti; for k=1:m
rest=0; f=musict(k,1);
td=musict(k,2);
//DURATION OF NOTES (in seconds) treble=[treble, note_gen(f,td,Fs)];
w=4.00; end;
h=2.00;
q=1.00; [m,n]=size(musicb);
e=0.50; bass=[];
s=0.25; for k=1:m
f=musicb(k,1);
function x=note_gen(f, td, Fs) td=musicb(k,2);
t=0:1/Fs:td-1/Fs bass=[bass, note_gen(f,td,Fs)];
x=sin(2*%pi*f*t); end;
endfunction
tune=[bass;treble];
stacksize(10^8); playsnd(tune,2*Fs);
SLU ECE 7
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
2. Revise the program in (1) so that the musical piece is played in mono. Save the SCILAB
program as Sonatina_mono.sce.
clear;clc; Fs=8000;
//FREQUENCY TABLE (in Hz)
do=261.63; dol=do/2; doh=2*do; exec('PATH\music_player_demo.sci');
re=293.67; rel=re/2; reh=2*re; exec('PATH\sonatina_bass.sci');
mi=329.63; mil=mi/2; mih=2*mi; exec('PATH\sonatina_treble.sci');
fa=349.23; fal=fa/2; fah=2*fa;
so=392; sol=so/2; soh=2*do; [m,n]=size(musict);
la=440; lal=la/2; lah=2*la; treble=[];
ti=493.9; til=ti/2; tih=2*ti; for k=1:m
rest=0; f=musict(k,1);
td=musict(k,2);
//DURATION OF NOTES (in seconds) treble=[treble, note_gen(f,td,Fs)];
w=4.00; end;
h=2.00;
q=1.00; [m,n]=size(musicb);
e=0.50; bass=[];
s=0.25; for k=1:m
f=musicb(k,1);
function x=note_gen(f, td, Fs) td=musicb(k,2);
t=0:1/Fs:td-1/Fs bass=[bass, note_gen(f,td,Fs)];
x=sin(2*%pi*f*t); end;
endfunction
tune=[bass,treble];
stacksize(10^8); playsnd(tune,2*Fs);
SLU ECE 8
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
(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.
clear;clc;clf; if x_temp<0 then
A=1;f=250;Fs=44100;tdur=5; x_temp = -x_temp;
t=0:1/Fs:1/f; end
function [x]=trigen(A, f, Fs, tdur) x = [x, x_temp];
T=1/f; end;
x=[]; endfunction;
for t=0:1/Fs:tdur
tcor = t- floor(t/T)*T; x=trigen(A,f,Fs,tdur);
x_temp =sin(500*%pi*tcor); wavwrite(x,Fs, 'PATH\FWsine.wav');playsnd(x,Fs);
(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.
clear;clc;clf; end;
A=1;f=250;Fs=44100;tdur=5; if tcor >= (T/2) & tcor <T then
t=0:1/Fs:1/f; x_temp = 1;
function [x]=trigen(A, f, Fs, tdur) end
T=1/f; x = [x, x_temp];
x=[]; end;
for t=0:1/Fs:tdur endfunction;
tcor = t- floor(t/T)*T
if tcor >= 0 & tcor < (T/2) then x=trigen(A,f,Fs,tdur);
x_temp = -1; wavwrite(x,Fs, 'PATH\FWsine.wav');playsnd(x,Fs)
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.
SLU ECE 9
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC
Use Fs=8000Hz. Save the DTMF signal as DTMF.wav. Save the program as DTMF.sce.
clear; clc; five= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh2*t1))/2;
six= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh3*t1))/2;
fl1=697; fl2=770; fl3=852; fl4=941; seven=(sin(2*%pi*fl3*t1)+sin(2*%pi*fh1*t1))/2;
fh1=1209; fh2=1336; fh3=1477; fh4=1633; eigth=(sin(2*%pi*fl3*t1)+sin(2*%pi*fh2*t1))/2;
nine= (sin(2*%pi*fl3*t1)+sin(2*%pi*fh3*t1))/2;
Fs=8000; zero= (sin(2*%pi*fl4*t1)+sin(2*%pi*fh1*t1))/2;
t1=0:1/Fs:0.200;
t2=0:1/Fs:0.150; dialed_number=[break zero break seven break seven break
break=zeros(t2); four break two break three break two break one break nine
break five break];
one= (sin(2*%pi*fl1*t1)+sin(2*%pi*fh1*t1))/2;
two= (sin(2*%pi*fl1*t1)+sin(2*%pi*fh2*t1))/2; playsnd(dialed_number,Fs);
three=(sin(2*%pi*fl1*t1)+sin(2*%pi*fh3*t1))/2; wavwrite(dialed_number,Fs,'PATH\DTMF.wav');
four= (sin(2*%pi*fl2*t1)+sin(2*%pi*fh1*t1))/2; clf; plot2d(dialed_number);
V. CONCLUSION
Based on the laboratory activities that we did, it can be concluded that there are different audio
synthesis such as tone generation, bell sound generation, ringing tone generation, random noise
generation, and periodic signal generation. Tone generation is the generation of sinewave sinewave
with A as the amplitude of the soundwave and the sound is based on the using different frequencies
as the sinewave’s frequency. The bell sound generation is using an exponentially decaying envelope
of the sinewave used as x(t) = e-ktsin(2πft), the higher the value of k the faster the bell sound fades.
The ring tone generation is composed of two sinewaves with high and low frequencies, with one
sinewave as envelope, the sinewave with the high frequency tone has the low frequency sinewave as
its envelope. The random noise generation is a set of random numbers with zero mean and rand()
function may be used to generate the random numbers. The periodic signal generation is used for the
generation of samples for any time instant and only one period.
It can also be concluded that the stated audio synthesis can be used to generate different sounds
like, musical tone, periodic signals and DTMF signals. The audio synthesis can be used for musical
tone wherein the sounds of “do re me fa so la ti doh” were generated and arranged such that it will
form a music. Audio synthesis can also be used in the generation of periodic signals such as sawtooth
periodic signal, full-wave rectified sinewave and square wave.
On the latter part of the exercises, where it was required to formulate a code for the DTMF
where sinewaves with different frequencies were combined so that different sounds were generated
when numbers zero to nine were dialed.
SLU ECE 10