%% Transfer function of a RLC-network
% This script will run automated measurements for you. Note that all frequencies are given in Hertz.
% All the figures that are plotted with this script will be drawn in this file itself. If you want to get them in a seperate window click on the arrow in the upper right corner of the plot.
%
% Do not edit the following code box.

addpath('subfiles\');

%
%% Component Values
% Fill in the measured values in the following code box.

R = 9.1146e3;   %Ohm
L = 3.0488;     %Henry
C = 8.1377e-9;  %Farad

% Give the desired begin and end frequency as well as number of steps:

f_start = 100; %Hz
f_stop = 3000; %Hz

% Do not edit the following code box.

f = 10.^linspace(log10(f_start),log10(f_stop),500);

%
%% Theoratical Formulas
% Give the equations for the magnitude:

A = -10*log10((1-(2*pi*f).^2*L*C).^2+(2*pi*f*R*C).^2);

% For the phase:

P = -atan((2*pi*f*R*C)./(1-(2*pi*f).^2*L*C));

% For the cut-off frequency:

Fc = 1/(2*pi*sqrt(L*C));

% And both asymptotes where f >> f_c and f << f_c:

S_smaller = 0*f;                      %smaller than cut-off frequency
S_larger = -40*log10(2*pi*f)-20*log10(L*C);     %larger than cut-off frequency

%
%% Measurement Settings
% If the theory_only variable is set to true the script will not execute the measurements. You can use this to only plot the theory.
% Change true in to false to run the measurement as well.

theory_only = true;

% The measurement wil run from f_start to f_stop. Give the desired measurement points as n_steps and the number of total measurements as n_measurements. You can set the output amplitude of the function generator with amplitude.

n_steps = 6;
n_measurements = 3;
amplitude = 10;

% Do not edit the following code box.

initializeEquipment;
RLC_TransferFunction_script;