产生衰减正弦波函数
function y = gen_wave(tone, rythm)
Fs = 8192;
freqs = [523, 587, 659, 698, 783, 880, 988];
x = linspace(0,2*pi*rythm,floor(Fs * rythm));
y = sin(freqs(tone) * x).*(1-x/(2*pi*rythm));
end
主函数
Fs = 8192;
tone = [1,1,5,5,6,6,5,4,4,3,3,2,2,1,5,5,4,4,3,3,2,5,5,4,4,3,3,2,1,1,5,5,6,6,5,4,4,3,3,2,2,1];
rythm = zeros(1,42);
for i=1:42
if mod(i,7)==0
rythm(1,i)=1;
else
rythm(1,i)=0.5;
end
end
y=[];
for i=1:42
ys = gen_wave(tone(1,i), rythm(1,i));
y = [y,ys];
end
sound(y,Fs);