This is a matlab script used to play a sound i have a problem with the second to
ID: 3782972 • Letter: T
Question
This is a matlab script used to play a sound i have a problem with the second to last line where it says " insert the note" i dont know how to write it in the script so i can play the sound .
% --------------play_lamb.m-------------- %
mary.keys = [44 42 40 42 44 44 44 42 42 42 44 47 47];
% NOTES: C D E F G % Key #40 is middle-C mary.durations = 0.25 * ones(1,length(mary.keys));
fs = 8000; % 11025 Hz also works xx = zeros(1, sum(mary.durations)*fs + length(mary.keys));
n1 = 1; forkk = 1:length(mary.keys) keynum = mary.keys(kk);
tone = % <------- Fill in this line n2 = n1 + length(tone) - 1; xx(n1:n2) = xx(n1:n2) + tone;%<------- Insert the note
n1 = n2 + 1;
end soundsc(xx, fs)
Explanation / Answer
mary.keys = [44 42 40 42 44 44 44 42 42 42 44 47 47];
% NOTES: C D E F G % Key #40 is middle-C mary.durations = 0.25 * ones(1,length(mary.keys));
fs = 8000; % 11025 Hz also works xx = zeros(1, sum(mary.durations)*fs + length(mary.keys));
n1 = 1;
Ts=1/fs;
tone=[0:Ts:1];
fork k = 1:length(mary.keys) keynum = mary.keys(kk);
n2 = n1 + length(tone) - 1;
xx(n1:n2) = xx(n1:n2) + tone;
n1 = n2 + 1;
end
soundsc(xx, fs)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.