% Callback script for Weaver demo

% Copyright 2010-2012 The MathWorks, Inc.
% Revision: $ 
%

% Get parameters from system
model         = bdroot(gcb);
param_block   = [model '/Parameters'];
try
    phase_str = get_param(param_block,'phase_offsets');
    phase_offsets = eval(phase_str);
catch exception
    error(message('simrf:simrfV2errors:BadParamValues',                 ...
        exception.message, phase_str,'phase offset'))
end

% Phase offset needs to be a row vector
validateattributes(phase_offsets, {'numeric'},                          ...
    {'nonempty','vector','finite', 'nrows',1},                          ...
    mfilename,'Phase offset values');

unique_offsets     = unique(phase_offsets);
len_unique_offsets = length(unique_offsets);
validateattributes(len_unique_offsets, {'numeric'}, {'>', 1},mfilename, ...
    'number of unique resistor values');

% Simulate the system
data_db = zeros(1,len_unique_offsets);
for idx = 1:len_unique_offsets
    SW_dPhi = unique_offsets(idx);
    sim(model);
    data_db(idx) = irr_db;
end

% Plot the IRR response of the system
figure
if any(unique_offsets<=0)
    h_lines = plot(unique_offsets,data_db,'-+');
else
    h_lines = semilogx(unique_offsets,data_db,'-+');
end
h_axes = get(h_lines,'Parent');
title(h_axes,'Image Rejection Ratio');
xlabel(h_axes,'Phase Offset (deg)');
ylabel(h_axes,'IRR (dB)');