这是某位牛人写的代码,贴到matlab里听听看。《卡农》!!!

% Cripple Pachebel's Canon on Matlab

% Have fun

fs = 44100; % sample rate

dt = 1/fs;

T16 = 0.125;

t16 = [0:dt:T16];

[temp k] = size(t16);

t4 = linspace(0,4*T16,4*k);

t8 = linspace(0,2*T16,2*k);

[temp i] = size(t4);

[temp j] = size(t8);

% Modification functions

mod4 = sin(pi*t4/t4(end));

mod8 = sin(pi*t8/t8(end));

mod16 = sin(pi*t16/t16(end));

f0 = 2*146.8; % reference frequency

ScaleTable = [2/3 3/4 5/6 15/16 ...

1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...

2 9/4 5/2 8/3 3 10/3 15/4 4 ...

1/2 9/16 5/8];

% 1/4 notes

do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);

re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);

mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);

fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);

so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);

la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);

ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);

do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);

re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);

mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);

fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);

so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);

la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);

tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);

ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);

do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);

re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);

mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);

fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);

so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);

la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);

ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);

do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);

blkf = zeros(1,i);

% 1/8 notes

fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);

so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);

la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);

ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);

do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);

re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);

mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);

fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);

so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);

la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);

tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);

ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);

do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);

re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);

mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);

fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);

so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);

la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);

ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);

do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);

blke = zeros(1,j);

% 1/16 notes

fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);

so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);

la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);

ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);

do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);

re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);

mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);

fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);

so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);

la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);

tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);

ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);

do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);

re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);

mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);

fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);

so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);

la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);

ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);

do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);

blks = zeros(1,k);

% Blank Block

blkblock = [blkf blkf blkf blkf  blkf blkf blkf blkf...

blkf blkf blkf blkf  blkf blkf blkf blkf];

% Base Melody

cello = [do1f do1f so0f so0f  la0f la0f mi0f mi0f...

fa0f fa0f do0f do0f  fa0f fa0f so0f so0f];

% So-FUCKING-Long Melody

