MATLAB play notes for different duration's as specified by

조회 수: 7 (최근 30일)
sanbadgerdude
sanbadgerdude 2017년 4월 15일
댓글: sanbadgerdude 2017년 4월 18일
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);

답변 (1개)

Geoff Hayes
Geoff Hayes 2017년 4월 18일
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);
  댓글 수: 1
sanbadgerdude
sanbadgerdude 2017년 4월 18일
Thank you! I have been beating myself up over this. I had started to write out a long drawed out code when I saw your answer. Very much appreciated! Such a simple overlooked resolution.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by