I want to play all frequencies given in matrix(FrTm) with its duration.The actual duration is one second but each frequency has to play for 3 of 1/18 and 6 of 1/18 seocnd such as given in matrix(FrTm).
function Music()
Fs=44100;
T=1/Fs;
M = zeros(1,88);
for I=7:88,
M(I) = round(36.8*(2^(1/12))^(I-6));
end
Signal=[];
FrTm=[50,3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
50,6];
t=0:1/18:1;
for i=1:length(FrTm),
M(i)=FrTm(i);
Z=M(i);
data= sin(2*pi*Z/Fs*t);
signal=[data;signal];
end
stem(Signal);
sound (Signal, 44100);
end
The classical way to make a sound with a given frequency (f) and sample frequency (Fs) is to make a time vector with step
1/Fs:Where
Dis the duration of the signal. The signal itself is then:In this case the total time is fixed, not the time of each signal. The total time is denoted with
T, and the total time vector is made asThe sum of the second column is the total number of units the vector
timeneeds to be divided in, e.g.50, 3means that a signal at 50 Hz needs to be played for 3 units. This means we only need a time vector of the length of 3 units:Where
durationis the number of units for this part andsis the total number of units. The signal is then simply, as stated above,The data is then appended to the whole
signal. The complete code, looks like this:Note instead of declaring
timein the beginning, it is possible to make a new vector each time you run through the loop. In that case omittime = 0:1/Fs:T;and changet = time(1:floor(end*duration/s));tot = 0:1/Fs:floor(end*duration/s);