The file fugue. mat will be made available to you. It contains numerical data that encode about 30-seconds' worth of Joh

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The file fugue. mat will be made available to you. It contains numerical data that encode about 30-seconds' worth of Joh

Post by answerhappygod »

The File Fugue Mat Will Be Made Available To You It Contains Numerical Data That Encode About 30 Seconds Worth Of Joh 1
The File Fugue Mat Will Be Made Available To You It Contains Numerical Data That Encode About 30 Seconds Worth Of Joh 1 (76.93 KiB) Viewed 30 times
The file fugue. mat will be made available to you. It contains numerical data that encode about 30-seconds' worth of Johann Sebastian Bach's Fugue #2 for the Well-Tempered Clavier. You are to write MATLAB code that loads this file, synthesizes the notes with correct timing, and then plays the notes. You will also prepare a document discussing possibilities for the computer-generated synthesis of music. In order to complete this project, you will need a computer with both MATLAB and sound. If you use a computer in the ECE department, you may need a set of headphones. This project is a rewritten version of a project given on the CD accompanying the book: J. H. McClellan, R. W. Schafer, and M. A. Yoder, Signal Processing First, Prentice Hall, 2003. Each student will submit his/her own work. You may discuss this project with other students. But your submissions must be the fruit of your own labor. Description of Project The file fugue.mat contains a structure array called voice with three elements. (In musical terms, this fugue contains three voices. These elements are: voice (m), where m = 1, 2, or 3 Each of these elements is a structure. Each of the elements represents a sequence of notes that is to be played. Each structure contains three fields: voice (m) pitch voice (m).start voice (m). duration

Each of these fields is a vector. For a given structure – for example, voice (2) – the three vectors - pitch, start, duration - are of equal length. These three vectors together define a sequence of notes. The vector start defines the start time of each note. The vector duration defines the duration of each note. The vector pitch defines the pitch of each note. 1 For example, the first number in the vector voice (2).start voice (2).start(1) is the start time in seconds of the first note in the sequence of notes defined by voice (2). The first number in the vector voice (2).duration voice (2).duration (1) is the duration in seconds of this first note. The first number in the vector voice (2).pitch voice (2).pitch (1) is the pitch number of this first note. Using the symbol p to represent the pitch number voice (m) - pitch (n), the pitch number for the n-th note of the m-th voice, the frequency of this note is given by 440 x 260-49)/12 Hz A couple of examples might be helpful. When p = 49, the frequency is 440 Hz. When p = 37, the frequency is 220 Hz.

Using the symbol p to represent the pitch number voice (m) - pitch (n), the pitch number for the n-th note of the m-th voice, the frequency of this note is given by 440 x 260–49)/12 Hz = A couple of examples might be helpful. When p = 49, the frequency is 440 Hz. When p = 37, the frequency is 220 Hz. The vector start tells you when each note should start, and the vector duration tells you how long each note should last. Both of these vectors measure time in seconds. In musical terms, each of the pitch numbers (numbers in the vector pitch) represents a key on the piano keyboard. This scheme accounts for both black and white keys. The pitch number increases as your finger moves from left to right on the keyboard. Middle C has been assigned the pitch number 40. When you move your finger on the keyboard to the right by 12 keys, the frequency doubles. For example, your finger moves 12 keys to the right in shifting from the key associated with pitch number 37 to the key associated with pitch number 49, and the corresponding frequencies are 220 Hz and 440 Hz, respectively. A set of 12 consecutive keys (including both black and white keys) is called an octave, corresponding to a doubling of the frequency Based on the above comments, the following idea should be forming in your mind. The file fugue.mat contains the same information normally found on sheet music. The program that you write will essentially replace three instruments. Your program will take the information from fugue.mat and use this information and the sound capability of the computer to play this fugue. The actual playing of the fugue is accomplished by passing a signal vector, which your program constructs, to the function sound. The signal vector will also be recorded. 2

