Sei sulla pagina 1di 10

Saint Louis University

School of Engineering and Architecture


Electronics Engineering

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

At the end of the activity, the student must be able to:


1. Demonstrate the concepts of audio synthesis.
2. Use audio synthesis to generate a musical tune, periodic signals, and dual-tone multi-
frequency (DTMF) signals.

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(2ft) = sin(20t). 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

III. LABORATORY ACTIVITY


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(2πft), 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
To generate tones for different musical notes
Fs=22050;
t=0:1/Fs:0.25; //Generate the values for time t
//for a duration of 0.25 seconds
//Compute the samples for each of the notes
do=sin(2*%pi*261.63*t); //frequency of note middle do is 261.63Hz
re=sin(2*%pi*293.67*t);
mi=sin(2*%pi*329.63*t);
fa=sin(2*%pi*349.23*t);
so=sin(2*%pi*392*t);
la=sin(2*%pi*440*t);
ti=sin(2*%pi*493.9*t);
doh=sin(2*%pi*523.26*t);
tune1=[do re mi fa so la ti doh]; //Put together the samples of each of the
notes
//notes to form the do-re-mi tune
playsnd(tune1,Fs); //Playback the tune

SLU ECE 3
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

2. Bell Sound Generation


The bell sound is modeled as a tone with an exponentially decaying envelope given as
x(t) = e-ktsin(2πft). The rate of decay of the exponential envelop depends on the value of k such that
a high value of k would mean a faster rate of decay and the bell sound fades faster.
To generate the bell sound

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

To generate a tune using the bell sound


Fs=22050;
t=0:1/Fs:0.25;
do=exp(-7*t).*sin(2*%pi*261.63*t);
re=exp(-7*t).*sin(2*%pi*293.67*t);
mi=exp(-7*t).*sin(2*%pi*329.63*t);
fa=exp(-7*t).*sin(2*%pi*349.23*t);
so=exp(-7*t).*sin(2*%pi*392*t);
la=exp(-7*t).*sin(2*%pi*440*t);
ti=exp(-7*t).*sin(2*%pi*493.9*t);
doh=exp(-7*t).*sin(2*%pi*523.26*t);
bell_tune1=[do re mi fa so la ti doh];
playsnd(bell_tune1,Fs);

SLU ECE 4
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

3. Ringing Tone Generation


A ringing tone is a high frequency tone with a low frequency sine wave envelope and
mathematically modeled as ring(t) = sin(2f1t)sin(2f2t), where f1 is the frequency of the envelope
and f2 is the frequency of the tone.
To generate a 3-second 500Hz ringing tone
Fs=22050;
t=1:1/Fs:3;
ring=sin(2*%pi*10*t).*sin(2*%pi*500*t);
clf;plot2d(t,bell);xgrid;
playsnd(ring, Fs);

4. Random Noise Generation


Random noise is mathematically modeled as a set of random numbers with zero mean. The
built-in function rand( ) may be used to generate the random numbers.
To generate a 3-second random noise
Fs=22050;
noise=2*rand(1,3*Fs)-1; //Generate a row vector of random numbers whose
//values vary between -1 and 1
playsnd(noise, Fs);
To generate a noise contaminated tone, generate separately the samples for the tone and
the samples for the random noise. Then add the samples array-wise.
t=0:1/Fs:3; //Generate the samples for a 3-second
tone=sin(2*%pi*250*t); //250Hz tone
noise=2*rand(1,length(t))-1; //Generate the samples for the noise
noisy_tone=sine+noise; //Combine the tone and noise
noisy_tone=noisy_tone/(max(abs(noisy_tone))); //Normalize the noisy
tone //tone
playsnd(noisy_tone,Fs);

SLU ECE 5
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

5. Periodic Signal Generation


A periodic signal is mathematically defined for one period only and this model is used
to generate the samples for any time instant.
Consider a periodic triangular wave with period T and amplitude A

described for one period as


x(t) = -A + (4A/T)t, 0 ≤ t ≤ T/2
= 3A - (4A/T)t, T/2 ≤ t ≤ T
The value of x(t) for any t ≥ 0 can be computed as x(t) = x(t-kT) with k=floor(t/T)..

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

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

IV. LABORATORY EXERCISES

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

3. Write a Scilab program to generate the following periodic signals.


(a)Sawtooth periodic signal whose amplitude varies between -1 and 1 with a fundamental frequency
of 250Hz and duration of 5 seconds. Use Fs=44100Hz. Save the audio signal as sawtooth.wav. Open
the audio file with Goldwave to verify the waveform, amplitude and frequency.

clear;clc;clf; if tcor >= (T/2) & tcor <T then


A=1;f=250;Fs=44100;tdur=5; x_temp = -A + (2*A/T)*tcor;
function [x]=trigen(A, f, Fs, tdur) end
x = [x, x_temp];
T=1/f;
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 = -A +(2*A/T)*tcor; wavwrite(x,Fs, ‘PATH\sawtooth.wav)
end; playsnd(x,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.

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

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

Potrebbero piacerti anche