violin = [mi2f mi2f re2f re2f  do2f do2f ti1f ti1f...

la1f la1f so1f so1f  la1f la1f ti1f ti1f ...%

do2f do2f ti1f ti1f  la1f la1f so1f so1f...

fa1f fa1f mi1f mi1f  fa1f fa1f re1f re1f ...%

do1f mi1f so1f fa1f  mi1f do1f mi1f re1f...

do1f la0f do1f so1f  fa1f la1f so1f fa1f...%

mi1f do1f re1f ti1f  do2f mi2f so2f so1f...

la1f fa1f so1f mi1f  do1f do2f blkf blke ti1e ...%

do2e ti1e do2e do1e  ti0e so1e re1e mi1e...

do1e do2e ti1e la1e  ti1e mi2e so2e la2e...

fa2e mi2e re2e fa2e  mi2e re2e do2e ti1e...

la1e so1e fa1e mi1e  re1e fa1e mi1e re1e... %%

do1e re1e mi1e fa1e  so1e re1e so1e fa1e...

mi1e la1e so1e fa1e  so1e fa1e mi1e re1e...

do1e la0e la1e ti1e  do2e ti1e la1e so1e...

fa1e mi1e re1e la1e  so1e la1e so1e fa1e...%

mi1f mi2e blke re2f re2f  blkf do1f mi2f mi2f...

la2f la2f so2f so2f  la2f la2f ti2f ti2f...%

do3e blke do2e blke ti1f ti1f  blkf la1f do2f do2f...

do2f do2f do2f do2f  do2f fa2f re2f so2f...%

so2e mi2s fa2s so2e mi2s fa2s so2s so1s la1s ti1s ...

do2s re2s mi2s fa2s mi2e do2s re2s...

mi2e mi1s fa1s so1s la1s so1s fa1s so1s mi1s fa1s so1s...

fa1e la1s so1s fa1e mi1s re1s mi1s re1s do1s re1s mi1s fa1s so1s la1s...

fa2e la1s so1s la1e ti1s do2s so1s la1s ti1s do2s re2s mi2s fa2s so2s...%

mi2e do2s re2s mi2e re2s do2s re2s ti1s do2s re2s mi2s re2s do2s ti1s...

do2e la1s ti1s do2e do1s re1s mi1s fa1s mi1s re1s mi1s do2s ti1s do2s...

la1e do2s ti1s la1e so1s fa1s so1s fa1s mi1s fa1s so1s la1s ti1s do2s...

la2e do2s ti1s do2e ti1s la1s ti1s do2s re2s do2s ti1s do1s la1s ti1s...%%

do2e blke blkf ti1e blke blkf la1e blke blkf do2e blke blkf...

do1e blke blkf do1e blke blkf do1e blke blkf do1e blke blkf...%

blkf so1e blke blkf so1e blke blkf mi1e blke blkf so1e blke...

blkf fa1e blke blkf mi1e blke blkf fa1e blke blkf re2e blke...%

mi2e mi1e fa1e mi1e re1e re2e mi2e re2e do2e mi1e do1e do2e ti1e so0e fa0e so0e...

la0e la1e so1e la1e so1e so0e fa0e so0e do1e la1e so1e la1e ti1e ti0e la0e ti0e...%

do1e do2e re2e do2e ti1e ti0e do1e ti0e la0e la1e so1e la1e ti1e ti0e mi1e re1e...

do1e do2e re2e fa2e mi2e mi1e so1e mi2e do2e fa2e mi2e fa2e re2e so1e fa1e so1e...%

mi1e so1e so1e so1e so1e so1e so1e so1e mi1e mi1e mi1e mi1e mi1e mi1e so1e so1e...

fa1e fa1e fa1e do2e do2e do2e do2e do2e do2e do2e la1e la1e so1e so1e re2e ti1e...%%

so1e mi2e mi2e mi2e re2e re2e re2e re2e do2e do2e do2e do2e so2e so2e so2e so2e...

la2e la2e la2e la2e so2e so2e so2e so2e la2e la2e la2e la2e ti2e ti1e ti1e ti1e...%

do2e do1s re1s mi1e do1e ti0e ti1s do2s re2e ti1e la1e la0s ti0s do1e la0e ti0e so1s fa1s mi1e re1e...

do1e mi1s re1s do1e fa1e mi1e do1s re1s mi1e so1e fa1e la1s so1s fa1e mi1e re1e so1s fa1s mi1e re1e...%

mi1e do2s ti1s do2e mi1e so1e so1s la1s ti1e so1e mi1e do2s re2s mi2e do2e mi2e mi2s re2s do2e ti1e...

la1e la1s so1s la1e ti1e do2e mi2s re2s do2e mi2e fa2e do2s ti1s la1e la1e so1e re1e so1e so1e...%

so1f so1f so1f so1f  do1f do1f do1f so1f...

fa1f fa1f so1f so1f  fa1f do1f do1f do1e ti0e...%

do1f do2f ti1f ti1f  la1f la1f so1f so1f...

do1f do1e re1e mi1f mi1f  do2f do2f ti1f ti1f...%%

do2f];

% cello

c1 = [cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello blkf];

% violin1

v1 = [blkblock violin blkblock blkblock];

% violin2

v2 = [blkblock blkblock violin blkblock];

% violin3

v3 = [blkblock blkblock blkblock violin];

% Get dirty

s = c1+v1+v2+v3;

s = s/max(s);

sound(s,fs);

