function varargout = untitled1(varargin)
% UNTITLED1 MATLAB code for untitled1.fig
% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing
% singleton*.
%
% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to
% the existing singleton*.
%
% UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED1.M with the given input arguments.
%
% UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled1_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 untitled1
% Last Modified by GUIDE v2.5 15-Nov-2020 16:40:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn, ...
'gui_OutputFcn', @untitled1_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 untitled1 is made visible.
function untitled1_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 untitled1 (see VARARGIN)
% Choose default command line output for untitled1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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;
function Re=Relation(X,N)%定义自相关函数
for i=0:(N-1)
Re(i+1)=0;
for n=1:(N-i)
Re(i+1)=Re(i+1)+X(n)*X(n+i);
end
end
function drawy(y,t) %定义时域谱画图函数
plot(t(1:100),y(1:100)); %画出时间为1到100,频率为1到100的时域片段
xlabel('时间');ylabel('幅度');%x轴和y轴加标签
title('时域谱');%加标题
zoom on;
%function drawfft(y,fs)
function drawfft(y,fs) %定义幅度谱画图函数
N=1024; % 采样点数
fy=fft(y,N); fy=abs(fy); %对采样信号做N点fft变换,取其幅度
f=(0:N/2-1)*fs/N; %使f和fy长度相同
plot(f,fy(1:N/2));%画图
xlabel('频率 (Hz)');ylabel('幅度');%x轴和y轴加标签
title('幅度谱');%加标题
zoom on;
function drawangle(y,fs) %定义相位谱画图函数
N=1024;
n=0:N-1;
t=n/fs;
Y=fft(y,N);%对采样信号fft变换
f=n*fs/N;%确定频率
ph=2*angle(Y(1:N/2));%利用angle函数求出每个点的角度
ph=ph*180/pi;%由角度转化成弧度
plot(f(1:N/2),ph(1:N/2));%画出相位图
xlabel('频率/hz'),ylabel('相角'),title('相位谱');
grid on;
%%% --- DO.
function pushbutton1_Callback(hObject, eventdata, handles)
fs = 4000;t = (0:1500)*(1/fs);
f=262;%do的频率
n=1;
y = cos(2*pi*f*t);
sound(y,fs);%发音do
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','DO的频率为262HZ');
% --- RE.
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;%发音re
n=2;
y = cos(2*pi*f*t);
sound(y,fs);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','RE的频率为294HZ');
% --- MI.
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;
y = cos(2*pi*f*t);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','MI的频率为330HZ');
% --- FA.
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;
y = cos(2*pi*f*t);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','FA的频率为349HZ');
% --- SO.
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;
y = cos(2*pi*f*t);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','SO的频率为392HZ');
% --- LA.
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;
n=7;
y = cos(2*pi*f*t);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','LA的频率为440HZ');
% --- XI.
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;
y = cos(2*pi*f*t);
sound(y,fs);
axes(handles.axes2);
drawy(y,t);
axes(handles.axes3);
drawfft(y,fs);
axes(handles.axes4);
drawangle(y,fs);
set(handles.edit1,'String','XI的频率为494HZ');
% --- 弹谱子.
function pushbutton8_Callback(hObject, eventdata, handles)
x=str2num(get(handles.edit1,'String')');
fs = 4000;t = (0:1500)*(1/fs);
p=[261 293.66 329.63 349.23 392.00 440.00 493.88 0];
for i=1:length(x)
P=cos(2*p(x(i))*pi*t);
sound(P,fs);
axes(handles.axes2);
drawy(P,t);
axes(handles.axes3);
drawfft(P,fs);
axes(handles.axes4);
drawangle(P,fs);
end
% --- edit1输谱子处文本.
function 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)
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata res
评论0