音符频率对应表

音符 频率/HZ 半周期/us 音符 频率/HZ 半周期/us
低1DO 262 1908 #4FA# 740 0676
#1DO# 277 1805 中5SO 784 0638
低2RE 294 1700 #5SO# 831 0602
#2RE# 311 1608 中6LA 880 0568
低3M 330 1516 #6LA# 932 0536
低4FA 349 1433 中7SI 988 0506
#4FA# 370 1350 高1DO 1046 0478
低5SO 392 1276 #DO# 1109 0451
#5SO# 415 1205 高2RE 1175 0426
低6LA 440 1136 #2RE# 1245 0402
#6LA# 466 1072 高3M 1318 0372
低7SI 494 1012 高4FA 1397 0358
中1DO 523 0956 #4FA# 1480 0338
#1DO# 554 0903 高5SO 1568 0319
中2RE 578 0842 #5S0# 1661 0292
#2RE# 622 0804 高6LA 1760 0284
中3M 659 0759 #6LA# 1865 0268
中4FA 698 0716 高7SI 1976

("#"表示半音,用于上升或下降半个音)

我们知道用Matlab的sound函数可以发声,但是那种声音是很难听的“电话铃声”,那该怎么模拟成钢琴音色呢?

每个音符有固定的基音频率,表格如上。

matlab实测

接下来,我们打开matlab

f=440;
fs=8000;
t=1/fs:1/fs:1;
x=sin(2*pi*f*t);
sound(x,fs);

这样点击运行的话,是一声电话音,但是知道频率的话,我们就可让它发出音乐的声音了

fs = 4000;t = (0:1500)*(1/fs);
f=294;
y = cos(2*pi*f*t);
sound(y,fs);

上面的程序是dao音

y=1;
fs = 4000;t = (0:1500)*(1/fs);
f1=262;
y1 = cos(2*pi*f1*t);
%sound(y1,fs);
f2=294;
y2 = cos(2*pi*f2*t);
%sound(y2,fs);
f3=330;
y3 = cos(2*pi*f3*t);
%sound(y3,fs);
f4=349;
y4 = cos(2*pi*f4*t);
%sound(y4,fs);
f5=392;
y5 = cos(2*pi*f5*t);
%sound(y5,fs);
f6=440;
y6 = cos(2*pi*f6*t);
%sound(y6,fs);
f7=494;
y7 = cos(2*pi*f7*t);
%%%%%%%%%y=[y1,y2,y3,y4,y5,y6,y7];
%%%%%%%%%sound(y,fs);
k=0;
A=input('请输入"[]",中间带空格');
for i=1:length(A) %MATLAB下标从1开始switch(A(i))case 1%y=[y1];sound(y1,fs);pause(0.5);case 2%y=[y2];sound(y2,fs);pause(0.5);case 3%y=[y3];sound(y3,fs);pause(0.5);case 4%y=[y4];sound(y4,fs);pause(0.5);case 5%y=[y5];sound(y5,fs);pause(0.5);case 6%y=[y6];sound(y6,fs);pause(0.5);case 7%y=[y7];sound(y7,fs);pause(0.5);end% sound(y,fs);
end


运行即可发声,而且输入“1234567789”等任意音符对应的数字也可以发出“dao ruai mi fa。。。”进行***音符识别***
下面展示gui版本

function varargout = duolaimi2(varargin)
% DUOLAIMI2 MATLAB code for duolaimi2.fig
%      DUOLAIMI2, by itself, creates a new DUOLAIMI2 or raises the existing
%      singleton*.
%
%      H = DUOLAIMI2 returns the handle to a new DUOLAIMI2 or the handle to
%      the existing singleton*.
%
%      DUOLAIMI2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DUOLAIMI2.M with the given input arguments.
%
%      DUOLAIMI2('Property','Value',...) creates a new DUOLAIMI2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before duolaimi2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to duolaimi2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help duolaimi2% Last Modified by GUIDE v2.5 17-Mar-2020 21:31:13% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
global h;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @duolaimi2_OpeningFcn, ...'gui_OutputFcn',  @duolaimi2_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end% --- Executes just before duolaimi2 is made visible.
function duolaimi2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to duolaimi2 (see VARARGIN)% Choose default command line output for duolaimi2
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes duolaimi2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end% --- Outputs from this function are returned to the command line.
function varargout = duolaimi2_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structure
varargout{1} = handles.output;
end% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=262;
n=1;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
end% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=294;
n=2;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
end% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=330;
n=3;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
end% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=349;
n=4;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
end% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=392;
n=5;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
end% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=440;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
%i=i+1;
end% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fs = 4000;t = (0:1500)*(1/fs);
f=494;
n=7;
global h;
y = cos(2*pi*f*t);
sound(y,fs);
set(handles.edit1,'String',n);
h(n,:)=y;
%i=i+1;
endfunction edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
%x=str2double(get(handles.edit1,'String'));
%x=num2str(x,'%04d')-'0';
x=str2num(get(handles.edit1,'String')');
Fs=44100;
t=0:1/Fs:0.5;
p1=cos(2*pi*261*t);
p2=cos(2*pi*293.66*t);
p3=cos(2*pi*329.63*t);
p4=cos(2*pi*349.23*t);
p5=cos(2*pi*392.00*t);
p6=cos(2*pi*440.00*t);
p7=cos(2*pi*493.88*t);
p0=cos(2*pi*0*t);
for i=1:length(x)switch(x(i))case 1sound(p1,Fs);pause(0.5);case 2sound(p2,Fs);pause(0.5);case 3sound(p3,Fs);pause(0.5);case 4sound(p4,Fs);pause(0.5);case 5sound(p5,Fs);pause(0.5);case 6sound(p6,Fs);pause(0.5);case 7sound(p7,Fs);pause(0.5);case 0pause(0.5);end
end
end% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end
end% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

Matlab模拟钢琴识别琴谱GUI相关推荐

  1. 基于Matlab的虹膜识别系统(GUI界面)

    点击查看:基于Matlab的虹膜识别系统(GUI界面) 文件大小:56M 操作系统:Windows10旗舰版 开发工具:Matlab2016.2018.2019.2020 开发语言:.m 代码注释:

  2. 基于MATLAB的人脸识别系统GUI

    基于MATLAB的人脸识别系统GUI,可以识别出不同表情的人脸 演示视频:[基于matlab人脸识别系统-哔哩哔哩] https://b23.tv/Pj8j0Uu 运行截图: 源码获取+卫星:DX52 ...

  3. matlab 二值化_基于MATLAB的指纹识别系统[GUI界面+万字技术文档+语音播报]

    一.课题介绍 本设计为基于MATLAB的指纹识别系统.本设计系统主要对指纹图像进行三方面处理:图像预处理.特征提取和特征匹配.图像预处理包括四个步骤:图像灰度化.滤波增强.二值化.细化,对指纹图像进行 ...

  4. matlab speex的语音处理模块_基于MATLAB的条形码识别系统[GUI,可识别几十个图片]...

    1.1 应用MATLAB识别条形码总体设计 本设计为基于MATLAB的条形码识别系统,带有一个GUI界面. GUI设计界面 1.1.1 程序总体设计思路 在上节中我们简单的介绍了MATLAB的发展以及 ...

  5. 钢琴的音色特点用matlab描述6,如何使用matlab模拟钢琴音色?

    有网友说想用MATLAB模拟钢琴音,于是我尝试写了一段,供大家参考.复制代码可直接运行. function Dian_Zi_Qin() clc;clear; P=[1 2 3 4 5 6 7 8 9 ...

  6. 基于MATLAB答题卡识别(GUI,论文)

    本课题为基于MATLAB的不变矩答题卡识别.可识别学号,学科,答案,并进行分数统计,以及判断是否及格.后台可设置标准excel答案.经过灰度变换形成灰度图像.二值化处理.图像滤波.边缘检测.hough ...

  7. matlab模拟钢琴演奏

    本文是信号与系统的一个大作业 需要掌握的知识有: 简单乐理知识 matlab基本操作

  8. matlab 仿真钢琴,用Matlab模拟钢琴的声音

    这是某位牛人写的代码,贴到matlab里听听看.<卡农>!!! % Cripple Pachebel's Canon on Matlab % Have fun fs = 44100; % ...

  9. 【电磁】基于Matlab模拟电偶极子电磁场附GUI界面

    ​ ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进.

最新文章

  1. C++入门经典-例6.14-通过指针连接两个字符数组
  2. C#写webservice(2)
  3. Java实现话术词槽匹配_桔子互动|百度UNIT操作详解(上篇)
  4. 【Android Gradle 插件】settings.gradle 配置文件 ( 配置基本作用 | include 函数用法 | 目录层级配置 | 修改 Module 模块构建脚本名称 )
  5. 两大主流Web服务器之分析与对比
  6. swift 网络请求中含有特殊字符的解决方案
  7. word List18
  8. 韩国FSC公布新方案允许分离银行加密业务 以帮助小型交易所继续运营
  9. 15、三数之和(python)
  10. HTMLCSS入门学习
  11. 单片机拟真电路图软件_DIY AT89S52单片机编程器
  12. 常用的monkey命令
  13. 【软件工程】——软工视频总结
  14. 一场无名的宿醉,失措了一夜的安然。
  15. 【Rust日报】2022-07-06 Android 平台中的 Rust
  16. 2023最新SSM计算机毕业设计选题大全(附源码+LW)之java校园新闻发布管理系统574ec
  17. 数据分析---arXiv论文数据统计
  18. STM32CubeMX学习笔记(22)——CRC接口使用
  19. java -- 随机获取字母或者数字
  20. Linus 命名 [冰封荒原] 版 Linux 内核的思考

热门文章

  1. Vue的自学之路(三)
  2. c++学习 | MFC —— 串口通信(四)发送数据
  3. VS+OpenCV+VC超详细的配置教程
  4. mechanize 是 pthon 的并且可编程的 浏览器插件,
  5. java 怎么让打印信息换行?
  6. 数据,数据对象,数据元素,数据项的关系图
  7. 我带着 chatGPT 做了 2800 道算法题
  8. 搜索引擎shodan
  9. window nginx关闭后,访问代理仍成功
  10. 'utf-8' codec can't decode byte 0xca in position 94: invalid continuation byte问题