Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 2. [40 points.] Although pure harmonics contain all the necessary information for us to identify the tune, musical instruments have a more pleasant
Exercise 2. [40 points.] Although pure harmonics contain all the necessary information for us to identify the tune, musical instruments have a more pleasant sound because they com- bine multiple harmonics and modulate the output based on their internal vibration modes. Moreover, musicians typically play more than one note at a time to enrich the sound. To en- able both of these behaviors, we are going to create a new MATLAB function w = tone2 (fs, note, instrument), where w is a row vector f, is a scalar, note is a structure that contains the following information octave: a vector of integer numbers; semitone: an array of strings of the same size as note. octave. Each element of the array can either be the same as the previous exercise or can contain -1'. In this case, w should be a vector of zeros of the same size as t, i.e. a pause; duration: a scalar number. Finally, instrument is an optional input and is a structure that contains the following information .harmonics: a 2 x 1 vector; envelope: a function hadle in t. The envisioned function must do the following. a) Generate the signal i=1 where N is the number of elements in the vector oct=note.octave (equal to the number of elements in the array note.semitone), and f, is the frequency of each individual note; b) If the user called the function with three inputs instead of just two, generate the signal N N Homework w = sin(2 f;. t), i=1 ECEN 2310 w = sin(2 fit) + a sin(27(2fi). t) + a2 sin(2 (3f;) . t), a and a2 are the intensities of the second and third harmonics (i.e. the soundwaves at 2 times and 3 times the main frequency), which can be obtained from the 2 x 1 vector instrument.harmonics; c) If the user called the function with three inputs instead of just two, multiply the final soundwave w by the function handle instrument.envelope evaluated in t. To check if the function works, write a new script that performs the following a) Define the structure piano, where the harmonics vector is [0.6 0.2] and the envelope is min (40t, 1). e-4t; Week 11 b) Run the MATLAB Script mary2.m; c) Play the first note in script and write a for loop that Calls tune2 to compute the soundwave associated to the next note; Waits for the previous note to be done playing using tic and toc to help with the timing; Plays the new soundwave.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started