clear
clc
%% Initialize internal resistances for devices

General_Resistance = 20;

R_C2d = General_Resistance;  % Ohm
R_C3d = General_Resistance;  % Ohm
R_EV1d = General_Resistance; % Ohm
R_EV2d = General_Resistance; % Ohm
R_Ad = General_Resistance;   % Ohm
R_EMUd = General_Resistance; % Ohm

%% Initialize cable resistances

% Cable type: Copper

resistivity = 1.72 * 10^(-8); % Resistivity [Omega * m]
cableDiamSize = 3; % Cable Diameter Size [AWG]
cableCrossSec = 26.6705 * 10^(-6); % Cable area [m2]

% All length are in meters.
L1 = 10; % Length of cable (one-way) from C1 to Battery
L2 = 150; % Length of cable (one-way) from C1 to PV
L3 = 5;  % Length of cable (one-way) from C1 to A
L4 = 20; % Length of cable (one-way) from C1 to EV1
L5 = 20; % Length of cable (one-way) from C1 to EV2
L6 = 30; % Length of cable (one-way) from C1 to EMU
L_c = 2; % Length of cable (one-way) connection

% All resistances are in Ohms,
R_DC1 = 2 * resistivity * L1 / cableCrossSec; % Battery
R_DC2 = 2 * resistivity * L2 / cableCrossSec; % PV
R_DC3 = 2 * resistivity * L3 / cableCrossSec; % A
R_DC4 = 2 * resistivity * L4 / cableCrossSec;
R_DC5 = 2 * resistivity * L5 / cableCrossSec;
R_DC6 = 2 * resistivity * L6 / cableCrossSec;
R_XXc = 2 * resistivity * L_c / cableCrossSec;

%% Other ETC.
T_sim = 60 * 10; % Simulation time [s]
samplingTimeZOH = 2; % [s]
noisePower = 0; 

%% FIR Coefficients 

N   = 24;        % FIR filter order
Fp  = 0.0001;       % 2 Hz passband-edge frequency
Fs  = 1/samplingTimeZOH;       % sampling frequency
Rp  = 0.00057565; % Corresponds to 0.01 dB peak-to-peak ripple
Rst = 1e-4;       % Corresponds to 80 dB stopband attenuation 

eqnum = firceqrip(N,Fp/(Fs/2),[Rp Rst],'passedge'); % eqnum = vec of coeffs
% fvtool(eqnum,'Fs',Fs) % Visualize filter