matlab 仿真钢琴,用Matlab模拟钢琴的声音相关推荐

  1. 用matlab仿真导航信号,北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序)[互联网+]...

    <北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序)[互联网+]>由会员分享,可在线阅读,更多相关<北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLA ...

  2. 用matlab仿真导航信号,北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序)...

    <北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序)>由会员分享,可在线阅读,更多相关<北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序)(9 ...

  3. 「电子万年历matlab仿真」——基于Matlab的电子万年历仿真实现

    「电子万年历matlab仿真」--基于Matlab的电子万年历仿真实现 作为一种具有时间显示.日期查询.闹钟提醒等功能的电子产品,电子万年历已经成为了人们日常生活中不可或缺的一部分.而在现代科技的发展 ...

  4. matlab仿真的实例,MATLAB仿真实例

    <MATLAB仿真实例>由会员分享,可在线阅读,更多相关<MATLAB仿真实例(51页珍藏版)>请在人人文库网上搜索. 1.实际应用,MATLAB/Simulink,的推出得到 ...

  5. ofdm系统matlab仿真论文,基于MATLAB的OFDM仿真(SIMULINK仿真)

    中 文 摘 要 正交频分复用(OFDM)是一种多载波宽带数字调制技术.相比一般的数字通信系统,它具有频带利用率高和抗多径干扰能力强等优点,因而适合于高速率的无线通信系统.正交频分复用 OFDM 是第四 ...

  6. 模糊PID控制器MATLAB仿真探讨,基于Matlab的模糊自整定PID控制器仿真研究

    1. 引言 传统的PID控制因其算法可靠简单,鲁棒优良,可靠度高,在工业过程中得到了广泛的应用,特别适用于建立一个精确的数学模型确定控制系统的确定性控制.李文宇等对PID控制进行了研究,并取得了一定的 ...

  7. matlab仿真报告,电路Matlab仿真实验精选报告.docx

    电路 Matlab 仿真实验报告 武汉大学电气工程学院仿真实验报告 武汉大学电气工程学院 MATLAB 电路仿真实验报告 姓名: 班级: 学号: 2015 级大二上仿真报告 武汉大学电气工程学院仿真实 ...

  8. 卫星测控matlab程序,北斗卫星导航信号串行捕获算法MATLAB仿真报告(附MATLAB程序).docx...

    PAGE 4 北斗卫星导航信号串行捕获算法MATLAB仿真报告 原理 卫星导航信号的串行捕获算法如图1所示. 图1 卫星导航信号的串行捕获算法 接收机始终在本地不停地产生对应某特定卫星的本地伪码,并且 ...

  9. 电机 matlab 仿真 实验总结,Matlab/Simulink仿真技术在电机实验教学中的应用

    为适应军队信息化建设和军队院校教育教学转型的需要,军队院校的实验教学必须不断创新.深化改革,形成系统.完整的实验教学创新理论,指导院校实验教学实践,推动实验教学水平跃上新台阶.电机实验的特点是机电结合 ...

  10. 变频器matlab仿真,SPWM变频器 Matlab仿真

    SPWM变频器 Matlab仿真 2011-2012学年第二学期 工作室项目研究报告 研究题目:SPWM变频器Matlab仿真 班级: 姓名: 指导教师: 2012年6月10日 1. 前言 随着现代电 ...

最新文章

  1. Mysql: pymysql 模块
  2. [转载]深入探索.NET框架内部了解CLR如何创建运行时对象
  3. Apache SparkStreaming 简介和编程模型
  4. [Usaco2008 Oct]灌水
  5. Java程序员从笨鸟到菜鸟之(一百零六)java操作office和pdf文件(四)页面列表导出cvs,excel、pdf报表.
  6. Oracle 11g RAC features
  7. 在 VS 类库项目中 Add Service References 和 Add Web References 的区别
  8. 暗黑2战网服务器爆率修改,暗黑2修改MOD最初级基础
  9. 工业大数据分析综述:模型与算法
  10. C++ 实现把非静态成员函数作为回调函数(非static)
  11. 解决Windows资源管理器右键菜单打开EditPlus容易导致资源管理器无响应问题
  12. 拓端tecdat|matlab使用分位数随机森林(QRF)回归树检测异常值
  13. StyTr^2:Image Style Transfer with Transformers
  14. 华硕x205ta小本驱动下载页面
  15. 【转】Photoshop中快速复制的技巧有哪些
  16. 看完《百家讲坛》之后的108个经典“留言”
  17. 购物小票的巧妙新设计
  18. 英汉《营销学》常用词汇-1
  19. linux下github上传文件,linux下将本地文件上传到github中?
  20. 微信开放平台、公众平台、公众号和小程序开发【原创】

热门文章

  1. 带你认识4种设计模式:代理模式、装饰模式、外观模式和享元模式
  2. 【华为云技术分享】测试微课堂 | 有的放矢制定测试计划
  3. 大型情感剧集Selenium:2_options设置 #华为云·寻找黑马程序员#
  4. 华为云微服务应用平台服务能力业界领先,通过微服务标准首批评估
  5. 多个数字数组_九章算法 | 谷歌面试题:多个数组的交集
  6. WPS关于尾注的细节
  7. pytorch之mnist数据集存放位置以及本地加载
  8. scipy.sparse.csr_matrix函数和coo_matrix函数
  9. 从零开始学Pytorch(十三)之梯度下降
  10. 【java基础知识】swagger组件常用命令