% Frequenzgang
% All voltages are measured in peak (NOT peak-to-peak!)
input_amp = 16;
f = [35 35.5 36 36.5 37 37.5 38 38.5 39 39.5 39.75 40 40.25 40.5 40.75 41 41.25 41.5 42 42.5 43 43.5 44 44.5 45]*1000;
H = [3.75 5 8 12 20 33.5 55 110 205 310 380 440 530 510 480 330 220 165 84 45 27.5 16.5 9.75 7.25 5.75]*0.001;

H=H/input_amp;

figure(1);
plot(f,20*log10(H));
grid on;
xlabel('Frequency / Hz');
ylabel('Magnitude / dB');
title('Frequency Response at 8V_{ac} and 60cm distance, maximum at circa 40.4kHz');

angle = -90:5:90;
ampl = [570 560 540 500 430 390 320 265 190 145 100 73 55 49 45 47 47 42 43]*0.001;
ampl = [fliplr(ampl(2:length(ampl))) ampl];
ampl = 20*log10(ampl/max(ampl));

figure(2);
plot(angle, ampl);
grid on;
xlabel('Angle / \circ');
ylabel('Attenuation / dB');
title('Attenuation over angle, -3dB at circa \pm20\circ');

figure(3);
pp(angle/180*pi, ampl, [-25 0], 'ThetaStartAngle', 90);
ylabel('Attenuation / dB');

dist = 0.3:0.1:1.8;
dist_att = [1150 900 700 580 500 420 370 330 300 275 225 250 200 200 110 165]*0.001;
dist_att = 20*log10(dist_att/input_amp);
figure(4);
plot(dist, dist_att);
grid on;
xlabel('Distance / m');
ylabel('Attenuation / dB');
title('Attenuation over distance, circa -12dB/m');
