📄 mff_equalizer_generator.m
字号:
%% Main GUI file
%%
% Most of this was created by GUIDE, so comments will be sparse.
function varargout = MFF_Equalizer_Generator(varargin)
%%
% MFF_EQUALIZER_GENERATOR M-file for MFF_Equalizer_Generator.fig
% MFF_EQUALIZER_GENERATOR, by itself, creates a new MFF_EQUALIZER_GENERATOR or raises the existing
% singleton*.
%
% H = MFF_EQUALIZER_GENERATOR returns the handle to a new MFF_EQUALIZER_GENERATOR or the handle to
% the existing singleton*.
%
% MFF_EQUALIZER_GENERATOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MFF_EQUALIZER_GENERATOR.M with the given input arguments.
%
% MFF_EQUALIZER_GENERATOR('Property','Value',...) creates a new MFF_EQUALIZER_GENERATOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MFF_Equalizer_Generator_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MFF_Equalizer_Generator_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 MFF_Equalizer_Generator
% Last Modified by GUIDE v2.5 04-Apr-2008 10:53:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MFF_Equalizer_Generator_OpeningFcn, ...
'gui_OutputFcn', @MFF_Equalizer_Generator_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 MFF_Equalizer_Generator is made visible.
function MFF_Equalizer_Generator_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 MFF_Equalizer_Generator (see VARARGIN)
% Choose default command line output for MFF_Equalizer_Generator
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MFF_Equalizer_Generator wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MFF_Equalizer_Generator_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)
global lowest_freq
global highest_freq
global q0;
global n_filters;
global hbp;
global r1;
global r2;
global r5;
global c3;
global c4;
global w0;
global options;
%% Logging
%%
% The time of the calculation is logged. This is fairly worthless, but
% could be expanded in a later version.
D = now;
date_time = datestr(D,0);
f = fopen(strcat(cd,'/EQ_gen_log.txt'),'a');
fprintf(f,'Time Start ');
fprintf(f,date_time);
fprintf(f,'\n\n');
%%
%% Parameter and component calculations
%%
% First, the filter parameters are calculated based on the user input, then
% the comopnents are calculated. Both of these actions are recorded to the
% log, and an error message, if applicable, is displayed.
fprintf(f,'Calculating filter parameters...\n');
[w0,q0,hbp,n] = calc_parameters(lowest_freq,highest_freq,q0,hbp,n_filters);
fprintf(f,'Calulating component values....\n');
[r1,r2,r5,c3,c4,error_msg] = calc_components(q0,w0,hbp,options);
if(length(error_msg) > 93)
errordlg(error_msg,'Try changing the options...','modal');
fprintf(f,'Error: ');
fprintf(f,error_msg);
fprintf(f,'\n');
end
%%
% --------------------------------------------------------------------
function plots_top_Callback(hObject, eventdata, handles)
% hObject handle to plots_top (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Magnitude plot menu item
% --------------------------------------------------------------------
function mag_plot_Callback(hObject, eventdata, handles, x, y)
% hObject handle to mag_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global q0;
global n_filters;
global hbp;
global w0;
[filter_mag,filter_phase,w0_vector] = calc_transfer(w0,q0,hbp,n_filters);
mag_plot_handle = figure;
semilogx(w0_vector/(2*pi),20*log10(filter_mag));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Output Magnitude vs. Frequency');
% --------------------------------------------------------------------
%%
%% Phase plot menu item
function phase_plot_Callback(hObject, eventdata, handles)
% hObject handle to phase_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global q0;
global n_filters;
global hbp;
global w0;
[filter_mag,filter_phase,w0_vector] = calc_transfer(w0,q0,hbp,n_filters);
phase_plot_handle = figure;
semilogx(w0_vector/(2*pi),filter_phase);
xlabel('Frequency (Hz)');
ylabel('Phase (rads)');
title('Filter Phase vs. Frequency');
%%
% --------------------------------------------------------------------
function spice_top_Callback(hObject, eventdata, handles)
% hObject handle to spice_top (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Write SPICE file menu item
% --------------------------------------------------------------------
function gen_net_Callback(hObject, eventdata, handles)
% hObject handle to gen_net (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global r1;
global r2;
global r5;
global c3;
global c4;
global w0;
global n_filters;
f = fopen(strcat(cd,'/EQ_gen_log.txt'),'a');
fprintf(f,'Generating SPICE file...\n');
write_spice_file(r1,r2,r5,c3,c4,w0,n_filters)
%%
% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function online_manual_Callback(hObject, eventdata, handles)
% hObject handle to online_manual (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
web http://www.msu.edu/~hatchsea/mff_equalizer_generator.pdf
%% Low frequency input
%%
%For this input, the string is converted to a double, and validated.
%**************************************************************************
%Low Freq Input Callback function:
%**************************************************************************
% 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
function edit1_Callback(hObject, eventdata, handles)
global lowest_freq;
lowest_freq = str2double(get(hObject,'string'));
if isnan(lowest_freq)
errordlg('You must enter a numeric value','Bad Input','modal')
end
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
%%
%% High frequency input
%**************************************************************************
%High Freq Input Callback function:
%**************************************************************************
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
global highest_freq;
highest_freq = str2double(get(hObject,'string'));
if isnan(highest_freq)
errordlg('You must enter a numeric value','Bad Input','modal')
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -