Code covered by the BSD License  

Highlights from
Agilent Spectrum Analyzer Seminar Examples

image thumbnail

Agilent Spectrum Analyzer Seminar Examples

by

 

11 Feb 2008 (Updated )

Agilent MXA, PSA Seminar Examples

ADVFigure(varargin)
function varargout = ADVFigure(varargin)
% ADVFIGURE M-file for ADVFigure.fig
%      ADVFIGURE, by itself, creates a new ADVFIGURE or raises the existing
%      singleton*.
%
%      H = ADVFIGURE returns the handle to a new ADVFIGURE or the handle to
%      the existing singleton*.
%
%      ADVFIGURE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ADVFIGURE.M with the given input arguments.
%
%      ADVFIGURE('Property','Value',...) creates a new ADVFIGURE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ADVFigure_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ADVFigure_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 ADVFigure

% Last Modified by GUIDE v2.5 05-Dec-2007 13:51:45

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ADVFigure_OpeningFcn, ...
                   'gui_OutputFcn',  @ADVFigure_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


%*******************************************************************
% OpeningFcn Callback
%
% Executes just before ADVFigure is made visible.  This function
% also performs the required initialization for the advanced
% data visualization functions.
%*******************************************************************
function ADVFigure_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 ADVFigure (see VARARGIN)

global g_ADVMXAHandle
global g_ADVClosing

% Choose default command line output for ADVFigure
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

%*-------------------------------------------------------------*
%  Initialize data visualization
%*-------------------------------------------------------------*
ADV_Initialize();
g_ADVClosing = 0;

%*-------------------------------------------------------------*
%  Set figure defaults
%*-------------------------------------------------------------*
set( handles.advFigure, ...
    'DefaultAxesColor', [0,0,0], ...
    'DefaultAxesXColor', [0, 0, 0], ...
    'DefaultAxesYColor', [0.5, 0.5, 0.5], ...
    'DefaultAxesZColor', [0.5, 0.5, 0.5], ...
    'DefaultAxesGridLineStyle', 'none', ...
    'KeyPressFcn', @ADVFigure_keypress, ...
    'DefaultUicontrolKeyPressFcn', @ADVFigure_keypress );

set( handles.button1, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button2, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button3, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button4, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button5, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button6, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.button7, 'KeyPressFcn', @ADVFigure_keypress );
set( handles.agilentLabel, 'KeyPressFcn', @ADVFigure_keypress );

%*-------------------------------------------------------------*
%  Add GUI data to the handles structure
%*-------------------------------------------------------------*

% menuNumber indicates the current softkey menu selection.  Possible 
% values are:
%  0 - Main menu
%  1 - Display mode selection

handles.menuNumber = 0;

% displayMode indicates the active display mode.  Possible values
% are:
%  0 = Analog advanced (default)
%  1 = Analog plus
%  2 = Waterfall
%  3 = Spectrogram
handles.displayMode = 0;

% timer stores a handle to the timer object
handles.timer = 0;

% Save the GUI data
guidata( handles.advFigure, handles );

% Update the display mode
ADV_SetDisplayMode( g_ADVMXAHandle, 0, handles );

% Show the main menu
ShowMainMenu( handles );



function ADVFigure_keypress( source, event )

handles = guidata( gcf );
if length(event.Modifier) == 2 && ...
        strcmp(event.Modifier(1), 'shift') && ...
        strcmp(event.Modifier(2), 'control')
    
    if strcmp( event.Key, 'f1' )
        button1_Callback( 0, event, handles );
    
    elseif strcmp( event.Key, 'f2' )
        button2_Callback( 0, event, handles );
        
    elseif strcmp( event.Key, 'f3' )
        button3_Callback( 0, event, handles );
        
    elseif strcmp( event.Key, 'f4' )
        button4_Callback( 0, event, handles );
        
    elseif strcmp( event.Key, 'f5' )
        button5_Callback( 0, event, handles );
        
    elseif strcmp( event.Key, 'f6' )
        button6_Callback( 0, event, handles );
        
    elseif strcmp( event.Key, 'f7' )
        button7_Callback( 0, event, handles );
    end
end


%*******************************************************************
% OutputFcn Callback
%
% Outputs from this function are returned to the command line.
%*******************************************************************
function varargout = ADVFigure_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;


