Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

85 wiersze
2.5KB

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