MATLAB程序设计报告--基于MATLAB动画播放及音乐播放
Matlab课程设计报告--MATLAB GUI的音乐键盘仿真

《 MATLAB 实践》课程设计目录1.设计目的 (3)2.题目分析 (3)3.总体设计 (4)4.具体设计 (4)5.结果分析 (15)6.心得体会 (15)1、设计目的:运用MATLAB实现MATLAB的GUI程序设计。
2、题目分析:课程设计题目:MATLAB GUI的音乐键盘仿真课程设计的基本要求:1)熟悉和掌握MATLAB 程序设计方法。
2)掌握MATLAB GUI 程序设计。
3)学习音乐合成基本知识。
设计分析:这次使用的设计软件是MATLAB的GUI模块,要设计一个音乐键盘要知道一个最简单的键盘本身要有36个发音键,既21个音阶和15个辅音阶。
于是就要在界面上画出36个pushbutton键,再根据其他要求的功能设计出其他相应的模块。
模拟键盘发音是使用音频函数soundsc将不同频率的函数以声音的模式表现出来,而每个音阶相差频率f=440*2^2/12;音阶与相应的辅音阶相差频率f=440*2^1/12。
有了音乐合成的这些基本知识后便可根据自己需要设计界面根据功能编写相应的回调函数。
课程设计的内容:学习MATLAB GUI程序设计,设计和实现一个音乐键盘仿真系统。
要求:按照软件工程方法,根据需求进行程序的功能分析和界面设计,给出设计详细说明。
然后按照自己拟定的功能要求进行程序设计和调试。
1)设计音乐键盘GUI界面,实现单音键盘的发声。
2)实现键盘的双音多频,即每个键盘对应低音频组的一个频率和高音频组的一个频率,实现按键的发出双音。
3)能改变音乐包络形式,实现音型的改变。
4)能够演奏一段音乐。
5)改变键盘的音色,给基音加上泛音序列,模拟不同的乐器演奏。
6)选作:根据节奏节拍,根据简谱自动演奏一段音乐。
3、总体设计其中琴键区域实现按键发声,可用鼠标点击,也可以用键盘实现;显示屏区域实现声音波形的实时显示;控制区域实现对整个系统的控制,包括音乐播放、暂停、停止,视屏播放,乐器切换,节拍切换和谐波切换。
matlab程序设计实验报告

