MATLAB play notes for different duration's as specified by
13 views (last 30 days)
Show older comments
I am trying to play a string of notes, each for a different duration. The following is what I have come up with but can not seem to get it to work properly. I am new to this and trying to understand. My intent is to have an array of notes then an array of times that each note will play. I may play the same note but hold it for a different duration of time.
if true
% code
end
clc
clear all
fs = 16000;
t1=[0:1/fs:0.3];
t2=[0:1/fs:0.6];
t3=[0:1/fs:0.9];
C2 = 65.4064;
D2 = 73.4162;
F2 = 87.3071;
staff1 = [C2 D2 F2];
time1 = [t1 t2 t3];
play1 = sin(2*pi*staff1*time1);
sound(play1,fs);
0 Comments
Answers (1)
Geoff Hayes
on 18 Apr 2017
sanbadgerdude - when I run your above code, I observe the following error
Error using *
Inner matrix dimensions must agree.
play1 = sin(2*pi*staff1*time1);
This is because the dimensions of staff1 is 1x3 whereas the dimensions for time1 is 1x28803, and so multiplying the two together is going to fail. What you can do instead is multiply each time intervals by a frequency prior to passing this in to the sine function. Try
ft = [t1*C2 t2*D2 t3*F2];
play1 = sin(2*pi*ft);
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!