附录
%GUI源程序
function varargout = untitled(varargin) % UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*. %
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*. %
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments. %
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_OpeningFcn via varargin. %
% *See GUI Options on GUIDE's Tools menu. Choose \allows only one
% instance to run (singleton)\ %
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 02-Jan-2017 21:00:51
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
10
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_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 untitled (see VARARGIN)
% Choose default command line output for untitled handles.output = hObject;
% Update handles structure guidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_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
11
MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- 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) [s,fs]=audioread ('C:\\Users\\昊东\\Desktop\\zhd.wav');%读取语音信号的数据,赋给变量y 信号 频率
y1=fft(s);
plot(handles.axes1,s)
plot(handles.axes5,abs(y1))
% --- 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) [s,fs]=audioread ('C:\\Users\\昊东\\Desktop\\zhd.wav');%读取语音信号的数据,赋给变量y 信号 频率
12
y1=fft(s);
f=fs*(0:511)/2048;%使频谱图的坐标从零开始
t=0:1/44100:(size(s)-1)/44100; %将所加噪声信号的点数调整到与原始信号相同 Au=0.08; %幅度值
d=Au*cos(2*pi*5000*t); %加余弦信号 频率是5000hz n=d';%将噪声进行转置,以便使噪声与信号的行列相同,进行相加 x=s+n;%原始信号和噪声信号叠加 y2=fft(x);%进行2048点傅里叶变换
plot(handles.axes2,x)
plot(handles.axes6,abs(y2))
% --- 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) [s,fs]=audioread ('C:\\Users\\昊东\\Desktop\\zhd.wav');%读取语音信号的数据,赋给变量y 信号 频率
t=0:1/44100:(size(s)-1)/44100; %将所加噪声信号的点数调整到与原始信号相同 Au=0.08; %幅度值
d=Au*cos(2*pi*5000*t); %加余弦信号 频率是5000hz n=d';%将噪声进行转置,以便使噪声与信号的行列相同,进行相加 x=s+n;%原始信号和噪声信号叠加
wp=0.08*pi;ws=0.1*pi; %两个频率的信号
Rp=1;Rs=15;Fs=44100;Ts=1/Fs;%阻带衰减和通带衰减,中间是过渡区,
13
采样频率44100
wp1=2/Ts*tan(wp/2);%将数字指标转换成模拟指标 ws1=2/Ts*tan(ws/2);
[N,Wn]=buttord(wp1,ws1,Rp,Rs,'s');%选择滤波器的最小阶数 [Z,P,K]=buttap(N);%创建butterworth模拟滤波器 [Bap,Aap]=zp2tf(Z,P,K); [b,a]=lp2lp(Bap,Aap,Wn);
[bz,az]=bilinear(b,a,Fs);%用双线性变换法实现模拟滤波器到数字滤波器的转换
[H,W]=freqz(bz,az);%绘制频率响应曲线 y=filter(bz,az,x);%调用上边滤波器函数
F0=fft(y);
plot(handles.axes3,x)
plot(handles.axes7,abs(F0))
% --- 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) [s,fs]=audioread ('C:\\Users\\昊东\\Desktop\\zhd.wav');
sound(s,fs);
% --- 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) [s,fs]=audioread ('C:\\Users\\昊东\\Desktop\\zhd.wav');%读取语音信号的数据,赋给变量y 信号 频率 y1=fft(s);
f=fs*(0:511)/2048;%使频谱图的坐标从零开始
14