⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiplotuserdata.m

📁 Talking about adaptive filter digital
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = GuiPlotUserData(varargin)
% GUIPLOTUSERDATA M-file for GuiPlotUserData.fig
%      GUIPLOTUSERDATA, by itself, creates a new GUIPLOTUSERDATA or raises the existing
%      singleton*.
%
%      H = GUIPLOTUSERDATA returns the handle to a new GUIPLOTUSERDATA or the handle to
%      the existing singleton*.
%
%      GUIPLOTUSERDATA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIPLOTUSERDATA.M with the given input arguments.
%
%      GUIPLOTUSERDATA('Property','Value',...) creates a new GUIPLOTUSERDATA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GuiPlotUserData_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GuiPlotUserData_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 GuiPlotUserData

% Last Modified by GUIDE v2.5 17-Jan-2004 16:25:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GuiPlotUserData_OpeningFcn, ...
                   'gui_OutputFcn',  @GuiPlotUserData_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 GuiPlotUserData is made visible.
function GuiPlotUserData_OpeningFcn(hObject, eventdata, handles, varargin)
global strFilterObject

% Load data
if isempty(strFilterObject)
   temp=load('matlab');
   disp([mfilename ' called in debug mode using matlab.mat datafile'])
   strFilterObject = temp.strFilterObject;
else
    strFilterObject=Utility_zpk(strFilterObject); % find poles, zeros
end
set(handles.uiFilterUserData,'Name',strFilterObject.sTitle)

% Initialize the GUI widgets and variables
handles = Initialize(handles);

% Calculate and plot
CalculateAndPlot(handles);

% Save handles data in figure
guidata(hObject, handles);

function varargout = GuiPlotUserData_OutputFcn(hObject, eventdata, handles)
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           Initialize
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function handles = Initialize(handles)
global strFilterObject

% initialize the Data box
fC = strFilterObject.fFc;
NSamples = 1001;  % samples in the datafile
NPeriods = 10;    % periods of the waveform
fSample = fC*(NSamples-1)/NPeriods;
handles.fSample = fSample;
handles.xData = sin(linspace(0,NPeriods*2*pi,NSamples));
set(handles.uitxData,'String',['Default ' Utility_EngOutput(fC,'Hz',4) ' sinusoid'])
[sMan,fExp]=Utility_EngOutput(fSample,'',4,-3,6);
set(handles.uiebData,'String',sMan)
set(handles.uipmData,'Value',(fExp/3)+2)

% initialize the Time box
sTMin = '0';
TMax = (NSamples-1)/fSample;
sTMax=Utility_EngOutput(TMax,'s');
[sTMax,sTUnit]=strtok(sTMax,' ');
sTUnit(1) = [];
set(handles.uiebTMin,'String',sTMin)
set(handles.uitxTMin,'String',[sTUnit '   or "default"'])
set(handles.uiebTMax,'String',sTMax)
set(handles.uitxTMax,'String',[sTUnit '   or "default"'])

% initialize the PSD box
fFMax = fSample/2;
sFMax=Utility_EngOutput(fFMax,'Hz');
[sFMax,sFUnit]=strtok(sFMax,' ');
sFUnit(1) = [];
set(handles.uiebFMin,'String','0')
set(handles.uitxFMin,'String',[sFUnit '   or "default"'])
set(handles.uiebFMax,'String',sFMax)
set(handles.uitxFMax,'String',[sFUnit '   or "default"'])
set(handles.uirbPSDLin,'Value',1)
set(handles.uirbPSDdB,'Value',0)
set(handles.uirbFLin,'Value',1)
set(handles.uirbFLog,'Value',0)

% initialize the show box
set(handles.uicbUnfiltered,'Value',1)
set(handles.uirbFilteredIdeal,'Value',1)
set(handles.uirbFilteredStandard,'Value',0)
if isempty(strFilterObject.fK1)
    set(handles.uirbFilteredStandard,'Enable','off')
    set(handles.uitxShowStandard,'Enable','off')
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                            CalculateAndPlot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function CalculateAndPlot(handles)
global strFilterObject

% Data box
fSample = handles.fSample;
xData = handles.xData;
tData = linspace(0,(length(xData)-1)/fSample,length(xData));

% Time box
tScale = GetScale(get(handles.uitxTMin,'String'));
tMin = str2num(get(handles.uiebTMin,'String'))*tScale;
tMax = str2num(get(handles.uiebTMax,'String'))*tScale;

% PSD box
fScale = GetScale(get(handles.uitxFMax,'String'));
fMin = str2num(get(handles.uiebFMin,'String'))*fScale;
fMax = str2num(get(handles.uiebFMax,'String'))*fScale;
bIsPSDLinear = get(handles.uirbPSDLin,'Value');
bIsFreqLinear = get(handles.uirbFLin,'Value');

% Show box
bShowX = get(handles.uicbUnfiltered,'Value'); 
bShowY = get(handles.uirbFilteredIdeal,'Value');
bShowY1 = get(handles.uirbFilteredStandard,'Value');

% Time axis
axes(handles.uiaxTime)
[dummy,strXLabel]=strtok(Utility_EngOutput(tMax,1,'s'),' ');
strXLabel(1)=[];
[dummy,exponent]=Utility_EngOutput(tMax);
tScale = 10^exponent;
cla, hold on
xlabel(strXLabel)
sWarn = '';
if bShowX
    plot(tData/tScale,xData,'b');
