54 lines
2.3 KiB
Matlab
54 lines
2.3 KiB
Matlab
function [U_exc] = generateShapedNoise(args)
|
|
% generateShapedNoise - Generate a Shaped Noise excitation signal
|
|
%
|
|
% Syntax: [U_exc] = generateShapedNoise(args)
|
|
%
|
|
% Inputs:
|
|
% - args - Optinal arguments:
|
|
% - Ts - Sampling Time - [s]
|
|
% - V_mean - Mean value of the excitation voltage - [V]
|
|
% - V_exc - Excitation Amplitude, could be numeric or TF - [V rms]
|
|
% - t_start - Time at which the noise begins - [s]
|
|
% - exc_duration - Duration of the noise - [s]
|
|
% - smooth_ends - 'true' or 'false': smooth transition between 0 and V_mean - [-]
|
|
|
|
arguments
|
|
args.Ts (1,1) double {mustBeNumeric, mustBePositive} = 1e-4
|
|
args.V_mean (1,1) double {mustBeNumeric} = 0
|
|
args.V_exc = 1
|
|
args.t_start (1,1) double {mustBeNumeric, mustBePositive} = 5
|
|
args.exc_duration (1,1) double {mustBeNumeric, mustBePositive} = 10
|
|
args.smooth_ends logical {mustBeNumericOrLogical} = true
|
|
end
|
|
|
|
t_noise = 0:args.Ts:args.exc_duration;
|
|
|
|
if isnumeric(args.V_exc)
|
|
V_noise = args.V_mean + args.V_exc*sqrt(1/args.Ts/2)*randn(length(t_noise), 1)';
|
|
elseif isct(args.V_exc)
|
|
V_noise = args.V_mean + lsim(args.V_exc, sqrt(1/args.Ts/2)*randn(length(t_noise), 1), t_noise)';
|
|
end
|
|
|
|
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
|
|
|
|
V_exc = [V_smooth_start, V_noise, V_smooth_end];
|
|
t_exc = args.Ts*[0:1:length(V_exc)-1];
|
|
|
|
U_exc = [t_exc; V_exc];
|