EE 426 : Digital Signal Processing (DSP)

EE 426 : Digital Signal Processing (DSP)

Week-9

Prepared by: Dr. Erhan A. Ince Lab Assist: Mr. Wasım Ahmad

______

Exercise 1

The objective of this exercise is to learn how MATLAB can be used for digital synthesis of music. The exercise itself will involve creating a function that can produce a simple set of musical notes and processing of the signal to improve the perceived quality of the signals when played back. Musical notes in general are arranged in groups of twelve called octaves. The fundamental frequencies associated with the twelve notes in the octave of frequencies ranging from 220Hz to 440Hz are as given below:

NOTE / Frequency (Hz)
A / 220
A# / 220*21/12
B / 220*22/12
C / 220*23/12
C# / 220*24/12
D / 220*25/12
D# / 220*26/12
E / 220*27/12
F / 220*28/12
F# / 220*29/12
G / 220*210/12
G# / 220*211/12

Table 1: Notes in the 220-440Hz Octave

Note that the frequency doubles from the start of an octave to its end. The next octave ranges from 440Hz to 880Hz. The fundamental frequencies of the notes in this octave can be found out by a similar approach as in table above.

Knowing the fundamental frequencies of each note, the notes for a musical piece as well as the duration of each piece will allow us to synthesise the musical piece on a computer. Notes are usually classified as one-eighth, quarter, half and whole notes, on the basis of their duration. One-eighth note last an eighth as long as the whole note. There are also silent pauses usually between notes varying from the length of a one-eighth note to that of a quarter note. What we need to do is to write a program as the one shown below that creates a row vector that corresponds to the first few notes of any piece of music you wish to synthesise. Since we will be using a computer our signal is a sampled version of the original. Let us for the sake of this experiment take a sampling rate of 8000 samples per second.

function [music] = song(speed)

%

%

alpha = 2^(1/12);

a = 220;

as = 220*alpha;

b =as*alpha;

c=b*alpha;

cs= c*alpha;

d = cs*alpha;

ds = d*alpha;

e = ds*alpha;

f = e*alpha;

fs = f*alpha;

g = fs*alpha;

gs=g*alpha;

gl = g/2;

eighth = speed;

quarter =2*speed;

half = 4*speed;

whole = 8*speed;

music = [s_note(c,quarter),s_note(c,quarter),s_note(d,quarter),...

s_note(e,quarter),s_note(c,quarter),s_note(e,quarter),...

s_note(d,half),s_note(c,quarter),s_note(c,quarter)];

sound(music,8000);

function[z] = s_note(note,length);

pausetime = zeros(1,500);

z = [ sin(2*pi*note*[0:length-1]/8000),pausetime];

1.  Explain in your own words what the program does. Include in your description the sequence of notes, the duration of each note, the duration of the pause between each note, and any other aspect that are relevant to the signal.

2.  To improve the perceived quality of the musical notes, we can include harmonics of

the fundamental frequencies in each note. Create a function that replaces the function

s_note by creating a row vector that contains a sum of a sinusoid at the fundamental

frequency, a sinusoid at twice the fundamental frequency and half the amplitude, and a

sinusoid at thrice the fundamental frequency and one-fourth the amplitude. Substitute

your function in the program and observe any difference in the quality of the signal you

created. Include the function with your solution and explain the difference in the perceived

quality.

Exercise 2

The purpose of this exercise is to study the effect of time scaling property of the Fourier transform on rectangular pulses. We have seen in class that the Transform pair of a rectangular pulse in time-domain is a sinc function in frequency domain and vice versa. For this exercise develop a MATLAB program that will ask the user to input widths of two different rectangular pulses (each of unity amplitude) and takes the FTs to compare their spectra. Make a plot of both the rectangular pulses and their spectra all on the same figure using subplot commands of MATLAB.