function playTwinkleTwinkle() % 定义音符和持续时间 notes = [261.63, 261.63, 392.00, 392.00, 440.00, 440.00, 392.00, ... 349.23, 349.23, 329.63, 329.63, 293.66, 293.66, 261.63, ... 392.00, 392.00, 349.23, 349.23, 329.63, 329.63, 293.66, ... 392.00, 392.00, 349.23, 349.23, 329.63, 329.63, 293.66, ... 261.63, 261.63, 392.00, 392.00, 440.00, 440.00, 392.00, ... 349.23, 349.23, 329.63, 329.63, 293.66, 293.66, 261.63]; durations = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, ... 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, ... 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, ... 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, ... 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, ... 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1]; % 演奏音符 for i = 1:length(notes) % 使用正弦波和方波的组合 t = 0:1/8000:durations(i); sound((1 - 0.2) * sin(2 * pi * notes(i) * t) + 0.2 * square(2 * pi * notes(i) * t, 50), 8000); pause(1 * durations(i)); end end
01-01
7897
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
5189
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)