Main GUI file
Contents
- Logging
- Parameter and component calculations
- Magnitude plot menu item
- Phase plot menu item
- Write SPICE file menu item
- Low frequency input
- High frequency input
- Number of filters input
- Quality input
- Passband gain input
- Minimum resistor value
- Maximum capacitor value
- Minimum capacitor value
- Maximum capacitor value
Most of this was created by GUIDE, so comments will be sparse.
function varargout = EQFilters(varargin)
EQFILTERS M-file for EQFilters.fig EQFILTERS, by itself, creates a new EQFILTERS or raises the existing singleton*.
H = EQFILTERS returns the handle to a new EQFILTERS or the handle to
the existing singleton*. EQFILTERS('CALLBACK',hObject,eventData,handles,...) calls the local
function named CALLBACK in EQFILTERS.M with the given input arguments. EQFILTERS('Property','Value',...) creates a new EQFILTERS or raises the
existing singleton*. Starting from the left, property value pairs are
applied to the GUI before EQFilters_OpeningFunction gets called. An
unrecognized property name or invalid value makes property application
stop. All inputs are passed to EQFilters_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 EQFilters % 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', @EQFilters_OpeningFcn, ... 'gui_OutputFcn', @EQFilters_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 EQFilters is made visible. function EQFilters_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 EQFilters (see VARARGIN) % Choose default command line output for EQFilters handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes EQFilters wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = EQFilters_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) % -------------------------------------------------------------------- function about_Callback(hObject, eventdata, handles) % hObject handle to about (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
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 % --- 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
Number of filters input
%************************************************************************** %Number of Filters Input Callback function: %************************************************************************** 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 global n_filters; n_filters = str2double(get(hObject,'string')); if isnan(n_filters) errordlg('You must enter a numeric value','Bad Input','modal') end % --- 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
Quality input
For this input, the program does diffeent things based on whether the user inputs a scalar or vector. If the user inputs a vector, the code conceptualizes it as such.
%************************************************************************** %Quality Input Callback function: %************************************************************************** function edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double global n; global q0; quality_input = get(hObject,'string'); quality_input2 = regexp(quality_input, ' ', 'split'); if (length(quality_input2) == 0) q0 = str2num(quality_input) else q0 = cellfun(@str2num,quality_input2) end function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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
Passband gain input
Again, the user can enter a scalar or a vector here.
%************************************************************************** %Passband Gain Callback function: %************************************************************************** function edit5_Callback(hObject, eventdata, handles) % hObject handle to edit5 (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 edit5 as text % str2double(get(hObject,'String')) returns contents of edit5 as a double %global n; global hbp; passband_gain_input = get(hObject,'string'); passband_gain_input2 = regexp(passband_gain_input, ' ', 'split'); hbp = cellfun(@str2num,passband_gain_input2) if (length(passband_gain_input2) == 0) hbp = str2num(passband_gain_input) else hbp = cellfun(@str2num,passband_gain_input2) end function edit5_CreateFcn(hObject, eventdata, handles) % hObject handle to edit5 (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
Minimum resistor value
The minimum resistor value is stored to the first index in the options vector.
function edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double global options; options(1) = str2double(get(hObject,'string')) % --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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
Maximum capacitor value
options(4) holds the maximum capacitor value
function edit12_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double global options; options(4) = str2double(get(hObject,'string')) % --- Executes during object creation, after setting all properties. function edit12_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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
Minimum capacitor value
options(3) holds the minimum capacitor value
function edit11_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double global options; options(3) = str2double(get(hObject,'string')) % --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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
Maximum capacitor value
options(2) holds the maximum capacitor value.
function edit10_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double global options; options(2) = str2double(get(hObject,'string')) % --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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
