我这周已经咕了三篇文章了T T

立flag需谨慎(我不一定补得回来了)

这周我们将来解锁MATLAB的新技能→用MATLAB演奏音乐!!!

由于时间有限(已经熄灯了),今天先把代码贴出来,原理我们下回介绍

% 创建函数gen_wavefunction 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/(rythm*2*pi));end% 我们来弹一曲小星星?y1=gen_wave(1,0.5);y2=gen_wave(1,0.5);y3=gen_wave(5,0.5);y4=gen_wave(5,0.5);y5=gen_wave(6,0.5);y6=gen_wave(6,0.5);y7=gen_wave(5,1);y=[y1,y2,y3,y4,y5,y6,y7];y1=gen_wave(4,0.5);y2=gen_wave(4,0.5);y3=gen_wave(3,0.5);y4=gen_wave(3,0.25);y5=gen_wave(3,0.25);y6=gen_wave(2,0.5);y7=gen_wave(2,0.5);y8=gen_wave(1,1);y=[y,y1,y2,y3,y4,y5,y6,y7,y8];y1=gen_wave(5,0.5);y2=gen_wave(5,0.5);y3=gen_wave(4,0.5);y4=gen_wave(4,0.5);y5=gen_wave(3,0.5);y6=gen_wave(3,0.5);y7=gen_wave(2,1);y=[y,y1,y2,y3,y4,y5,y6,y7];y1=gen_wave(5,0.5);y2=gen_wave(5,0.5);y3=gen_wave(4,0.5);y4=gen_wave(4,0.5);y5=gen_wave(3,0.5);y6=gen_wave(3,0.5);y7=gen_wave(2,1);y=[y,y1,y2,y3,y4,y5,y6,y7];y1=gen_wave(1,0.5);y2=gen_wave(1,0.5);y3=gen_wave(5,0.5);y4=gen_wave(5,0.5);y5=gen_wave(6,0.5);y6=gen_wave(6,0.5);y7=gen_wave(5,1);y=[y,y1,y2,y3,y4,y5,y6,y7];y1=gen_wave(4,0.5);y2=gen_wave(4,0.5);y3=gen_wave(3,0.5);y4=gen_wave(3,0.25);y5=gen_wave(3,0.25);y6=gen_wave(2,0.5);y7=gen_wave(2,0.5);y8=gen_wave(1,1);y=[y,y1,y2,y3,y4,y5,y6,y7,y8];sound(y,Fs);

大家快来试一试叭