%*******************************************************************
% Button1 Callback
%
% This function is called when the user clicks on the first softkey
% button.  Its functionality depends on the current menu selection,
% defined by the menuNumber variable.
%*******************************************************************
function button1_Callback(hObject, eventdata, handles)
% hObject    handle to button1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%*******************************************************************
% Button2 Callback
%
% This function is called when the user clicks on the second softkey
% button.  Its functionality depends on the current menu selection,
% defined by the menuNumber variable.
%*******************************************************************
function button2_Callback(hObject, eventdata, handles)
% hObject    handle to button2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


global g_ADVMXAHandle

if handles.menuNumber == 0
    %*---------------------------------------------------*
    %  Display mode button was pressed in the main menu.
    %*---------------------------------------------------*
    for i=0:3
        % Determine the text and button handle
        switch i
            case 0
                buttonText = 'Analog Adv';
                handle = handles.button2;
            case 1
                buttonText = 'Analog Plus';
                handle = handles.button3;
            case 2
                buttonText = 'Waterfall';
                handle = handles.button4;
            case 3
                buttonText = 'Spectrogram';
                handle = handles.button5;
        end
        
        % If this is the current display mode, make the text bold
        if i == handles.displayMode
            fontWeight = 'bold';
        else
            fontWeight = 'normal';
        end
        
        % Update the button
        set( handle, 'String', buttonText, 'Visible', 'on', 'FontWeight', fontWeight' );
    end

    % Add the return menu
    set( handles.button6, 'Visible', 'off' );
    set( handles.button7, 'String', 'Return', 'Visible', 'on' );
    
    % Update the menu number
    handles.menuNumber = 1;
    guidata( handles.advFigure, handles );

elseif handles.menuNumber == 1
    %*---------------------------------------------------*
    %  Analog advanced button was pressed in the
    %  display mode menu.
    %*---------------------------------------------------*    
    % Change mode to analog advanced
    handles.displayMode = 0;
    ADV_SetDisplayMode( g_ADVMXAHandle, 0, handles );
    guidata( handles.advFigure, handles );
    
    % Update timer user data
    if handles.timer ~= 0 
        set( handles.timer, 'UserData', handles );
    end

    % Switch to the main menu
    ShowMainMenu( handles );
end

% --- Executes on button press in button3.
function button3_Callback(hObject, eventdata, handles)
% hObject    handle to button3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% --- Executes on button press in button4.

global g_ADVMXAHandle    

if handles.menuNumber == 0 
    %*---------------------------------------------------*
    %  Start/Stop button was pressed in the main menu.
    %*---------------------------------------------------*
    if strcmpi( get( handles.button3, 'String' ), 'Start' )
        % Initialize the timer object
        t = timer( 'TimerFcn', @timer_Callback, ...
            'StartDelay', 0.0, ...
            'Period', 0.01, ...
            'ExecutionMode', 'fixedRate' );
        
        % Update the GUI data to include the timer handle
        handles.timer = t;
        guidata( handles.advFigure, handles );
        set( t, 'UserData', handles );
        
        % Change start button to stop
        set( handles.button3, 'String', 'Stop' );
        drawnow
        
        % Start the timer
        start( t );
        
    else
        % Stop the timer
        stop( handles.timer );
        delete( handles.timer );
        
        % Change button text back to start
        set( handles.button3, 'String', 'Start' );
        
        % Update the GUI data
        handles.timer = 0;
        guidata( handles.advFigure, handles );
        
    end
    
elseif handles.menuNumber == 1
    %*---------------------------------------------------*
    %  Analog plus button was pressed in the display 
    %  mode selection menu.
    %*---------------------------------------------------*
    % Change mode to analog plus
    handles.displayMode = 1;
    ADV_SetDisplayMode( g_ADVMXAHandle, 1, handles );
    guidata( handles.advFigure, handles );
    
    % Update timer user data
    if handles.timer ~= 0 
        set( handles.timer, 'UserData', handles );
    end
    
    % Switch to the main menu
    ShowMainMenu( handles );

end


function button4_Callback(hObject, eventdata, handles)
% hObject    handle to button4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_ADVMXAHandle

if handles.menuNumber == 0
    % Restart
    ADV_Reset( g_ADVMXAHandle );
    
elseif handles.menuNumber == 1 
    % Change mode to waterfall
    handles.displayMode = 2;
    ADV_SetDisplayMode( g_ADVMXAHandle, 2, handles );
    guidata( handles.advFigure, handles );
    
    % Update timer user data
    if handles.timer ~= 0 
        set( handles.timer, 'UserData', handles );
    end
    
    % Switch to the main menu
    ShowMainMenu( handles );

end


% --- Executes on button press in button5.
function button5_Callback(hObject, eventdata, handles)
% hObject    handle to button5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_ADVMXAHandle

if handles.menuNumber == 1 
    % Change mode to waterfall
    handles.displayMode = 3;
    ADV_SetDisplayMode( g_ADVMXAHandle, 3, handles );
    guidata( handles.advFigure, handles );
    
    % Update timer user data
    if handles.timer ~= 0 
        set( handles.timer, 'UserData', handles );
    end
    
    % Switch to the main menu
    ShowMainMenu( handles );

end


% --- Executes on button press in button6.
function button6_Callback(hObject, eventdata, handles)
% hObject    handle to button6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in button7.
function button7_Callback(hObject, eventdata, handles)
% hObject    handle to button7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_ADVClosing

if handles.menuNumber == 0 
    % Stop the timer, if it is executing
    if handles.timer ~= 0 
        stop( handles.timer );
        delete( handles.timer );
        g_ADVClosing = 1;
    else
        % Execute termination code
        ADV_Close;
        %fprintf( handle, '*RST' );
        % Close the figure
        close( handles.advFigure );
        
    end
    
    
elseif handles.menuNumber == 1
    % Return to main menu
    ShowMainMenu( handles );
    
end


%*******************************************************************
% ShowMainMenu
%
% Configures the buttons to display the main menu.
%*******************************************************************
function ShowMainMenu( handles )
% Determine mode button name
switch handles.displayMode
    case 0
        modeName = 'Analog Adv';

    case 1 
        modeName = 'Analog Plus';

    case 2
        modeName = 'Waterfall';

    case 3
        modeName = 'Spectrogram';
end

% Change button names
set( handles.button1, 'Visible', 'off' );
set( handles.button2, 'String', modeName, 'FontWeight', 'normal' );
if handles.timer ~= 0
    if strcmpi( get( handles.timer, 'Running' ), 'off' ) == 1 
        startText = 'Start';
    else
        startText = 'Stop';
    end
else
    startText = 'Start';
end
set( handles.button3, 'Visible', 'on' );
set( handles.button3, 'String', startText, 'FontWeight', 'normal' );
set( handles.button4, 'Visible', 'on' );
set( handles.button4, 'String', 'Restart' );
set( handles.button5, 'Visible', 'off' );
set( handles.button6, 'Visible', 'off' );
set( handles.button7, 'String', 'Exit' );

% Update the menu number
handles.menuNumber = 0;
guidata( handles.advFigure, handles );
drawnow;


%*******************************************************************
% Timer Callback
%
% Executes the code that is required for each iteration of the 
% timer loop.  This callback is used to acquire the data from the 
% MXA and perform the post processing and display functions.
%*******************************************************************
function timer_Callback( hObject, eventdata )

global g_ADVTraceFIFO
global g_ADVXAxis
global g_ADVYAxis 
global g_ADVPersistBuffer
global g_ADVMXAHandle
global g_ADVClosing

% Retrieve the figure handles structure
handles = get( hObject, 'UserData' );

% Acquire data from the MXA
data = MXA_AcquireData( g_ADVMXAHandle );
ADV_DataToBuffer( g_ADVMXAHandle, data );

% Make sure the timer is still running
if isvalid( handles.timer ) == 0
    return;
end

% Update the display
figure( handles.advFigure );
uicontrol( handles.button7 );
if handles.displayMode == 0
    % Analog advanced
    image( g_ADVXAxis, g_ADVYAxis, g_ADVPersistBuffer );
    set( handles.mainAxes, 'YDir', 'normal' );

elseif handles.displayMode == 1
    % Analog plus
    image( g_ADVXAxis, g_ADVYAxis, g_ADVPersistBuffer );
    set( handles.mainAxes, 'YDir', 'normal' );

elseif handles.displayMode == 2
    % Waterfall
    mesh( handles.mainAxes, g_ADVYAxis, g_ADVXAxis, g_ADVTraceFIFO, 'MeshStyle', 'Column' );
    set( handles.mainAxes, 'View', [95, 30] );     
    
elseif handles.displayMode == 3
    % Spectrogram
    mesh( handles.mainAxes, g_ADVYAxis, g_ADVXAxis, g_ADVTraceFIFO );
    set( handles.mainAxes, 'View', [90, 90] );

end

if g_ADVClosing == 1
    % Terminate ADV
    ADV_Close;
    
    % Close figure
    close( handles.advFigure );
end


Contact us