Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using MATLAB .Write a script to play a short piece of electronic music of your c

ID: 667177 • Letter: U

Question

Using MATLAB.Write a script to play a short piece of electronic music of your composing. The
piece must conform to the following rules
1. It must be between 10 and 15 seconds long.
2. It must be sampled at the rate Fs = 8192.
3. It must incorporate at least three of the built-in sounds handel, gong, laughter,
train, chirp and splat. These can be incorporated in part, in full, or re-
peated several times in succession
4. It must include sounds playing at the same time as others.
5. It may include pure notes created using sine waves, but this is optional.
6. It may include piano notes, but this is harder than it might seem: they will
need to be resampled to match the sampling rate of 8192. Only attempt
this if you want a challenge.
7. No other sounds may be included in the piece. So no sampling your own
voice, no downloading other clips, etc.
8. The nal piece must be represented by a single array, which is played with
a single call of sound or soundsc.

9.The script you paste below must construct and play your piece from an empty
workspace

Explanation / Answer

For example, >> load chirp
followed by >>my_music = y; reads the chirp sound from a file into an array called y and then
sets my_music equal to y.

clc;    % Clear the command window.
format long g;
format compact;
notes={'C' 'E' 'B' 'A' 'G'}
freq=[523.251 659.255 493.88 440.00 392.00]
deltaT = 1 / (20*min(freq))
song={'C' 'C' 'E' 'C' 'B' 'A' 'G'}              % your song
dur=[1 .5 0.125 0.06 0.8 0.5 2 1]
a=[]
for k = 1 : numel(song)
   fprintf('In iteration %d, looking for note %s in notes. ', k, song{k});
   index = find(ismember(notes, song{k}))
   thisFrequency = freq(index)
   numberOfSoundSamples = dur(k) / deltaT
   t = linspace(0, dur(k), numberOfSoundSamples);
   a=[a sin(2 * pi * thisFrequency * t)]; % sinusoidal
end
plot(a, 'b-', 'LineWidth', 2);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.5 1 .5]);
soundsc(a)
fprintf('DONE! ');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote