diff --git a/OOequipment/RC_TransferFunction.mlx b/OOequipment/RC_TransferFunction.mlx index 47eb0b3..8c32111 100644 Binary files a/OOequipment/RC_TransferFunction.mlx and b/OOequipment/RC_TransferFunction.mlx differ diff --git a/OOequipment/RC_TransferFunction_solution.mlx b/OOequipment/RC_TransferFunction_solution.mlx new file mode 100644 index 0000000..8c32111 Binary files /dev/null and b/OOequipment/RC_TransferFunction_solution.mlx differ diff --git a/OOequipment/RLC_TransferFunction.mlx b/OOequipment/RLC_TransferFunction.mlx index 2cde9cd..a86fb6d 100644 Binary files a/OOequipment/RLC_TransferFunction.mlx and b/OOequipment/RLC_TransferFunction.mlx differ diff --git a/OOequipment/RLC_TransferFunction_solution.mlx b/OOequipment/RLC_TransferFunction_solution.mlx new file mode 100644 index 0000000..a86fb6d Binary files /dev/null and b/OOequipment/RLC_TransferFunction_solution.mlx differ diff --git a/OOequipment/subfiles/RC_TransferFunction_script.m b/OOequipment/subfiles/RC_TransferFunction_script.m index e5287ab..34e1d1b 100644 --- a/OOequipment/subfiles/RC_TransferFunction_script.m +++ b/OOequipment/subfiles/RC_TransferFunction_script.m @@ -23,16 +23,24 @@ linkaxes([ax1,ax2],'x') %% Run the measurements if theory_only == false data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements); +%% Plotting %% Process the data - A_mean = mean(data.magnitude); - P_mean = mean(data.phase); - A_std = std(data.magnitude); - P_std = std(data.phase); + A_mean = mean(data.magnitude,1); + P_mean = mean(data.phase,1); + A_std = zeros(1,data.steps); + P_std = zeros(1,data.steps); + if data.measurements > 1 + A_std = std(data.magnitude,1); + P_std = std(data.phase,1); + end + A_mean_log = 20*log10(A_mean); + A_std_log_neg = A_mean_log - 20*log10(A_mean - A_std); + A_std_log_pos = 20*log10(A_mean + A_std) - A_mean_log; %% plot average measurement, theory and asymptote. figure; ax1 = subplot(2,1,1); - semilogx(data.frequency,20*log10(A_mean),f,A,f,S) + semilogx(data.frequency,A_mean_log,f,A,f,S) ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement','Theory','Asymptote'); @@ -49,21 +57,21 @@ if theory_only == false %% plot avearage measurement with standard deviation and theory. figure; ax1 = subplot(2,1,1); + errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos) ax1.XScale = 'log'; - errorbar(data.frequency,20*log10(A_mean),20*log10(A_std)) hold on semilogx(f,A) hold off ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); - legend('Average Measurement','Theory','Asymptote'); + legend('Average Measurement','Theory'); grid on title('RC-circuit Bodeplot') ax2 = subplot(2,1,2); - ax2.XScale = 'log'; errorbar(data.frequency,P_mean,P_std); + ax2.XScale = 'log'; hold on - semilogx(data.frequency,P_mean,f,P) + semilogx(f,P) hold off ylabel('Phase [rad]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); @@ -73,16 +81,16 @@ if theory_only == false %% plot avearage measurement with standard deviation. figure; ax1 = subplot(2,1,1); + errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos) ax1.XScale = 'log'; - errorbar(data.frequency,20*log10(A_mean),20*log10(A_std)) ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement'); grid on title('RC-circuit Bodeplot') ax2 = subplot(2,1,2); - ax2.XScale = 'log'; errorbar(data.frequency,P_mean,P_std); + ax2.XScale = 'log'; ylabel('Phase [rad]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement'); diff --git a/OOequipment/subfiles/RLC_TransferFunction_script.m b/OOequipment/subfiles/RLC_TransferFunction_script.m index 160035c..6f74c60 100644 --- a/OOequipment/subfiles/RLC_TransferFunction_script.m +++ b/OOequipment/subfiles/RLC_TransferFunction_script.m @@ -10,7 +10,7 @@ xlabel('Frequency [Hz]','Fontsize',10); xlim([f_start,f_stop]); legend('Theory','Asymptote'); grid on -title('RLC-circuit Bodeplot Theory') +title('RC-circuit Bodeplot Theory') ax2 = subplot(2,1,2); semilogx(f,P) ylabel('Phase [rad]','Fontsize',10); @@ -23,16 +23,24 @@ linkaxes([ax1,ax2],'x') %% Run the measurements if theory_only == false data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements); +%% Plotting %% Process the data - A_mean = mean(data.magnitude); - P_mean = mean(data.phase); - A_std = std(data.magnitude); - P_std = std(data.phase); + A_mean = mean(data.magnitude,1); + P_mean = mean(data.phase,1); + A_std = zeros(1,data.steps); + P_std = zeros(1,data.steps); + if data.measurements > 1 + A_std = std(data.magnitude,1); + P_std = std(data.phase,1); + end + A_mean_log = 20*log10(A_mean); + A_std_log_neg = A_mean_log - 20*log10(A_mean - A_std); + A_std_log_pos = 20*log10(A_mean + A_std) - A_mean_log; %% plot average measurement, theory and asymptote. figure; ax1 = subplot(2,1,1); - semilogx(data.frequency,20*log10(A_mean),f,A,f,S) + semilogx(data.frequency,A_mean_log,f,A,f,S) ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement','Theory','Asymptote'); @@ -49,21 +57,21 @@ if theory_only == false %% plot avearage measurement with standard deviation and theory. figure; ax1 = subplot(2,1,1); + errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos) ax1.XScale = 'log'; - errorbar(data.frequency,20*log10(A_mean),20*log10(A_std)) hold on semilogx(f,A) hold off ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); - legend('Average Measurement','Theory','Asymptote'); + legend('Average Measurement','Theory'); grid on title('RLC-circuit Bodeplot') ax2 = subplot(2,1,2); - ax2.XScale = 'log'; errorbar(data.frequency,P_mean,P_std); + ax2.XScale = 'log'; hold on - semilogx(data.frequency,P_mean,f,P) + semilogx(f,P) hold off ylabel('Phase [rad]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); @@ -73,16 +81,16 @@ if theory_only == false %% plot avearage measurement with standard deviation. figure; ax1 = subplot(2,1,1); + errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos) ax1.XScale = 'log'; - errorbar(data.frequency,20*log10(A_mean),20*log10(A_std)) ylabel('Magnitude [dB]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement'); grid on title('RLC-circuit Bodeplot') ax2 = subplot(2,1,2); - ax2.XScale = 'log'; errorbar(data.frequency,P_mean,P_std); + ax2.XScale = 'log'; ylabel('Phase [rad]','Fontsize',10); xlabel('Frequency [Hz]','Fontsize',10); legend('Average Measurement');