实验报告课程名称:可视化计算机语言实验项目名称:matlab程序设计学院:信息工程学院专业:电子信息工程指导教师:报告人:学号:班级:实验时间:实验报告提交时间:教务部制一、实验目的与要求:1、熟练掌握matlab的程序流程控制结构..2、熟悉掌握M文件的结构和函数调用..3、掌握内联函数和函数句柄的使用..4、了解程序性能剖析窗口..二、内容和步骤:MATLAB的语法规则简洁;编程效率高;作为一个完整的程序语言;MATLAB也有各种程序流程控制;文件格式和函数调用的规则;通过对函数的调用就能够组成庞大的程序;完成复杂的功能..1.使用程序流程控制Fibonacci数列的各元素为:1、1、2、3、5、8、...满足一下关系F1=1 F2=1 F n=F n-1+F n-2用M函数文件实现;数列的元素个数为输入变量..(1)按M函数文件格式创建文件开头..function f=shiyan0501n%SHIYAN0501%Fibonacci数列%n 元素个数%f 构成Fibonacci数列向量%%copyright 2015-11-25(2)用while循环实现程序功能f1=1;f2=1;i=2;while i<=nfi+1=fi-1+fi;i=i+1;End运行后;输入参数10;运行结果如下所示:(3)使用for循环实验for i=2:nfi+1=fi-1+fi;end运行结果如下所示:(4)当某个元素大于50时;退出循环结构;程序修改如下:for i=2:nif fi>10breakelsefi+1=fi-1+fi;endend当某个元素大于50;程序便退出循环结构当n=10;最后一个元素刚好是大于50的;正好退出循环结构当n=12时;第十个元素对应的fi大于50;于是退出循环结构;不再运行f11;f12了..(5)将该.m文件生成P码文件>> pcode shiyan0501将shiyan0501.m删除;重新运行该文件夹;结果如下所示:练习:将该M文件函数改为M脚本文件;将数列元素个数通过键盘输入;程序应该如何修改①将M文件函数另存为M脚本文件;②在函数前加n=input'please input a num:'便可通过键盘键入文件f=mf;endk=f1/2^2n1f^22n1+1;end调用程序shiyan0502;运行结果如下所示:>> y=shiyan05020.7y =0.7754运行结果与使用子函数factorial的运行结果一致..(4)使用程序性能剖析..选择菜单‘view’->‘profile’命令;或使用在命令窗口输入‘profile viewer’命令都可以打开程序性能剖析窗口..在程序性能剖析窗口的‘命令输入栏’中输入需要剖析的命令;‘y=shiyan05020.7’;然后单击‘start profiling’按钮;查看剖析报告..(5)程序的调试..当有多个函数调用时;由于函数变量的工作空间是独立的;被调用的函数执行结束后变量消失;因此调试时要使用matlab调试器查看运行过程中的变量值..①设置断点..在需要查看的程序的地方设置断点;>> shiyan05020.7K>> yy =0.7000K>> x=0.5x =0.5000在K>>输入x=0.5即可将x的值从0.7修改为0.5.去除断点;查看结果:ans =0.7236结果与x值为0.7时不一致;当x=0.7时;y =0.7754;由此可知;x的值已被修改..②单步运行>> shiyan05020.79 n=n+1;K>>按单步运行键:可看到箭头不断的移动:6使用函数句柄..在命令窗口使用函数句柄调用函数..>> h_shiyan0502=shiyan0502h_shiyan0502 =shiyan0502>> y=fevalh_shiyan0502;0.5y =0.5236(7)使用全局变量..Matlabe的编程不提倡使用全局变量;本例中的程序主要是为了查看全局变量的概念..将n 作为全局变量;子函数factorial不修改;子函数cal程序和主函数shiyan0502修改如下:function y=shiyan0502x%shiyan0502 arcsinxglobal n;n=1;if absx<1y=x;while caln>0.0001y=y+calnx^2n+1;n=n+1;endelsedisp'输入错误';y=0;returnendfunction k=caln1global nfor m=1:nk=factorial2n/2^2nfactorialn^222n+1;Endglobal为设置的全局变量;子函数没有输入变量;而用全局变量n传递..在全局变量前设置断点;然后运行程序;当程序运行到断点处停止;接着不断使用单步运行调试;结果如下所示:|||练习:使用单步运行调试;查看全局变量n的变化;并在工作空间查看n;3、利用泛函命令实现数值分析①创建函数shiyan0503实现上述表达式关系..function y=shiyan0503t%shiyan0503 y=sint.^2.expat-babsta=0.1;b=0.5;y=sint.^2.expat-babst;②查看该函数的输出波形;如下图所示:注:1、报告内的项目或内容设置;可根据实际情况加以调整和补充..2、教师批改学生实验报告时间应在学生提交实验报告时间后10日内..。
基于matlab的声音文件播放器设计_毕业论文设计[管理资料]
![基于matlab的声音文件播放器设计_毕业论文设计[管理资料]](https://img.taocdn.com/s3/m/a878f5ecde80d4d8d05a4f13.png)
实验3 Matlab程序设计1实验报告

实验3 Matlab程序设计1实验报告I am going to write the report for the Matlab program design experiment 3. In this experiment, I was required to use Matlab to design a program to solve a specific problem.I had to write the program, test it, and then write areport on the results.First, I started by analyzing the problem and breaking it down into smaller, more manageable parts. This is a crucial step in programming, as it allows me to understand the problem fully and come up with an effective solution. Once I had a clear understanding of the problem, I began writing the program in Matlab.I encountered some challenges along the way, such as debugging errors and optimizing the code for efficiency. However, with some perseverance and problem-solving skills, I was able to overcome these challenges and successfully write the program.After writing the program, I tested it with different inputs to ensure that it produced the correct outputs inall cases. Testing is an essential part of programming, asit helps to identify and fix any errors or bugs in the code.Once the program was tested and working correctly, I wrote a report on the results. In the report, I explainedthe problem, my approach to solving it, and the results of the program. I also included any insights or observations that I gained from working on the program.Overall, this experiment was a valuable learning experience for me. It allowed me to practice my programming skills and problem-solving abilities, and it also gave me a better understanding of how to use Matlab for real-world applications.中文回答:我要写实验3的Matlab程序设计实验报告。
基于MatlabGUI的音乐播放器设计

基于Matlab/GUI的音乐播放器设计作者:燕丽红来源:《现代电子技术》2015年第08期摘要:随着社会大数据化的提出,数据分析时要求能使用一种快速、简洁、高效的软件进行数据处理工作,其中Matlab软件就是一种有效的分析工具。
利用Matlab强大的仿真和数据分析功能,通过编程M文件和Matlab GUI界面设计进行了音乐播放器的设计,其中M文件编程可以播放任意歌曲,GUI界面设计的播放器具有音乐播放、暂停、单音播放、多音播放、视频播放、歌词显示等功能。
实践表明,在教学上采用Matlab软件进行系统设计具有良好的实用性,也可以很直观、方便地进行人机交互,教学效果良好。
关键词: M文件; Matlab/GUI;数据分析功能;人机交互中图分类号: TN911⁃34; G642 文献标识码: A 文章编号: 1004⁃373X(2015)08⁃0114⁃03Design of music player based on Matlab/GUIYAN Li⁃hong(Information Engineering College,Xi’an Eurasia University,Xi’an 710065, China)Abstract: with the occurrence of the big⁃datamation, the rapid, simple and efficient softwares are required to realize data processing when carrying out data analysis, in which the Matlab software is an effective analysis tool. With powerful simulation and data analysis function of Matlab, the music player was designed by means of M file programming and Matlab GUI interface design. The M file programming can play any song, and the player designed with GUI interface has the functions of play, pause, monophonic music play, multitone play, video playback, lyrics display, etc. The practice shows that the Matlab software for system design has good practicability in teaching, with which man⁃machine interaction can be realized intuitively and expediently, and the perfect teaching effect can be achieved.Keywords: M File; Matlab/GUI; data analysis function; man⁃machine interaction0 引言Matlab是美国MathWorks公司设计的数学软件,主要包括Matlab/Simulink和GUI设计两大部分[1⁃2]。
matlab程序设计实验报告

matlab程序设计实验报告《MATLAB程序设计实验报告》摘要:本实验报告旨在介绍MATLAB程序设计的基本原理和实践操作,通过实验演示和分析,展示了MATLAB在工程领域的应用和重要性。
本报告详细介绍了MATLAB程序设计的基本语法和常用函数,以及如何利用MATLAB进行数据处理、图像处理、信号处理等工程应用。
通过本报告的学习,读者将能够掌握MATLAB程序设计的基本技能,为工程实践提供有力的支持。
1. 引言MATLAB是一种用于算法开发、数据可视化、数据分析和数值计算的高级技术计算语言和交互式环境。
它具有强大的数学计算功能和丰富的绘图工具,广泛应用于工程、科学和金融等领域。
本实验报告将介绍MATLAB程序设计的基本原理和实践操作,帮助读者快速掌握MATLAB的基本技能。
2. 实验目的本实验的主要目的是让读者了解MATLAB程序设计的基本语法和常用函数,掌握MATLAB在工程领域的应用和重要性。
通过实验演示和分析,展示MATLAB 在数据处理、图像处理、信号处理等方面的应用。
3. 实验内容(1)MATLAB程序设计的基本语法和常用函数(2)利用MATLAB进行数据处理的实验演示(3)利用MATLAB进行图像处理的实验演示(4)利用MATLAB进行信号处理的实验演示4. 实验步骤(1)学习MATLAB程序设计的基本语法和常用函数(2)编写MATLAB程序,实现数据处理、图像处理、信号处理等功能(3)进行实验演示和分析,展示MATLAB在工程领域的应用和重要性5. 实验结果与分析通过本实验的学习,读者将能够掌握MATLAB程序设计的基本技能,包括数据处理、图像处理、信号处理等方面的应用。
通过实验演示和分析,读者将了解MATLAB在工程领域的重要性,为工程实践提供有力的支持。
6. 结论MATLAB程序设计是一种强大的工程工具,具有广泛的应用前景。
通过本实验报告的学习,读者将能够掌握MATLAB程序设计的基本技能,为工程实践提供有力的支持。
MATLAB程式设计入门篇音讯读写录制与播放Audio

Volume (音量): the amplitude of audio signals
Also known as intensity, or energy.
Pitch (音高): Fundamental frequency (the number of fundamental periods in a second) in audio signals.
0.2
0.1
0
-0.1
-0.2
-0.3
0
0.5
1
1.5
Enlarge to see fundamental periods!
MATLAB 程式設計入門篇:音訊讀寫、錄製與播放
中介資料
Read Metadata from .wav Files
Reading metadata
info=audioInfo('file'); Different types of audio files may return different fields of info.
張智星 (Roger Jang) 台大資訊系 多媒體檢索實驗室 CSIE/NTU, MIR Lab
MATLAB 程式設計入門篇:音訊讀寫、錄製與播放
音訊的基本介紹
聲音訊號(Audio Signals)簡稱音訊,泛指由人耳 聽到的各種聲音的訊號。 音訊的基本聲學特徵
音量(Volume):聲音的大小稱為音量,又稱為力度、強度 (Intensity)或是能量(Energy)。音量越大,代表音訊波形的震幅 越大。 音高(Pitch):聲音的基本頻率(Fundamental Frequency)越高, 代表音高越高(例如女高音的歌聲);反之,聲音的基本頻率越低, 代表音高越低(例如男低音的歌聲)。 音色(Timbre):音訊波形在每個週期內的變化,就形成了此音訊的 音色。不同的音色即代表不同的音訊內容,例如不同的字有不同的發 音,或是不同的歌手有不同的特色,這些都是由於音色不同而產生。
基于MATLAB的音乐分析与合成演示程序的设计

科技风2021年2月科技创新DOI:10. 19392/ki.1671-7341.202104011基于MATLAB的音乐分析与合成演示程序的设计毛艺晓王志鹏#南阳师范学院物理与电子工程学院河南南阳473061摘要:利用MATLABGUI平台,设计了一个音乐分析与合成综合演示系统。
用户通过简单的鼠标点击操作,就可以实现音乐载入、波形显示、频域分析、音乐合成以及音频播放等一系列功能。
该演示系统可以让用户更直观地理解音乐信号分析与合成的基本原理,激发对音频信号分析和处理的兴趣。
关键词:MATLAB#音乐分析与合成;傅里叶变换Desij^n of demonstration program of music analysisand composition based on MATLABMao Yixiao Wang Zhipeng#College of physics and Electronic Engineering,Nanyang Normal University HenanNanyang473061 Abstract:Using Matlab GUI platform,a music analysis and synthesis integrated demonstration system is designed.Through mouse click operation,users can achieve a series of functions such as music loading,waveform disf)lay,frequency domain analysis,music synthesis and audio playback.The demo system can make users understand the basic principle of m more intuitively and stimulate their interest in audio signal analysis and processing.Key words :MATLAB;music analysis and synthesis;Fourier transform1绪论MATLAB是是矩阵实验室(Matrix Laboratory)的简称,是 美国MahWoks公司出品的商业数学软件,可以进行矩阵运 算、绘制函数和数据、实现算法、创建用户界面、连接其他编 程语言的程序等,在信号处理领域已得到广泛的应用[1]。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《MATLAB程序设计》课程设计报告设计题目:基于MATLAB的动画演示及背景音乐插入专业:2011级通信工程姓名(学号):储兆雄1162310213邓少林1162310214徐凯越1162310223指导教师:倪建军(博士/副教授)时间:2013年12月20日目录1、设计目的2、总体设计3、具体设计(功能实现)4、结果分析5、改进方向6、心得体会文献附录1、设计目的学会运用matlab工具箱实现matlab GUI设计,处理动画运行,以及添加背景音乐,并实现其动态操作,如继续、暂停等功能。
2、总体设计主要包括:动画模块,音乐模块,动画显示模块3、具体设计(功能实现)1) 动画模块(1)打开动画文件:从文件打开对话框选择动画程序,实现动画播放的可选择性程序实现代码如下:function btnvopen_Callback(hObject, eventdata, handles)% hObject handle to btnvopen (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vfname %动画文件名[vfname vpname vindex]=uigetfile('*.m','choose moive file');len=length(vfname);if vindexset(handles.txtvname,'string',vfname(1:len-2))end打开对话框效果如下:(2)开始动画播放:先获取文件名称vfname(1:len-2),然后用run()命令来执行程序实现代码如下:function btnvstart_Callback(hObject, eventdata, handles)% hObject handle to btnvstart (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vfnametrylen=length(vfname);run(vfname(1:len-2));catchmsgbox('sorry, there are some error while playing movie!','NOTICING');end以下是其中两个动画程序snow动画%***************设置背景****************************%A=imread('H:\YOU.jpg');h=figure;imshow(A);axesaxis([0 1 0 1]);axis off;set(gcf,'color','k');N=20;handles=zeros(1,N);x=rand(2,N);fontsize=floor(rand(1,N)*17+32);new_handles_N=0;%绘图for i=1:Nhandles(i)=text(x(1,i),x(2,i),'*','fontsize',fontsize(i),'color','w');endwhile 1if ~ishandle(h)returnendfor i=1:Ntemp=get(handles(i),'position');step=get(handles(i),'fontsize')/48*0.05;if temp(2)<0new_handles_N=new_handles_N+1;new_handles(new_handles_N)= copyobj(handles(i),gca);if new_handles_N==500delete(new_handles);new_handles_N=0;endtemp(1)=rand(1);temp(2)=1;elsetemp(1)=temp(1)+rand(1)*0.1-0.05;temp(2)=temp(2)-step;endset(handles(i),'position',temp,'rotation',get(handles(i),'rotation')+5);endpause(.2)end简单程序动画tryMovie=moviein(16);for k=1:16plot(fft(eye(k+16)))axis equalaxis offM(k)=getframe;endmovie(M,30);catchmsgbox('sorry, there are some error while playing movie!','NOTICING');end动画效果如下:(3)暂停/继续功能:获取pause按钮string参数,实现暂停和继续播放功能的切换,而通过timerPause()函数来实现其功能程序实现代码如下:function btnvpause_Callback(hObject, eventdata, handles)% hObject handle to btnvpause (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global symPausetryif strcmp(get(handles.btnvpause,'string'),'pause')handles.timer1 = timer('Period', 0.1, 'ExecutionMode','singleShot','timerFcn', {@timerPause});set(handles.btnvpause,'string','continue')start(handles.timer1);elseif strcmp(get(handles.btnvpause,'string'),'continue')symPause =0;set(handles.btnvpause,'string','pause')endcatchmsgbox('sorry, there are some error while excuting thefunction!','NOTICING','error');endfunction timerPause(hObject,eventdata,handles)global symPausesymPause=1;while symPause==1pause(1)end(4)添加文字function btnvshow_Callback(hObject, eventdata, handles)% hObject handle to btnvshow (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tryif get(handles.txtvword,'string')set(handles.stxtshow,'string',get(handles.txtvword,'string'),...'visible','on','fontname','¿¬Ìå','fontsize',12.0);elseset(handles.stxtshow,'visible','off');msgbox('Add some words first!');endcatchmsgbox('sorry, there are some error while excuting thefunction!','NOTICING','error');end2)音乐模块(1)打开音乐function btnmbrowse_Callback(hObject, eventdata, handles)% hObject handle to btnmbrowse (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global mfilepathtry[mfname mpname mindex]=uigetfile('*.wav','choose music');if mindexmfilepath=[mpname mfname];set(handles.edit1,'string',mfilepath);endcatchmsgbox('Error,while importing music£¡','NOTICING','error'); end(2)播放音乐function btnstart_Callback(hObject, eventdata, handles)% hObject handle to btnstart (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global mfilepath player signsign='false';tryif mfilepath~=0[data,Fs,nbits]=wavread(mfilepath);elsetry[data,Fs,nbits]=wavread('you are a song in my heart.wav');catchmsgbox('sorry,the default music does not exist','NOTICING');endendplayer=audioplayer(data,Fs,nbits);play(player);sign='ture';set(handles.btnmpause,'string','pause','Enable','on');catchmsgbox('Rrror while playing music!','NOTICING');end(3)暂停/继续功能function btnmpause_Callback(hObject, eventdata, handles)% hObject handle to btnmpause (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtryif strcmp(get(handles.btnmpause,'string'),'pause')pause(player);set(handles.btnmpause,'string','continue');elseif strcmp(get(handles.btnmpause,'string'),'continue')resume(player);set(handles.btnmpause,'string','pause');endcatchmsgbox('sorry, there are some error while excuting thefunction!','NOTICING');end(4)停止播放音乐function btnmstop_Callback(hObject, eventdata, handles)% hObject handle to btnmstop (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtrystop(player);sign='false';set(handles.btnmpause,'string','pause','Enable','off');catchmsgbox('ERROR','NOTICING');end3)其他辅助功能(1)关闭程序:在退出程序时,音乐不会自动停止,所以为了在退出程序时同时关闭音乐,才加入此功能function figure1_DeleteFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtryif strcmp(sign,'true')stop(player);close allendcatchmsgbox('sorry, there are some error while excuting thefunction!','NOTICING','error');end(2)异常捕捉机制try-catch由于程序功能再设计上考虑的并不是十分全面,可能会出现预料不到的错误,因此加入此功能,避免在出现未知错误时,程序崩溃。