function [U_exc] = generateSweepExc(args) % generateSweepExc - Generate a Sweep Sine excitation signal % % Syntax: [U_exc] = generateSweepExc(args) % % Inputs: % - args - Optinal arguments: % - Ts - Sampling Time - [s] % - f_start - Start frequency of the sweep - [Hz] % - f_end - End frequency of the sweep - [Hz] % - V_mean - Mean value of the excitation voltage - [V] % - V_exc - Excitation Amplitude for the Sweep, could be numeric or TF - [V] % - t_start - Time at which the sweep begins - [s] % - exc_duration - Duration of the sweep - [s] % - sweep_type - 'logarithmic' or 'linear' - [-] % - smooth_ends - 'true' or 'false': smooth transition between 0 and V_mean - [-] arguments args.Ts (1,1) double {mustBeNumeric, mustBePositive} = 1e-4 args.f_start (1,1) double {mustBeNumeric, mustBePositive} = 1 args.f_end (1,1) double {mustBeNumeric, mustBePositive} = 1e3 args.V_mean (1,1) double {mustBeNumeric} = 0 args.V_exc = 1 args.t_start (1,1) double {mustBeNumeric, mustBeNonnegative} = 5 args.exc_duration (1,1) double {mustBeNumeric, mustBePositive} = 10 args.sweep_type char {mustBeMember(args.sweep_type,{'log', 'lin'})} = 'lin' args.smooth_ends logical {mustBeNumericOrLogical} = true end t_sweep = 0:args.Ts:args.exc_duration; if strcmp(args.sweep_type, 'log') V_exc = sin(2*pi*args.f_start * args.exc_duration/log(args.f_end/args.f_start) * (exp(log(args.f_end/args.f_start)*t_sweep/args.exc_duration) - 1)); elseif strcmp(args.sweep_type, 'lin') V_exc = sin(2*pi*(args.f_start + (args.f_end - args.f_start)/2/args.exc_duration*t_sweep).*t_sweep); else error('sweep_type should either be equal to "log" or to "lin"'); end if isnumeric(args.V_exc) V_sweep = args.V_mean + args.V_exc*V_exc; elseif isct(args.V_exc) if strcmp(args.sweep_type, 'log') V_sweep = args.V_mean + abs(squeeze(freqresp(args.V_exc, args.f_start*(args.f_end/args.f_start).^(t_sweep/args.exc_duration), 'Hz')))'.*V_exc; elseif strcmp(args.sweep_type, 'lin') V_sweep = args.V_mean + abs(squeeze(freqresp(args.V_exc, args.f_start+(args.f_end-args.f_start)/args.exc_duration*t_sweep, 'Hz')))'.*V_exc; end end if args.t_start > 0 t_smooth_start = args.Ts:args.Ts:args.t_start; V_smooth_start = zeros(size(t_smooth_start)); V_smooth_end = zeros(size(t_smooth_start)); if args.smooth_ends Vd_max = args.V_mean/(0.7*args.t_start); V_d = zeros(size(t_smooth_start)); V_d(t_smooth_start < 0.2*args.t_start) = t_smooth_start(t_smooth_start < 0.2*args.t_start)*Vd_max/(0.2*args.t_start); V_d(t_smooth_start > 0.2*args.t_start & t_smooth_start < 0.7*args.t_start) = Vd_max; V_d(t_smooth_start > 0.7*args.t_start & t_smooth_start < 0.9*args.t_start) = Vd_max - (t_smooth_start(t_smooth_start > 0.7*args.t_start & t_smooth_start < 0.9*args.t_start) - 0.7*args.t_start)*Vd_max/(0.2*args.t_start); V_smooth_start = cumtrapz(V_d)*args.Ts; V_smooth_end = args.V_mean - V_smooth_start; end else V_smooth_start = []; V_smooth_end = []; end V_exc = [V_smooth_start, V_sweep, V_smooth_end]; t_exc = args.Ts*[0:1:length(V_exc)-1]; U_exc = [t_exc; V_exc];