您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

91 行
2.7KB

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