1. Engineering
  2. Computer Science
  3. please help with this matlab assignment ive figured out parts...

Question: please help with this matlab assignment ive figured out parts...

Question details
Please help with this MATLAB assignment! I’ve figured out parts 1 and 2 which I have attached, but I am stuck on part 3 figuring out how to overlap the decaying notes. Thank you in advance!

Lab 1: Elementary Music Synthesis This lab is based on a lab by Professor Virginia Stonick of Oregon State University 1. Purpose: The purpose of this lab is to construct physically meaningful signals mathematically in MATLAB™ using your knowledge of signals You will gain some understanding of the physical meaning of the signals you construct by using audio playback. We also hope that you have fun For this lab, you will need to use a PC with a sound card installed in it. You will need speakers or a set of headphones to listen to your musical creation 2. Background In this section, we explore how to use simple tones to compose a segment of music. By using tones of various frequencies, you will construct the first few bars of the Scarborough Fair song. In addition, you will work on improving the perceived quality of the sound your created Each musical note can be simply represented by a sinusoid whose frequency depends on the note pitch. In this lab, you will use a sampling rate of8 kHz There are seven natural notes: A, B, C, D, E, F and G. After G, we begin again with A Music is written on a staff consisting of five lines with four spaces between the lines The notes on the staff are written in alphabetical order, the first line is E as shown in Figure 1. Notes can
extend above and below the staff When they do, ledger lines are added. D E G A Figure 1. Natural notes Musical notes are arranged in groups o well be using for Scarborough Fair are in the octave containing frequencies from 220 Hz to 440 Hz. The twelve notes in each octave are logarithmically spaced in frequency, with each note being of a frequency 2Times the frequency of the note of lower frequency f twelve notes called octaves. The notes that Thus, a 1-octave pitch shift corresponds to a doubling of the frequencies of the notes in the original octave Table 1 shows the ordering of notes in the octave to be used to synthesize the opening of Scarborough Fair, as well as the fundamental frequencies for these notes Table 1. Notes in the 220-440 Hz octave Note Frequenc 220 A, B 220x2 220x2 220x2 220x2 220x2 220x2 220x2 220x2 220x2 220x211 440 A musical score is essentially a plot of frequencies (notes) on the vertical scale versus time (measures) on the horizontal scale. The musical sequence of notes for the piece you will synthesize is given in
Figure 2. The following discussion identifies how musical scores can be mapped to tones of specific pitch and duration Figure 2. Musical Score for Scarborough Fair 3. Note Frequency In the simplest case, each note may be represented by a burst of samples of a sinusoid followed by a shorter period of silence (samples of zeros, which are a pause). The pauses allow us to distinguish between separate notes of the same pitch The duration of each note burst is determined by whether the note is a whole note, half note, fourth note or an eight note (see Figure 3). Obviously, a fourth note has twice the duration of an eighth note, and so orn whole note it lasts 4 counts half note it lasts 2 courts fourthnote. it lasts 1 count Figure 3. Types of notes. In this Lab use a duration of4.000 samples for 1 count Therefore, your whole notes should be four times the duration of your fourth notes. The short pause you use to follow each note should be of the same duration regardless of the length of the note. Longer periods of silence that are part of the musical score are indicated by one of more rest symbols There are no rest symbols in the score you are given Note that A-G only yields seven notes, the additional notes are due to changes in pitch called sharps (denoted by the symbol #)or flats (denoted by the symbol b) that follows a given note. A sharp increases the pitch by 2and a flat decreases the pitch by 2 1/12 1/12 There are no sharp or flat symbols in the music you are going to create
In the musical score in Figure 2, the first half note and fourth note are both A. The next three fourth notes are all E and so on. You can get the fundamental frequencies for these notes from Table 1. 4. Improving perceived quality There are many ways of improving the perceived quality of a synthesized sound. Here you will learn about two methods: varying the note volume and overlapping individual tones. 4.1 Volume variations Typically, when a note is played, the volume rises quickly from zero and then decays over time, depending on how hard the key is struck and how long it is depressed. The variation of the volume over time is divided into four segments: Attack, Decay, Sustain, and Release (ADSR). For a given note, volume changes can be achieved by multiplying a sinusoid by another function called a windowing function An example of such function is shown in Figure 4. You may take A-5%, D=10%, S-70% and R15% of the length of a note. Figure 4. An ADSR Envelope 4.2 Overlapping tones Another improvement in perceived quality can be achieved by overlapping some notes as done by advanced piano players. As the volume of one note is decaying, another note is played. Mathematically, this can be accomplished by allowing the time regions occupied by subsequent sinusoids to overlap, hence removing the pause. This will yield a much smoother, less staccato-sounding piece.
5. Assignment 1. Synthesize the piece appearing in Figure 2 using only information from Sections 2 and 3. Play it back using the sound(x,fs)command in Matlab. Type help sound for more information. Please specify the sampling rate 8k Hz in the playback Turn in a listing of vour m-file 2. Improve the quality of the sound with a volume window function (see Section 4. Were you able to improve the sound quality? Save the modified music 3. As explained in Section 4.2, allow the decaying notes (i.e. with the windowing above). Try concatenating different function to model ADSR. function) to overlap slightly in time. synthesis in a new m-file Also turn in a listing of this m-file.
PART 1: Synthesizing the Musical Score for Scarborough Fair Fs 4000; %sampling note frequency rrequency for each note in the musical score for Scarborough rail 220 B 220 2-(2/12) C-220.2° (3/12) ; E 220 2-(7/12) Darations of note burst 1-0:1/Fs:: count t2-0:1/Fs:2: %2 counts note Ain(2 p 2) note A2in (2 pit) note B-sin(2 pi B 1) pause zero5 (1,1000); %Pause between note vecto of all the combined not [note Al pause note A2 pause note E pause note E pause note E pause- note B pause note c pause note B pause mote a3 sound (y, 8000); %Playing the sound Figure 1: MATLAB Code for Synthesis of the Scarborough Fair Sound PART 2: Improving Sound with ADSR Window Function function x ADSR (note) Alinspace (, 1, 0.05 length (note)) D-linspace (1, 0.8, 0.1length (note))
PART 2: Improving Sound with ADSR Window Function function x ADSR (note) A linspace (0, 1, 0.05length (note)): Dlinspace (1, 0.8, 0.1*length (note)) S = 1 inspace ( 0 . 8, 0 .8 , 0·7s length (note) ) ; R linspace (0.8, 0, 0.15length (note)) dif = length (note)-length (x) ; x [x, zeros (1, dif) ] ; Figure 2: ASDR Function >> Creating ADSR envelope for each note >xiADSR (note Al) 2 ADSR (note A2): x3ADSR (note E) ADSR (note B) ADSR (note_C) xADSR (note A3) >> Maltiplying each note by it ADSR ADSR A1x.note A ADSR A2-x2.note A2 ADSR E-x3.note E: ADSR A3x6.note A3: ADSRB pause ADSR C pause ADSRB pause ADSR A3); - >> sound (new sound, 8000) Playing sound
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution