選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

95 行
2.8KB

  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);
  27. P_mean = mean(data.phase);
  28. A_std = std(data.magnitude);
  29. P_std = std(data.phase);
  30. A_mean_log = 20*log10(A_mean);
  31. A_std_log_neg = A_mean_log - 20*log10(A_mean - A_std);
  32. A_std_log_pos = 20*log10(A_mean + A_std) - A_mean_log;
  33. %% plot average measurement, theory and asymptote.
  34. figure;
  35. ax1 = subplot(2,1,1);
  36. semilogx(data.frequency,A_mean_log,f,A,f,S)
  37. ylabel('Magnitude [dB]','Fontsize',10);
  38. xlabel('Frequency [Hz]','Fontsize',10);
  39. legend('Average Measurement','Theory','Asymptote');
  40. grid on
  41. title('RC-circuit Bodeplot')
  42. ax2 = subplot(2,1,2);
  43. semilogx(data.frequency,P_mean,f,P)
  44. ylabel('Phase [rad]','Fontsize',10);
  45. xlabel('Frequency [Hz]','Fontsize',10);
  46. legend('Average Measurement','Theory');
  47. grid on
  48. linkaxes([ax1,ax2],'x')
  49. %% plot avearage measurement with standard deviation and theory.
  50. figure;
  51. ax1 = subplot(2,1,1);
  52. errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos)
  53. ax1.XScale = 'log';
  54. hold on
  55. semilogx(f,A)
  56. hold off
  57. ylabel('Magnitude [dB]','Fontsize',10);
  58. xlabel('Frequency [Hz]','Fontsize',10);
  59. legend('Average Measurement','Theory');
  60. grid on
  61. title('RC-circuit Bodeplot')
  62. ax2 = subplot(2,1,2);
  63. errorbar(data.frequency,P_mean,P_std);
  64. ax2.XScale = 'log';
  65. hold on
  66. semilogx(f,P)
  67. hold off
  68. ylabel('Phase [rad]','Fontsize',10);
  69. xlabel('Frequency [Hz]','Fontsize',10);
  70. legend('Average Measurement','Theory');
  71. grid on
  72. linkaxes([ax1,ax2],'x')
  73. %% plot avearage measurement with standard deviation.
  74. figure;
  75. ax1 = subplot(2,1,1);
  76. errorbar(data.frequency,A_mean_log,A_std_log_neg,A_std_log_pos)
  77. ax1.XScale = 'log';
  78. ylabel('Magnitude [dB]','Fontsize',10);
  79. xlabel('Frequency [Hz]','Fontsize',10);
  80. legend('Average Measurement');
  81. grid on
  82. title('RC-circuit Bodeplot')
  83. ax2 = subplot(2,1,2);
  84. errorbar(data.frequency,P_mean,P_std);
  85. ax2.XScale = 'log';
  86. ylabel('Phase [rad]','Fontsize',10);
  87. xlabel('Frequency [Hz]','Fontsize',10);
  88. legend('Average Measurement');
  89. grid on
  90. linkaxes([ax1,ax2],'x')
  91. end