function varargout = gangbadai(varargin)
% GANGBADAI M-file for gangbadai.fig
% GANGBADAI, by itself, creates a new GANGBADAI or raises the existing
% singleton*.
%
% H = GANGBADAI returns the handle to a new GANGBADAI or the handle to
% the existing singleton*.
%
% GANGBADAI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GANGBADAI.M with the given input arguments.
%
% GANGBADAI('Property','Value',...) creates a new GANGBADAI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gangbadai_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gangbadai_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 gangbadai
% Last Modified by GUIDE v2.5 17-Nov-2012 12:26:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gangbadai_OpeningFcn, ...
'gui_OutputFcn', @gangbadai_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 gangbadai is made visible.
function gangbadai_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 gangbadai (see VARARGIN)
% Choose default command line output for gangbadai
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gangbadai wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gangbadai_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)
%he=get(handles.edit2,'string');
[filename,pathname]=uigetfile('*.wav','选择一个声音文件');
voice=[pathname,filename];
[y,fs,nbits]=wavread(voice);
N= length(y)
% [y,fs,nbits]=wavread('E:\kaoyan.wav');
set(handles.edit2,'string',fs);
set(handles.edit3,'string',N);%%%131072是2的17次方
axes(handles.axes1);
plot(y);grid;
title('原始信号时域波形');
axes(handles.axes2);
w = linspace(-fs/2,fs/2,N);
plot(w,fftshift(abs(fft(y))));grid;
title('原始信号频域波形');
setappdata(handles.figure1,'y',y);
setappdata(handles.figure1,'fs',fs);
setappdata(handles.figure1,'nbits',nbits);
setappdata(handles.figure1,'N',N);
% --- 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)
%b1=getappdata(handles.figure1,'b1');
y=getappdata(handles.figure1,'y');
fs=getappdata(handles.figure1,'fs');
nbits=getappdata(handles.figure1,'nbits');
sound(y,fs,nbits);
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 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)
N=getappdata(handles.figure1,'N');
b=getappdata(handles.figure1,'b');
y=getappdata(handles.figure1,'y');
fs=getappdata(handles.figure1,'fs');
nbits=getappdata(handles.figure1,'nbits');
b1=filter(b,1,y);
axes(handles.axes1);
plot(b1);
title('滤波信号时域波形');
axes(handles.axes2);
w = linspace(-fs/2,fs/2,N);
plot(w,fftshift(abs(fft(b1))));
title('滤波信号频域波形');
% sound(b1,fs);
setappdata(handles.figure1,'b1',b1);
% --- Executes on selection change in xiala.
function xiala_Callback(hObject, eventdata, handles)
% hObject handle to xiala (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns xiala contents as cell array
% contents{get(hObject,'Value')} returns selected item from xiala
value=get(handles.xiala,'value');
y=getappdata(handles.figure1,'y');
switch value
case 2
Ft=4000;
Fp=get(handles.edit_3,'string') ;
Fp=str2num(Fp);
Fs=get(handles.edit_4,'string');
Fs=str2num(Fs);
wp=2*Fp/Ft;
ws=2*Fs/Ft;
As=get(handles.edit_1,'string');As=str2num(As);
wdel = ws - wp; %过渡带宽
Wn = (wp + ws)/2 ; %截止频率即Wc % N取奇数
M=ceil((As-7.95)/(2.285*wdel)+1)+1;
axes(handles.axes3);
b = fir1(M-1,Wn,kaiser(M,11));
[h1,w1]=freqz(b,1);
plot(w1/pi,20*log10(abs(h1)));
axis([0,1,-140,10]);
grid;
xlabel('归一化频率/p') ;
ylabel('幅度/dB') ;
case 3
Ft=20000; %最高截止频率要低于2000
Fp=get(handles.edit_4,'string') ;
Fp=str2num(Fp);