Question

Write an M-file to produce a desired note, expressed in piano key number, for a given...

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.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

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.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Write an M-file to produce a desired note, expressed in piano key number, for a given...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT