【数字信号】简易电子琴(英文版)【含GUI Matlab源码 873期】

在这里插入图片描述

⛄一、获取代码方式

获取代码方式1:
完整代码已上传我的资源: 【数字信号】基于matlab GUI简易电子琴(英文版)【含Matlab源码 873期】
点击上面蓝色字体,直接付费下载,即可。

获取代码方式2:
付费专栏Matlab信号处理(初级版)

备注:
点击上面蓝色字体付费专栏Matlab信号处理(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab信号处理(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码

⛄二、案例简介

.m是MATLAB源代码文件,.fig是MATLAB的GUI文件,.jpg和.wav分别是一张图和一段语音,是项目所需的资源文件。
在程序最开始,会默认打开目录中的.wav文件,播放一段语音,内容就是“welcome to my piano”。后面还有一个label,它显示的内容也是这句话,label的标志是一个笑脸,就是目录中的.jpg文件。之后就进入了程序的正式界面。
上方标题之下是2个坐标面板,左右分别显示当前琴音的时域、频域波形。右侧框内显示了琴音的频率数值,当前按下的是小字一组的g(so音),其频率为392Hz。下面的单选框是选择坐标值有无虚线网格。下方的按键是对应计算机键盘作出来的,因为当时的初步想法是按下某一个键盘就响起对应的琴音,但是后来没能实现,所以只好老老实实地用鼠标点击。我一共是作了5组音键:大字组、小字组、小字一组、小字二组、小字三组,频率由低变高。

⛄三、部分源代码

%---------Designer:Tang Men-------%
%-----------Time:02.05.2021--------------%

function varargout = MyPiano(varargin)
% MYPIANO MATLAB code for MyPiano.fig
% MYPIANO, by itself, creates a new MYPIANO or raises the existing
% singleton*.
%
% H = MYPIANO returns the handle to a new MYPIANO or the handle to
% the existing singleton*.
%
% MYPIANO(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in MYPIANO.M with the given input arguments.
%
% MYPIANO(‘Property’,‘Value’,…) creates a new MYPIANO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MyPiano_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MyPiano_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 MyPiano

% Last Modified by GUIDE v2.5 15-Jul-2017 13:18:02

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @MyPiano_OpeningFcn, …
‘gui_OutputFcn’, @MyPiano_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% — Executes just before MyPiano is made visible.
function MyPiano_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 MyPiano (see VARARGIN)

% Choose default command line output for MyPiano
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MyPiano wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = MyPiano_OutputFcn(hObject, eventdata, handles)
smile1 = imread(‘smile1.jpg’);
s = ‘Welcome To MyPiano!’;
hs = msgbox(s,‘Welcome!’,‘custom’,smile1);
ht = findobj(hs, ‘Type’, ‘text’); %change the size of words
set(ht, ‘FontSize’, 12, ‘Unit’, ‘normal’,‘FontName’,‘Times New Roman’);
%position [a b c d]determine the position of the msgbox, [a b] represent the coordinate of the point
% in the lower left quarter,c and d respectively express the width and height of the msgbox.
%It will show the former msgbox,setting proper coordinate will make the latter msgbox cover the former one.
set(hs,‘Position’,[480 380 280 80]);
fn = uigetfile(‘WelcomeToMyPiano.wav’,‘Open File’);
[y,fs] = audioread(fn);
sound(y,fs);
varargout{1} = handles.output;

%function dawy(y,t)
function drawy(y,t)
%Vectors must be the same length.but the time frame showed in the axes can be adjusted,like number’100’can be changed
plot(t(1:100),y(1:100));
xlabel(‘time (s)’);ylabel(‘amplitude’);
zoom on;

%function drawfft(y,fs)
function drawfft(y,fs)
N=1024; % make a self-defined drawfft(y,N,fs)
fy=fft(y,N); fy=abs(fy);
f=(0:N/2-1)*fs/N;
plot(f,fy(1:N/2));
xlabel(‘Frequency (Hz)’);ylabel(‘amplitude’);
zoom on;

function pushbutton1_Callback(hObject, eventdata, handles)
global fs t
%To control time frame to 3/8 s,make fs as 4000 in order to limite the frame of frequency to 1-2000,
%and this range is suitable for the biggest frequency 1975.5 Hz
fs = 4000;t = (0:1500)(1/fs);
f=65.4;
y = cos(2
pift);
sound(y);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f); %pay attention to the function set

function pushbutton2_Callback(hObject, eventdata, handles)
global fs t
f=73.4;
y = cos(2pif*t);
sound(y);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton3_Callback(hObject, eventdata, handles)
global fs t
f=82.4;
y = cos(2pif*t);
sound(y);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton4_Callback(hObject, eventdata, handles)
global fs t
f=87.3;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton5_Callback(hObject, eventdata, handles)
global fs t
f=98.0;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton6_Callback(hObject, eventdata, handles)
global fs t
f=110.0;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton7_Callback(hObject, eventdata, handles)
global fs t
f=123.5;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton11_Callback(hObject, eventdata, handles)
global fs t
f=130.8;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton12_Callback(hObject, eventdata, handles)
global fs t
f=146.8;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton13_Callback(hObject, eventdata, handles)
global fs t
f=164.8;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton14_Callback(hObject, eventdata, handles)
global fs t
f=174.6;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

function pushbutton15_Callback(hObject, eventdata, handles)
global fs t
f=196.0;
y = cos(2pif*t);
sound(y,fs);
axes(handles.axes1);
drawy(y,t);
axes(handles.axes2);
drawfft(y,fs);
set(findobj(‘Tag’,‘edit1’),‘String’,f);

⛄四、运行结果

在这里插入图片描述

⛄五、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]李伟国.简易电子琴的设计[J].电子世界. 2010(10)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

  • 25
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab领域

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值