2021-06-07 19:00:29 +02:00
|
|
|
%% Clear Workspace and Close figures
|
|
|
|
clear; close all; clc;
|
|
|
|
|
|
|
|
%% Intialize Laplace variable
|
|
|
|
s = zpk('s');
|
|
|
|
|
|
|
|
addpath('./src/');
|
|
|
|
|
|
|
|
%% Simulation configuration
|
2021-08-11 18:03:35 +02:00
|
|
|
Fs = 1e4; % Sampling Frequency [Hz]
|
2021-06-08 16:51:38 +02:00
|
|
|
Ts = 1/Fs; % Sampling Time [s]
|
2021-06-07 19:00:29 +02:00
|
|
|
|
|
|
|
%% Data record configuration
|
2021-07-01 17:45:57 +02:00
|
|
|
Trec_start = 5; % Start time for Recording [s]
|
2021-08-11 18:03:35 +02:00
|
|
|
Trec_dur = 100; % Recording Duration [s]
|
2021-06-07 19:00:29 +02:00
|
|
|
|
|
|
|
Tsim = 2*Trec_start + Trec_dur; % Simulation Time [s]
|
|
|
|
|
2021-06-10 14:17:06 +02:00
|
|
|
%% Security
|
2021-08-11 18:03:35 +02:00
|
|
|
% u_min = -1;
|
|
|
|
% u_max = 7.5;
|
|
|
|
|
|
|
|
u_min = 1.25;
|
|
|
|
u_max = 5.25;
|
|
|
|
|
|
|
|
d_min = -50e-6;
|
|
|
|
d_max = 50e-6;
|
2021-06-10 14:17:06 +02:00
|
|
|
|
2021-06-07 19:00:29 +02:00
|
|
|
%% Shaped Noise
|
|
|
|
V_noise = generateShapedNoise('Ts', 1/Fs, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', 0.05/(1 + s/2/pi/10));
|
2021-06-07 19:00:29 +02:00
|
|
|
|
|
|
|
%% Sweep Sine
|
|
|
|
gc = 0.1;
|
|
|
|
xi = 0.5;
|
2021-06-08 16:51:38 +02:00
|
|
|
wn = 2*pi*92.7;
|
2021-06-07 19:00:29 +02:00
|
|
|
|
|
|
|
% Notch filter at the resonance of the APA
|
|
|
|
G_sweep = 0.2*(s^2 + 2*gc*xi*wn*s + wn^2)/(s^2 + 2*xi*wn*s + wn^2);
|
|
|
|
|
|
|
|
V_sweep = generateSweepExc('Ts', Ts, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'f_start', 10, ...
|
|
|
|
'f_end', 400, ...
|
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'sweep_type', 'log', ...
|
|
|
|
'V_exc', G_sweep*1/(1 + s/2/pi/500));
|
2021-06-07 19:00:29 +02:00
|
|
|
|
2021-06-08 16:51:38 +02:00
|
|
|
V_sweep_lf = generateSweepExc('Ts', Ts, ...
|
2021-08-11 18:03:35 +02:00
|
|
|
'f_start', 20, ...
|
|
|
|
'f_end', 40, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
2021-08-11 18:03:35 +02:00
|
|
|
'sweep_type', 'lin', ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_exc', 0.2);
|
2021-06-08 16:51:38 +02:00
|
|
|
|
2021-06-07 19:00:29 +02:00
|
|
|
%% High Frequency Shaped Noise
|
2021-06-08 16:51:38 +02:00
|
|
|
[b,a] = cheby1(10, 2, 2*pi*[240 2e3], 'bandpass', 's');
|
2021-06-07 19:00:29 +02:00
|
|
|
wL = 0.005*tf(b, a);
|
|
|
|
|
2021-06-30 23:22:08 +02:00
|
|
|
V_noise_hf = generateShapedNoise('Ts', Ts, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', wL);
|
2021-06-07 19:00:29 +02:00
|
|
|
|
2021-06-08 16:51:38 +02:00
|
|
|
%% Low Frequency Shaped Noise
|
2021-08-11 18:03:35 +02:00
|
|
|
[b,a] = cheby1(10, 2, 2*pi*[20 40], 'bandpass', 's');
|
|
|
|
wL = 0.01*tf(b, a);
|
2021-06-08 16:51:38 +02:00
|
|
|
|
|
|
|
V_noise_lf = generateShapedNoise('Ts', 1/Fs, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', wL);
|
2021-06-08 16:51:38 +02:00
|
|
|
|
2021-08-11 18:03:35 +02:00
|
|
|
%% Band Pass Shaped Noise
|
|
|
|
[b,a] = cheby1(10, 2, 2*pi*[9 1.1e3], 'bandpass', 's');
|
|
|
|
wL = 0.005*tf(b, a);
|
|
|
|
|
|
|
|
V_noise_bf = generateShapedNoise('Ts', 1/Fs, ...
|
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', wL);
|
|
|
|
|
2021-06-07 19:00:29 +02:00
|
|
|
%% Sinus excitation with increasing amplitude
|
|
|
|
V_sin = generateSinIncreasingAmpl('Ts', 1/Fs, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
'sin_ampls', [0.1, 0.2, 0.4, 1, 2, 4], ...
|
|
|
|
'sin_period', 1, ...
|
|
|
|
'sin_num', 5, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'smooth_ends', true);
|
|
|
|
|
2021-06-30 23:22:08 +02:00
|
|
|
%% Zero Voltage
|
2021-06-08 16:51:38 +02:00
|
|
|
V_zero = generateShapedNoise('Ts', 1/Fs, ...
|
2021-06-30 23:22:08 +02:00
|
|
|
'V_mean', 0, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', tf(0));
|
|
|
|
|
|
|
|
%% Offset Voltage for all APA
|
|
|
|
V_zero_off = generateShapedNoise('Ts', 1/Fs, ...
|
2021-06-10 14:17:06 +02:00
|
|
|
'V_mean', 3.25, ...
|
|
|
|
't_start', Trec_start, ...
|
|
|
|
'exc_duration', Trec_dur, ...
|
|
|
|
'smooth_ends', true, ...
|
|
|
|
'V_exc', tf(0));
|
2021-06-08 16:51:38 +02:00
|
|
|
|
2021-06-10 14:17:06 +02:00
|
|
|
%% Select the excitation signal and offset voltage
|
2021-08-11 18:03:35 +02:00
|
|
|
V_exc = timeseries(V_noise_bf(2,:), V_noise_bf(1,:));
|
2021-06-30 23:22:08 +02:00
|
|
|
V_off = timeseries(V_zero_off(2,:), V_zero_off(1,:));
|
2021-06-07 19:00:29 +02:00
|
|
|
|
|
|
|
%% Plot
|
|
|
|
figure;
|
|
|
|
tiledlayout(1, 2, 'TileSpacing', 'Normal', 'Padding', 'None');
|
|
|
|
|
|
|
|
ax1 = nexttile;
|
2021-08-11 18:03:35 +02:00
|
|
|
hold on;
|
2021-06-10 14:17:06 +02:00
|
|
|
plot(V_exc.Time, squeeze(V_exc.Data+V_off.Data));
|
2021-08-11 18:03:35 +02:00
|
|
|
plot([V_exc.Time(1), V_exc.Time(end)], [u_min, u_min], 'k--');
|
|
|
|
plot([V_exc.Time(1), V_exc.Time(end)], [u_max, u_max], 'k--');
|
|
|
|
hold off;
|
2021-06-07 19:00:29 +02:00
|
|
|
xlabel('Time [s]'); ylabel('Amplitude [V]');
|
|
|
|
|
|
|
|
ax2 = nexttile;
|
2021-06-08 16:51:38 +02:00
|
|
|
win = hanning(floor(length(squeeze(V_exc.Data))/8));
|
|
|
|
[pxx, f] = pwelch(squeeze(V_exc.Data), win, 0, [], Fs);
|
2021-06-07 19:00:29 +02:00
|
|
|
plot(f, pxx)
|
|
|
|
xlabel('Frequency [Hz]'); ylabel('Power Spectral Density [$V^2/Hz$]');
|
|
|
|
set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log');
|
|
|
|
xlim([1, Fs/2]); ylim([1e-10, 1e0]);
|
|
|
|
|
|
|
|
%% Save data that will be loaded in the Simulink file
|
2021-07-01 17:45:57 +02:00
|
|
|
save('sim_data/data_sim.mat', ...
|
|
|
|
'Fs', 'Ts', 'Tsim', 'Trec_start', 'Trec_dur', ...
|
|
|
|
'V_exc', 'V_off', ...
|
2021-08-11 18:03:35 +02:00
|
|
|
'u_min', 'u_max', ...
|
|
|
|
'd_min', 'd_max');
|