end
if bShowY
   z = strFilterObject.vZeros;
   p = strFilterObject.vPoles;
   k = strFilterObject.fK;
   [yData,sWarn] = LinearFilter(z,p,k,xData,tData);
   plot(tData/tScale,yData,'g')
end
if bShowY1
   z1 = strFilterObject.vZeros1;
   p1 = strFilterObject.vPoles1;
   k1 = strFilterObject.fK1;
   [yData1,sWarn] = LinearFilter(z1,p1,k1,xData,tData);
   plot(tData/tScale,yData1,'Color',[0.5 0 0])
end
v = axis;
v(1) = str2num(get(handles.uiebTMin,'String'));
v(2) = str2num(get(handles.uiebTMax,'String'));
axis(v)
set(handles.uiaxTime,'YLimMode','auto')

% PSD axis
axes(handles.uiaxPSD)
cla, hold on
% setup axis
if bIsFreqLinear
    [dummy,strXLabel]=strtok(Utility_EngOutput(fMax,1,'Hz'),' ');
    strXLabel(1)=[];
    xlabel(strXLabel)
    [dummy,exponent]=Utility_EngOutput(fMax);
    fScale = 10^exponent;
else
    xlabel('Hz')
    fScale = 1;
end
if bShowX
    [XData,f] = MyPSD(xData,fSample);
    if ~bIsPSDLinear, XData = 10*log10(XData); end
    plot(f/fScale,XData,'b')
end
if bShowY
    [YData,f] = MyPSD(yData,fSample);
    if ~bIsPSDLinear, YData = 10*log10(YData); end
    plot(f/fScale,YData,'Color',[0 0.5 0])
end
if bShowY1
    [YData1,f] = MyPSD(yData1,fSample);
    if ~bIsPSDLinear, YData1 = 10*log10(YData1); end
    plot(f/fScale,YData1,'Color',[0.5 0 0])
end
if bIsFreqLinear
    set(handles.uiaxPSD,'XScale','linear')
    set(handles.uiaxPSD,'XLimMode','auto')
else
    set(handles.uiaxPSD,'XScale','log')
    set(handles.uiaxPSD,'XLimMode','auto')
end
if bIsPSDLinear
    ylabel('Power (linear)')
else
    ylabel('Power (dB)')
end

v = axis;
if bIsFreqLinear
    fScale = 1;
else
    [dummy,exponent]=Utility_EngOutput(fMax);
    fScale = 10^exponent;
end
v(1) = str2num(get(handles.uiebFMin,'String'))*fScale;
v(2) = str2num(get(handles.uiebFMax,'String'))*fScale;
axis(v)
set(handles.uiaxPSD,'YLimMode','auto')

if ~isempty(sWarn)
    warndlg(sWarn,'Warning')
end
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                      Data Box Callbacks   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uipbData_Callback(hObject, eventdata, handles)
if exist('handles.sPathName')
    cd(handles.sPathName)
end
[sFileName, sPathName] = uigetfile('*.txt','Open user data file');
bGoodData = 0;
if sFileName
    fid = fopen([sPathName sFileName],'rt');
    % process first line; look for sample frquency information
    line1 = fgetl(fid);
    xData = [];
    fSample = [];
    if findstr(lower(line1),'sample')
        fSample = str2num(strtok(line1));
        if isempty(fSample)
            str1 = 'File format incorrect.  ';
            str2 = 'The first row may either have the first sample alone, or it may have ';
            str3 = 'the first sample followed by a space and the words "sample frequency".';
            errordlg([str1 str2 str3],'Error')
        else
            bGoodData = 1;
        end
    end
    while 1
        curLine = fgetl(fid);
        if ~ischar(curLine), break, end  % end of file reached
        curNum = str2num(curLine);
        if isempty(curNum) || prod(size(curNum)) ~= 1
            str1 = 'File format incorrect.  ';
            str2 = 'The file must have a single column of numbers and be in ASCII format.';
            errordlg([str1 str2],'Error')
            bGoodData = 0;
            break
        else
            xData = [xData; curNum];
            bGoodData = 1;
        end
    end
    fclose(fid);
    
    if ~bGoodData, return, end
    if ~isempty(fSample)
        handles.fSample = fSample;
        % update the data box sample frequency widgets
        [sMan,fExp]=Utility_EngOutput(fSample,'',4,-3,6);
        set(handles.uiebData,'String',sMan)
        set(handles.uipmData,'Value',(fExp/3)+2)
        % update the PSD box frequency labels
        fFMax = fSample/2;
        sFMax=Utility_EngOutput(fFMax,'Hz');
        [sFMax,sFUnit]=strtok(sFMax,' ');
        sFUnit(1) = [];
        set(handles.uiebFMin,'String','0')
        set(handles.uitxFMin,'String',[sFUnit '   or "default"'])
        set(handles.uiebFMax,'String',sFMax)
        set(handles.uitxFMax,'String',[sFUnit '   or "default"'])
        set(handles.uirbPSDLin,'Value',1)
        set(handles.uirbPSDdB,'Value',0)
        set(handles.uirbFLin,'Value',1)
        set(handles.uirbFLog,'Value',0)
    end
    handles.xData = xData;
    set(handles.uitxData,'String',sFileName)
    % initialize the Time box
    sTMin = '0';
    NSamples = length(xData);
    fSample = handles.fSample;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -