matlab音乐合成报告.doc
MATLAB音乐合成报告姓名:学号:专业:集成电路设计与集成系统课程名称:信号与系统学院:通信工程学院目录一、本实验及背景介绍二、设计过程1、没加谐波的初步设计2、加谐波后的分析三、实验感悟一、本实验及背景介绍从物理的角度看,音乐是不同频率,不同时长声波的组合,声波的频率表示不同的音调,声波的时长反映不同的节奏,根据该原理,将不同频率,不同时长的声波进行有序组合,则能成为音乐,利用MATLAB对不同频路信号的组合及分析功能,能够进行简单的音乐合成。本次音乐合成所作曲目为《粉红的记忆》简谱如下:二、设计过程1、没加谐波的初步设计原程序如下fs=8000;a=349.23;b=392.00;c=440.00;d=439.88;e=523.25;f=587.33;a1=1046.5;f0=239.66;e0=261.63;a0=1396.9;b1=1174.7;f=[1550.0a1568.0293.66e1760.01568.01396.9f1396.9eeeeefacbabafaae0af0e0af0e0abcbabeeeeefeceffa1fefbbafbbafefabaeeefe0a1feeefe0eeefafececbce0bbbcb0babbaf0afe0abceffa1feee0fa1fa1fef0efcecbba1a0];%各个音乐对应的频率time=fs*[0.375,0.125,0.375,0.125,0.25,0.25,1/8,1/8,0.25,1,1/4,1/4,1/4,1/4,0.25,1/8,1/10,1/4,1/4,1/4,0.125,0.125,1/4,1/4,0.125,0.375,0.01,1/2,1/4,1/4,1/2,1/4,1/4,1/4,1/4,1/8,1/8,1/4,1,1/4,1/4,1/4,1/4,1/4,1/8,1/8,1/4,1/4,1/4,1/8,1/8,1/4,1/4,1,0.58,1/6,0.125,1/4,0.55,1/6,1/7,1/4,1/4,1/4,1/4,1/4,1,0.475,0.125,1/4,1/4,1/4,1/4,1/4,0.25,0.405,1/8,0.17,1/8,1/2,0.475,0.126,0.25,1/4,0.512,0.31,1/4,1/4,1/8,1/8,1/4,1/4,0.375,0.125,0.375,0.125,1/4,1/4,1/4,1/4,1/4,1/4,0.125,1/4,0.125,1/4,1/4,1/8,0.375,0.375,1/8,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1,1/2,1/2,1/8,0.375,1/8,0.375,1/4,1/4,1/2,0.55,0.215,1/8,1/8,0.375,1/4,1/4,1/8,0.375,0.25,1/4];%各个音乐的抽样点数N=length(time);%总的抽样点数east=zeros(1,N);%存储抽样点n=1;fornum=1:N%利用for循环产生抽样数据,num表示音乐的编号t=1/fs:1/fs:(time(num))/fs;%产生第num个音乐的抽样点east(n:n+time(num)-1)=sin(2*pi*f(num)*t);%给第num个音乐加包络n=n+time(num);endsound(2*east,8000);plot(east);所的波形如下在刚才的音乐中听到有“啪”的杂声,下面通过加包络来消噪音。最简单的包络为指数衰减。最简单的指数衰减是对每个音乘以因子,在实验中首先加的是的衰减,这种衰减方法使用的是相同速度的衰减,但是发现噪音并没有完全消除,播放的音乐效果不是很好,感觉音乐起伏性不强。于是采用不同速度的衰减,根据乐音持续时间的长短来确定衰减的快慢,乐音持续时间越长,衰减的越慢,持续时间越短,衰减的越快。在1.1程序的基础上加上包络,编写如下程序:fs=8000;a=349.23;b=392.00;c=440.00;d=439.88;e=523.25;f=587.33;a1=1046.5;f0=239.66;e0=261.63;a0=1396.9;b1=1174.7;f=[1550.0a1568.0293.66e1760.01568.01396.9f1396.9eeeeefacbabafaae0af0e0af0e0abcbabeeeeefeceffa1fefbbafbbafefabaeeefe0a1feeefe0eeefafececbce0bbbcb0babbaf0afe0abceffa1feee0fa1fa1fef0efcecbba1a0];%各个音乐对应的频率time=fs*[0.375,0.125,0.375,0.125,0.25,0.25,1/8,1/8,0.25,1,1/4,1/4,1/4,1/4,0.25,1/8,1/10,1/4,1/4,1/4,0.125,0.125,1/4,1/4,0.125,0.375,0.01,1/2,1/4,1/4,1/2,1/4,1/4,1/4,1/4,1/8,1/8,1/4,1,1/4,1/4,1/4,1/4,1/4,1/8,1/8,1/4,1/4,1/4,1/8,1/8,1/4,1/4,1,0.58,1/6,0.125,1/4,0.55,1/6,1/7,1/4,1/4,1/4,1/4,1/4,1,0.475,0.125,1/4,1/4,1/4,1/4,1/4,0.25,0.405,1/8,0.17,1/8,1/2,0.475,0.126,0.25,1/4,0.512,0.31,1/4,1/4,1/8,1/8,1/4,1/4,0.375,0.125,0.375,0.125,1/4,1/4,1/4,1/4,1/4,1/4,0.125,1/4,0.125,1/4,1/4,1/8,0.375,0.375,1/8,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1,1/2,1/2,1/8,0.375,1/8,0.375,1/4,1/4,1/2,0.55,0.215,1/8,1/8,0.375,1/4,1/4,1/8,0.375,0.25,1/4];%各个音乐的抽样点数N=length(time);%总的抽样点数east=zeros(1,N);%存储抽样点n=1;G=zeros(1,time(num));%G为存储包络数据的向量G(1:time(num))=exp(1:(-1/time(num)):1/8000);%产生包络点east(n:n+time(num)-1)=sin(2*pi*f(num)*t).*G(1:time(num));sound(100000*east,8000);plot(east);播放后可以听出噪音已经消除,同时因为不同时长的乐音衰减的快慢不一样,音乐听起来更有起伏感,下图是加包络后的east图像。更科学的包络如下图所示,每个乐音都经过冲激、衰减、持续、消失四个阶段。由上图可以看出这个包络是四段直线段构成的,因此只要确定了每段线段的端点,即可