function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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 main
% Last Modified by GUIDE v2.5 25-Dec-2017 23:52:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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;
% --- 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)
%---------------------------利用函数wavread对语音信号的采集--------------------------------%
global wav_in;
global wav_in_1;
global Fs;
global bits;
global n;
global f1;
[filename pathname]=uigetfile({'*.wav'}, 'File Selector');
[wav_in,Fs,bits] = wavread([pathname '\' filename]);
handles.wav_in = wav_in;
guidata(hObject, handles);
axes(handles.axes1);
% aa=abs(fftshift(wav_in));
% plot(aa);title('')
N=length(wav_in);
n=0:N-1;
plot(n,wav_in); %画出原始语音信号的波形
xlabel('n');
ylabel('x(n)');
title('原始语音信号');
f1=fft(wav_in,N); %对语音号进行快速傅里叶变换,得出频谱
% GX=fft(wav_in,512);
sound(wav_in,Fs);
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)
global wav_in;
global wav_in_1;
global Fs;
global bits;
global n;
global f1;
% SNR=40;
% wav_in=awgn(wav_in,SNR);
y1=fft(wav_in,512);
f=Fs*(0:511)/512;
Au=0.03;
wav_in=wav_in(:,1);
t=0:1/Fs:(size(wav_in)-1)/Fs;%将所加噪声信号的点数调整到与原始信号相同
d=[Au*cos(2*pi*5000*t)]';%噪声为5kHz的余弦信号
wav_in_1=10*wav_in+d;
y2=fft(wav_in_1,512);
handles.wav_in = wav_in_1;% ¨¨¨
guidata(hObject, handles);
axes(handles.axes2);
plot(t,wav_in_1)
title('加噪后的信号');
xlabel('time n');
ylabel('fuzhi n');
guidata(hObject, handles);
axes(handles.axes3);
plot(abs(n),abs(f1));
xlabel('k');
ylabel('|y(k)|');
title('FFT后的波形');
% guidata(hObject, handles);
% axes(handles.axes3);
% plot(f,abs(y1(1:512)));
% title('原始语音信号频谱');
% xlabel('Hz');
% ylabel('fuzhi');
guidata(hObject, handles);
axes(handles.axes4);
plot(f,abs(y2(1:512)));
title('加噪后的信号频谱');
xlabel('Hz');
ylabel('fuzhi');
sound(wav_in_1,Fs);
% --- 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)
global wav_in;
global wav_in_1;
global Fs;
global bits;
mc(wav_in_1,Fs,bits,hObject, handles)
% --- 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)
global wav_in;
global wav_in_1;
global Fs;
global bits;
sx(wav_in_1,Fs,bits,hObject, handles)
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)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- 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
% --- 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)
close(gcf);
评论0