Matlab Scripts on C-Chord
In my note on Intervals of Notes, I said I would provide a Matlab script that I wrote to compare notes and build versions of the C-chord. My Word version of the document had tables of icons that played short sound samples. Maybe someone can tell me how to incorporate something like that in LinkedIn. Anyway, here is the script that I used to build the files. This is basically how I write scripts or programs or code. Being an old dude, I learned Fortran, then Fortran 77. I caught the tail end of cards. I have written in those and C and C++. It's all the same, you just have to learn the particular syntax. I also am very good at scavenging from bits and pieces of code either I wrote before, or someone else wrote and posted. It is "fun" trying to figure out what someone else was trying to do. Anyway, if you want to, and if you happen to have Matlab on your computer, you can play around with this bit of script. If you don't like whatever syntax I am using, oh well, modify it. Make it work for you.
Inton = 2; % Inton:? 1 = Just Intonation (JI), 2 = Equal Temperament (ET)
?
A1 = 1.0; %? Note of C, 261.63 Hz
A2 = 1.0; %? Note of E, 327.04 or 329.63 Hz (JI or ET)
A3 = 1.0; %? Note of G, 392.45 or 392 Hz (JI or ET)
B = 1.0;? %? Attenuation of Higher orders
?
Ffund1(1) = 261.63;? %? Note of C
Ffund1(30) = 0.0;
A(1) = A1;
w(1) = 2*pi*Ffund1(1);
s1 = A(1) sin(w(1) t);
for i = 2:30
??? Ffund1(i) = Ffund1(1) * i;
??? w(i) = 2*pi*Ffund1(i);
??? A(i) = A(i-1) * B;
??? p1(i) = 2*pi*rand;
??? s1 = s1 + A(i) sin(p1(i)+(w(i) t));
end
?
Ffund2(1) = Ffund1(1) * 5/4;? %? Note of E
if Inton == 2
??? Ffund2(1) = Ffund1(1) * 2^(4/12);
end
Ffund2(30) = 0.0;
A(1) = A2;
w(1) = 2*pi*Ffund2(1);
s2 = A(1) sin(w(1) t);
for i = 2:30
领英推荐
??? Ffund2(i) = Ffund2(1) * i;
??? w(i) = 2*pi*Ffund2(i);
??? A(i) = A(i-1) * B;
??? p2(i) = 2*pi*rand;
??? s2 = s2 + A(i) sin(p2(i)+(w(i) t));
end
?
Ffund3(1) = Ffund1(1) * 3/2;? %? Note of G
if Inton == 2
??? Ffund3(1) = Ffund1(1) * 2^(7/12);
end
Ffund3(30) = 0.0;
A(1) = A3;
w(1) = 2*pi*Ffund3(1);
s3 = A(1) sin(w(1) t);
for i = 2:30
??? Ffund3(i) = Ffund3(1) * i;
??? w(i) = 2*pi*Ffund3(i);
??? A(i) = A(i-1) * B;
??? p3(i) = 2*pi*rand;
??? s3 = s3 + A(i) sin(p3(i)+(w(i) t));
end
?
sComposite = s1 + s2 + s3;????????????????????? % Generate composite of tones s and s2
sCompositeNorm = sComposite / max(abs(sComposite));
?
sound(sCompositeNorm, Fs)????????????????????% Produce Composite Tone s + s2 As Sound
?
filename = 'CEG_1p0harms_ET_RandomPhase0.wav';
audiowrite(filename,sCompositeNorm,Fs);
?