You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.9KB

  1. %% Plot theory only
  2. S = asymptote(S_smaller,S_larger,f,Fc);
  3. P = mod(P,pi);
  4. figure;
  5. ax1 = subplot(2,1,1);
  6. semilogx(f,A,f,S)
  7. ylabel('Magnitude [dB]','Fontsize',10);
  8. xlabel('Frequency [Hz]','Fontsize',10);
  9. xlim([f_start,f_stop]);
  10. legend('Theory','Asymptote');
  11. grid on
  12. title('RC-circuit Bodeplot Theory')
  13. ax2 = subplot(2,1,2);
  14. semilogx(f,P)
  15. ylabel('Phase [rad]','Fontsize',10);
  16. xlabel('Frequency [Hz]','Fontsize',10);
  17. xlim([f_start,f_stop]);
  18. legend('Theory');
  19. grid on
  20. linkaxes([ax1,ax2],'x')
  21. %% Run the measurements
  22. if theory_only == false
  23. data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements);
  24. %% Plotting
  25. %% Process the data
  26. A_mean = mean(data.magnitude,1);
  27. P_mean = mean(data.phase,1);
  28. A_std = zeros(1,data.steps);
  29. P_std = zeros(1,data.steps);
  30. if data.measurements > 1
  31. A_std = std(data.magnitude,1);
  32. P_std = std(data.phase,1);
  33. end
  34. A_mean_log = 20*log10(A_mean);
  35. A_std_log_neg = A_mean_log - 20*log10(A_mean - A_std);
  36. A_std_log_pos = 20*log10(A_mean + A_std) - A_mean_log;
  37. %% plot average measurement, theory and asymptote.
  38. figure;
  39. ax1 = subplot(2,1,1);
  40. semilogx(data.frequency,A_mean_log,f,A,f,S)
  41. ylabel('Magnitude [dB]','Fontsize',10);
  42. xlabel('Frequency [Hz]','Fontsize',10);
  43. legend('Average Measurement','Theory','Asymptote');
  44. grid on
  45. title('RLC-circuit Bodeplot')
  46. ax2 = subplot(2,1,2);
  47. semilogx(data.frequency,P_mean,f,P)
  48. ylabel('Phase [rad]','Fontsize',10);
  49. xlabel('Frequency [Hz]','Fontsize',10);
  50. legend('Average Measurement','Theory');
  51. grid on
  52. linkaxes([ax1,ax2],'x')
  53. %% plot avearage measurement with standard deviation and theory.
  54. figure;
  55. ax1 = subplot(2,1,1);
  56. errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos)
  57. ax1.XScale = 'log';
  58. hold on
  59. semilogx(f,A)
  60. hold off
  61. ylabel('Magnitude [dB]','Fontsize',10);
  62. xlabel('Frequency [Hz]','Fontsize',10);
  63. legend('Average Measurement','Theory');
  64. grid on
  65. title('RLC-circuit Bodeplot')
  66. ax2 = subplot(2,1,2);
  67. errorbar(data.frequency,P_mean,P_std);
  68. ax2.XScale = 'log';
  69. hold on
  70. semilogx(f,P)
  71. hold off
  72. ylabel('Phase [rad]','Fontsize',10);
  73. xlabel('Frequency [Hz]','Fontsize',10);
  74. legend('Average Measurement','Theory');
  75. grid on
  76. linkaxes([ax1,ax2],'x')
  77. %% plot avearage measurement with standard deviation.
  78. figure;
  79. ax1 = subplot(2,1,1);
  80. errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos)
  81. ax1.XScale = 'log';
  82. ylabel('Magnitude [dB]','Fontsize',10);
  83. xlabel('Frequency [Hz]','Fontsize',10);
  84. legend('Average Measurement');
  85. grid on
  86. title('RLC-circuit Bodeplot')
  87. ax2 = subplot(2,1,2);
  88. errorbar(data.frequency,P_mean,P_std);
  89. ax2.XScale = 'log';
  90. ylabel('Phase [rad]','Fontsize',10);
  91. xlabel('Frequency [Hz]','Fontsize',10);
  92. legend('Average Measurement');
  93. grid on
  94. linkaxes([ax1,ax2],'x')
  95. end