You will first place a copy the file fugue.mat into the folder that you will use as the current folder while working on this project. You will write a script m-file and a function m-file. The function will be called from the script. Within the script, you will load the file fugue.mat into the MATLAB workspace using load. The script will also define a variable representing the sampling frequency and assign this variable the value 11025 (hertz or, equivalently, samples per second). This sampling frequency is only one-fourth the sampling frequency (44.1 kHz) used on a CD, but 11025 Hz is adequate for the purpose of this project. Your function will produce a signal vector representing one note. There will be three input arguments to this function. The first of these is the pitch number. The next argument is the duration in seconds. The final argument is the sampling frequency in hertz. This function will not need the start time because the signal vector produced by this function will later be shifted to start at the correct time. (That shifting will occur in the script.) There will be two outputs from this function: one signal vector and one scalar. The scalar is the number of samples in the signal vector. A single pure note having frequency f (Hz) and duration T (seconds) could be synthesized like this: t = 0: Ts:T; = x = cos (2*pi*f*t); In the above sample code, Ts is the sample period (the time between adjacent sample values) in seconds. The sample period equals the reciprocal of the sampling frequency. (Don't confuse the sampling frequency with the frequency f of the note.) The frequency f is related to the pitch number as explained in the section Description of Project. If you were to synthesize the notes as shown above, however, there would be audible clicks in your synthesized music. These clicks are due to the sudden arrival and departure of the notes. You should eliminate the clicks by having each note fade in and fade out. You can accomplish this by multiplying each pure note (the x defined above) by a mask. The mask is a vector having the same length as x. The first k samples of the mask vector should increase linearly from 0 to 1. The last k samples of the mask should decrease linearly from 1 to 0. All other samples in the mask should equal 1. You should use k = 100; this is a suitable choice for the sampling frequency of 11025 Hz that you will be using in this project. In other words, with k = 100, the fade-in of each note will last about 9 ms, as will the fade-out of each note. The duration of the note will be the time from the beginning of the fade-in to the end of the fade-out. So the mask for each note will equal 1 for a period of time that is less than the duration of the note by about

18 ms. Since different notes will, in general, have different durations, the mask will be different for different notes. (However, the duration of every note will be greater than 20 ms, so the fade- out will never overlap the fade-in.) The vector returned by your function will represent one masked note. As mentioned above, the function will also return a scalar equal to the number of samples in the output vector. Your script will call your function once for each note of each voice. The script will shift the signal for each note so that it starts at the proper time. The script will then compose a signal vector that incorporates all notes of all three voices. We will call this the composite-signal vector You should look up the actual values of voice (1).start(1), voice (2).start(1) and voice (3).start(1). You will find that for a time at the beginning of the fugue only the first voice is present. In other words, during this period, in which only the first voice is present, only one note plays at a time. After a while, the second voice begins, so that two sequences of notes are playing simultaneously. A short while after that, the third voice begins and three sequences of notes are playing simultaneously. In the interest of efficiency, you should pre-allocate memory for the signal vector that will be passed to sound. As usual, this pre-allocation will be accomplished with the function zeros. But first, it will be necessary to determine how long this signal vector must be. This can be determined by doing some simple calculations on the start time and duration of the last note for each of the three voices. You should program your script to do these calculations. (You could hard-code the maximum length, but that is not good programming practice.) Be aware that your calculations will, by default, employ (double-precision) floating-pointing numbers. The length that you input to zeros cannot have a fractional part. You can use the function uint32 to round a floating-point number to the nearest unsigned integer. (You need uint32 because uint8 and uint16 can't represent a large enough number for this application.) In the script, the masked signal vector for each note must be added to the composite-signal vector (that has been pre-allocated and that, after normalization, will eventually be passed to sound). For example, the masked signal vector w of a note can be added in to the long signal vector y (the composite-sigmal vector) like this: v(a:b) = y(a:b) + w; where a is the index of y corresponding to the start time of the note and b is the index corresponding to the end time of the note. Please note, since a and b are indices, they are whole numbers (1, 2, 3, etc); they are dimensionless, even though they are related to time as measured in seconds. These index values a and b may be computed from the start time of the note, the sampling frequency (11025 Hz) and the number of samples for the note's signal vector. Make

sure you round-off your calculated index values using uint32. (If you use a floating-point number with a nonzero fractional part as an index in an array, MATLAB will complain.) It is essential to scale properly the composite-signal vector. The function sound, which will be used to play the composite-signal vector, and the function audiowrite, which will be used to record the composite-signal vector, both expect that all sample values will be between -1 and +1. Any sample value that does not meet this criterion will be clipped. (A sample value of -1.27 will, for example, be clipped to -1, and a sample value of +2.41 will be clipped to +1.) As you might imagine, clipping will distort the fugue. You should recognize that even if each component note meets this criterion, the composite-signal vector, obtained by summing notes together, may not. You can achieve the desired normalization by first finding the maximum of the absolute value of the composite-signal) samples and then dividing all samples by this maximum. It is recommended that you additionally multiply the result by 0.9; this ensures that the new, normalized composite-signal vector does not even touch the limits of -1 and +1. After the normalized, composite-signal vector has been constructed, the script will use sound in order to play the music. You should use three input arguments to sound: the (normalized composite-signal) vector, a scalar equal to the sampling frequency, and a scalar equal to 16. (This last input is the number of bits to be used per sample when playing the vector. If you don't specify 16 bits, sound will use 8 bits by default.) When the script is executed, the command sound should be executed only once. In this single invocation of sound, the script should send the normalized composite-signal vector, which includes every note of all three voices. If your script invokes sound more than once, the fugue won't sound right. With multiple invocations of sound, computational delay between invocations will cause the timing of the notes to be wrong. When played correctly, this fugue begins with just one voice, a second voice joins in after a few seconds, and the third voice joins in a few seconds after that. If you have done the masking in the function m-file) correctly, there should be no clicking sounds. Finally, you will record the normalized composite-signal vector in a WAVE (waveform audio format) file (*.wav) using the audiowrite function. (A WAVE file does not employ compression and is much less memory-efficient than MP3; but a WAVE file is acceptable for small sound snippets.) Use audiowrite with three inputs: a string for the filename, the (normalized composite-signal) vector, and the sampling frequency. In the interest of conserving memory, audiowrite saves each sample using just 16 bits, rather than with the full 64 bits (that is, 8 bytes) of a double. After saving the signal vector to a WAVE file, use the function audioinfo to obtain some basic facts about the saved WAVE file. Then print out the sample rate and the total number of) samples for the WAVE file (with information provided by the function audioinfo). A WAVE file can be played even outside of MATLAB.

What You Will Submit You will submit three files. One file will be a document (submitted as a PDF file) in which you discuss possibilities for the computer-generated synthesis of music. Your document should be approximately one page long. The other two files will be your script m-file and your function m-file. You need not submit the WAVE file. You will not be publishing your script m-file. Checklist: 1. Document (as a PDF file) containing your discussion of music synthesis 2. Script m-file 3. Function m-file
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply