clear;
clc;

fprintf('Bodediagram of the filter\n\n');

R2 = input('R2 [Ohm] : ');
R3n = input('R3:[kOhm] : ');
C4n = input('C4 [nF] : ');
L5n = input('L5 [mH] : ');
fprintf('\n');

R3 = R3n*1e3;
C4 = C4n*1e-9;
L5 = L5n*1e-3;

t0 = 0;
t1 = L5;
n0 = R2+R3;
n1 = L5;
n2 = n0*C4*L5;

fstep = 4;
f=596;

for i=1:251
   f = f + fstep;
   frequentie(i) = f;
   w = 2*pi*f;
   H(i)=((1i*w*t1)/(n0+1i*w*n1+n2*(1i*w)^2));
end

figure(1);
fig_label=('Bodediagram Fourierfilter');
set(clf,'PaperType','A4');
set(clf,'Color',[1,1,1]);
subplot(211);
semilogx(frequentie, abs(H))
axis([600 1600 0.0 1.2])
ylabel('amplitude','Fontsize',10)
hndl=title(fig_label,'Fontsize',10,'Fontweight','bold');
h=get(hndl);
set(gca, 'XTick', [600 700 800 900 1000 1100 1200 1300 1400 1500 1600],'Fontsize',8)
set(gca, 'YTick', [0.0 0.2 0.4 0.6 0.8 1.0 1.2],'Fontsize',8)
grid;

subplot(212);
semilogx(frequentie, angle(H)/pi)
axis([600 1600 -0.6 0.6])
xlabel('frequency [Hz]','Fontsize',10)
ylabel('phase [rad]','Fontsize',10)
set(gca, 'XTick', [600 700 800 900 1000 1100 1200 1300 1400 1500 1600],'Fontsize',8)
set(gca, 'YTick', [-0.6 -0.4 -0.2 0.0 0.2 0.4 0.6],'Fontsize',8)
grid;
