Write an M-file to produce a desired note, expressed in piano key number, for a given duration. Your M-file should be in the form of a function called key2note.m. Your function should have the following form:
function xx = key2note(X, keynum, dur, fsamp) % KEY2NOTE Produce a sinusoidal waveform corresponding to a % given piano key number % % usage: xx = key2note (X, keynum, dur) % % xx = the output sinusoidal waveform % X = complex amplitude for the sinusoid, X = A*exp(j*phi). % keynum = the piano keyboard number of the desired note % dur = the duration (in seconds) of the output note % fs = sampling frequency, use 11025 or 22050 Hz % tt = 0:(1/fsamp):dur; freq = %<=============== fill in this line xx = real( X*exp(j*2*pi*freq*tt) );
For the “freq =” line, use the formulas given above to determine the frequency for a sinusoid in terms of its key number. You should start from a reference note (middle-C or A-440 is recommended) and solve for the frequency based on this reference. Notice that the xx = real( ) line generates the actual sinusoid as the real part of a complex exponential at the proper frequency. Show the code and play a note, say key #47 (G4), for 2 seconds to the instructor for verification.
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Write an M-file to produce a desired note, expressed in piano key number, for a given...