ch6.m
来自「基于MATLAB与VC混合编程的数字均衡器的设计」· M 代码 · 共 913 行 · 第 1/3 页
M
913 行
function varargout = ch6(varargin)
% CH6 M-file for ch6.fig
% CH6, by itself, creates a new CH6 or raises the existing
% singleton*.
%
% H = CH6 returns the handle to a new CH6 or the handle to
% the existing singleton*.
%
% CH6('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CH6.M with the given input arguments.
%
% CH6('Property','Value',...) creates a new CH6 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ch6_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ch6_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help ch6
% Last Modified by GUIDE v2.5 31-Oct-2007 19:33:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ch6_OpeningFcn, ...
'gui_OutputFcn', @ch6_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 ch6 is made visible.
function ch6_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 ch6 (see VARARGIN)
% Choose default command line output for ch6
handles.output = hObject;
handles.fband=[20 100 200 500 1000 2000 4000 8000 16000];
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ch6 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ch6_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 WAVopen.
function WAVopen_Callback(hObject, eventdata, handles)
% hObject handle to WAVopen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.wav', 'Pick an WAVE-file');
if isequal(filename,0)
disp('User selected Cancel')
else
set(handles.reading,'Visible','on');
set(handles.reading,'String','Reading...');
disp(['User selected', fullfile(pathname, filename)])
[handles.y handles.Fs bits]=wavread(filename);
handles.y=handles.y(:,1);
guidata(hObject,handles);
set(handles.reading,'String',sprintf('%dHz,%2.2fs',handles.Fs,length(handles.y)/handles.Fs));
set(handles.filt,'Enable','on');
set(handles.play,'Enable','on');
end
% --- Executes on button press in AUopen.
function AUopen_Callback(hObject, eventdata, handles)
% hObject handle to AUopen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.au', 'Pick an AU-file');
if isequal(filename,0)
disp('User selected Cancel')
else
set(handles.reading,'Visible','on');
disp(['User selected', fullfile(pathname, filename)])
[handles.y handles.Fs bits]=auread(filename);
guidata(hObject,handles);
set(handles.reading,'Visible','off');
set(handles.filt,'Enable','on');
set(handles.play,'Enable','on');
end
% --- Executes on button press in filt.
function play_Callback(hObject, eventdata, handles)
% hObject handle to filt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(handles.addmode,'Value')==1
wavplay(handles.y,handles.Fs,'async');
else
set(handles.filt,'Enable','off');
pause(0.01);
wavplay(handles.y,handles.Fs,'sync');
set(handles.filt,'Enable','on');
end
% --- Executes on button press in startrecord.
function startrecord_Callback(hObject, eventdata, handles)
% hObject handle to startrecord (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.startrecord,'Enable','off');
pause(0.01);
Fs=str2double(get(handles.recordFs,'String'));
recordtime=str2double(get(handles.recordtime,'String'));
handles.Fs=Fs;
handles.y=wavrecord(recordtime*Fs,Fs,'int16');
set(handles.startrecord,'Enable','on');
set(handles.filt,'Enable','on');
set(handles.play,'Enable','on');
% --- Executes on button press in gensquare.
function gensquare_Callback(hObject, eventdata, handles)
% hObject handle to gensquare (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Fs=44100;
N=44100;
x=linspace(0,N/Fs,N);
x=x';
frequency=str2double(get(handles.genfrequence,'String'));
amp=str2double(get(handles.genamp,'String'));
phase=0;
handles.y=amp*sign(sin(2*pi*x*frequency+phase));
handles.Fs=Fs;
guidata(hObject,handles);
set(handles.filt,'Enable','on');
set(handles.play,'Enable','on');
% --- Executes on button press in filterplay.
function filterplay_Callback(hObject, eventdata, handles)
% hObject handle to filterplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.filterplay,'Enable','off');
pause(0.01);
N=size(handles.yy);
N=N(1);
% step=0.1;
% n=handles.Fs*step;
n=4096;
step=n/handles.Fs;
from=1;
to=n;
ymax=max(handles.y);
ymin=min(handles.y);
f=linspace(0,handles.Fs/2,n/2);
fband=handles.fband;
num=length(fband)-1;
tic
while to<=N;
y=handles.yy(from:to,:);
pause(step-toc*0.99);
wavplay(y,handles.Fs,'async');
tic
P=fft(y,n);
Pyy =2*abs(P)/n;
loglog(handles.axes1,f,Pyy(1:n/2));
axis(handles.axes1,[fband(1) fband(num+1) 1e-3 ymax]);
for i=1:num
yb(i)=60+20*log10(mean(Pyy(floor(fband(i)*n/handles.Fs):floor(fband(i+1)*n/handles.Fs))));
end
bar(handles.axes3,yb);
ylim(handles.axes3,[0 60]);
plot(handles.axes2,y);
ylim(handles.axes2,[ymin ymax]);
from=from+n;
to=to+n;
end
set(handles.filterplay,'Enable','on');
% --- Executes on button press in filt.
function save_Callback(hObject, eventdata, handles)
% hObject handle to filt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile('*.wav', 'WAVE-file');
if isequal(filename,0) | isequal(pathname,0)
disp('User selected Cancel')
else
set(handles.save,'Enable','off');
disp(['User selected',fullfile(pathname,filename)])
wavwrite(handles.yy,handles.Fs,filename);
set(handles.save,'Enable','on');
end
% --- Executes on button press in fileinput.
function fileinput_Callback(hObject, eventdata, handles)
% hObject handle to fileinput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of fileinput
set(handles.WAVopen,'Enable','on');
set(handles.AUopen,'Enable','on');
set(handles.startrecord,'Enable','off');
set(handles.recordFs,'Enable','off');
set(handles.recordtime,'Enable','off');
set(handles.genfrequence,'Enable','off');
set(handles.genamp,'Enable','off');
set(handles.gensquare,'Enable','off');
% --- Executes on button press in recordinput.
function recordinput_Callback(hObject, eventdata, handles)
% hObject handle to recordinput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of recordinput
set(handles.WAVopen,'Enable','off');
set(handles.AUopen,'Enable','off');
set(handles.startrecord,'Enable','on');
set(handles.recordFs,'Enable','on');
set(handles.recordtime,'Enable','on');
set(handles.genfrequence,'Enable','off');
set(handles.genamp,'Enable','off');
set(handles.gensquare,'Enable','off');
function recordFs_Callback(hObject, eventdata, handles)
% hObject handle to recordFs (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 recordFs as text
% str2double(get(hObject,'String')) returns contents of recordFs as a double
% --- Executes during object creation, after setting all properties.
function recordFs_CreateFcn(hObject, eventdata, handles)
% hObject handle to recordFs (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function recordtime_Callback(hObject, eventdata, handles)
% hObject handle to recordtime (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 recordtime as text
% str2double(get(hObject,'String')) returns contents of recordtime as a double
% --- Executes during object creation, after setting all properties.
function recordtime_CreateFcn(hObject, eventdata, handles)
% hObject handle to recordtime (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function band1_Callback(hObject, eventdata, handles)
% hObject handle to band1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?