📄 guilistfrequencyresponse.m
字号:
function varargout = GuiListFrequencyResponse(varargin)
% GUILISTFREQUENCYRESPONSE M-file for GuiListFrequencyResponse.fig
% GUILISTFREQUENCYRESPONSE, by itself, creates a new GUILISTFREQUENCYRESPONSE or raises the existing
% singleton*.
%
% H = GUILISTFREQUENCYRESPONSE returns the handle to a new GUILISTFREQUENCYRESPONSE or the handle to
% the existing singleton*.
%
% GUILISTFREQUENCYRESPONSE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUILISTFREQUENCYRESPONSE.M with the given input arguments.
%
% GUILISTFREQUENCYRESPONSE('Property','Value',...) creates a new GUILISTFREQUENCYRESPONSE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GuiListFrequencyResponse_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GuiListFrequencyResponse_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 GuiListFrequencyResponse
% Last Modified by GUIDE v2.5 27-Dec-2003 07:09:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GuiListFrequencyResponse_OpeningFcn, ...
'gui_OutputFcn', @GuiListFrequencyResponse_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 GuiListFrequencyResponse is made visible.
function GuiListFrequencyResponse_OpeningFcn(hObject, eventdata, handles, varargin)
% hObject handle to figure
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GuiListFrequencyResponse (see VARARGIN)
handles.output = hObject; % Choose default command line output for GuiListFrequencyResponse
global strFilterObject
% Load data
if isempty(strFilterObject)
temp=load('matlab');
disp([mfilename ' called in debug mode using matlab.mat datafile'])
strFilterObject = temp.strFilterObject;
end
strFilterObject=Utility_zpk(strFilterObject); % find poles, zeros
set(handles.uiFigure,'Name',strFilterObject.sTitle)
% initialize the ui widgets to the cutoff frequency
if strFilterObject.fFc >= 1e6
set(handles.uipmF1,'Value',4)
set(handles.uitxF1, 'String', num2str(strFilterObject.fFc/1e6))
set(handles.uipmF2,'Value',4)
set(handles.uitxF2, 'String', num2str(strFilterObject.fFc/1e6))
elseif strFilterObject.fFc >= 1000
set(handles.uipmF1,'Value',3)
set(handles.uitxF1, 'String', num2str(strFilterObject.fFc/1e3))
set(handles.uipmF2,'Value',3)
set(handles.uitxF2, 'String', num2str(strFilterObject.fFc/1e3))
elseif strFilterObject.fFc >= 1
set(handles.uipmF1,'Value',2)
set(handles.uitxF1, 'String', num2str(strFilterObject.fFc))
set(handles.uipmF2,'Value',2)
set(handles.uitxF2, 'String', num2str(strFilterObject.fFc))
elseif strFilterObject > 0
set(handles.uipmF1,'Value',1)
set(handles.uitxF1, 'String', num2str(strFilterObject.fFc*1000))
set(handles.uipmF2,'Value',1)
set(handles.uitxF2, 'String', num2str(strFilterObject.fFc*1000))
else
error('Fc in strFilterObject is negative')
end
set(handles.uitxStatus,'String','Find the filter response at up to two different frequencies');
% Update handles structure
guidata(hObject, handles);
Recalculate1(handles)
Recalculate2(handles)
% --- Outputs from this function are returned to the command line.
function varargout = GuiListFrequencyResponse_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UI Widget Handlers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function uitxF1_Callback(hObject, eventdata, handles)
global strFilterObject
num=str2double(get(hObject,'String'));
if isnan(num)
errordlg('Enter a numeric freqnency at which to examine the filter''s response','Error')
set(hObject,'String',sprintf('%g',strFilterObject.fFc))
elseif num < 0
errordlg('The frequency must be postive','Error')
set(hObject,'String',sprintf('%g',strFilterObject.fFc))
else
set(hObject,'String',sprintf('%g',num))
end
Recalculate1(handles)
function uitxF2_Callback(hObject, eventdata, handles)
global strFilterObject
num=str2double(get(hObject,'String'));
if isnan(num)
errordlg('Enter a numeric freqnency at which to examine the filter''s response','Error')
set(hObject,'String',sprintf('%g',strFilterObject.fFc))
elseif num < 0
errordlg('The frequency must be postive','Error')
set(hObject,'String',sprintf('%g',strFilterObject.fFc))
else
set(hObject,'String',sprintf('%g',num))
end
Recalculate2(handles)
function uipmF1_Callback(hObject, eventdata, handles)Recalculate1(handles)
function uipmF2_Callback(hObject, eventdata, handles)Recalculate2(handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Recalculate1(handles)
global strFilterObject
% get the data
z = strFilterObject.vZeros;
p = strFilterObject.vPoles;
k = strFilterObject.fK;
f = str2num(get(handles.uitxF1,'String'))*10^((get(handles.uipmF1,'Value')-2)*3);
% do the calculations
w=f*2*pi;
H = k*prod(j*w-z)/prod(j*w-p);
magH = abs(H);
dBH = 20*log10(magH);
radH = angle(H);
degH = radH*180/pi;
% post the data
set(handles.uitxF1Mag,'String',sprintf('%g',magH))
set(handles.uitxF1MagDb,'String',sprintf('%g',dBH))
set(handles.uitxF1AngleDeg,'String',sprintf('%g',degH))
set(handles.uitxF1AngleRad,'String',sprintf('%g',radH))
function Recalculate2(handles)
global strFilterObject
% get the data
z = strFilterObject.vZeros;
p = strFilterObject.vPoles;
k = strFilterObject.fK;
f = str2num(get(handles.uitxF2,'String'))*10^((get(handles.uipmF2,'Value')-2)*3);
% do the calculations
w=f*2*pi;
H = k*prod(j*w-z)/prod(j*w-p);
magH = abs(H);
dBH = 20*log10(magH);
radH = angle(H);
degH = radH*180/pi;
% post the data
set(handles.uitxF2Mag,'String',sprintf('%g',magH))
set(handles.uitxF2MagDb,'String',sprintf('%g',dBH))
set(handles.uitxF2AngleDeg,'String',sprintf('%g',degH))
set(handles.uitxF2AngleRad,'String',sprintf('%g',radH))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -