Advertisement
aidanozo

Untitled

Jan 16th, 2025
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 5.63 KB | None | 0 0
  1. Tema SCPI
  2. Incarcarea datelor
  3. clear all
  4. data1 = load('Set1.mat');
  5. data2 = load('Set2.mat');
  6. data3 = load('Set3.mat');
  7.  
  8. time1 = data1.set_date_n_n_1.Time;  
  9. values1 = data1.set_date_n_n_1.Data;
  10. plot(time1, values1);
  11. xlabel('Timp [s]');
  12. ylabel('Valori');
  13. title('Date initiale');
  14.  
  15. time2 = data2.set_date_n_n_2.Time;  
  16. values2 = data2.set_date_n_n_2.Data;
  17. plot(time2, values2);
  18. xlabel('Timp [s]');
  19. ylabel('Valori');
  20. title('Date initiale');
  21.  
  22. time3 = data3.set_date_n_n_3.Time;  
  23. values3 = data3.set_date_n_n_3.Data;
  24. plot(time3, values3);
  25. xlabel('Timp [s]');
  26. ylabel('Valori');
  27. title('Date initiale');
  28. Filtrarea datelor
  29. Set 1
  30. x_1 = data1.set_date_n_n_1.Data;
  31. a = 1;
  32. Ws1 = 5; % il alegem ca sa arate graficul cat mai bine
  33. b = (1/Ws1) * ones(1, Ws1);
  34. y_1 = filter(b, a, x_1)
  35.  
  36. figure;
  37. plot(time1, values1, 'b', time1, y_1, 'r');
  38. title('Filtrare date - Set 1');
  39. legend('Date brute', 'Date filtrate');
  40. Set 2
  41. x_2 = data2.set_date_n_n_2.Data;
  42. a = 1;
  43. Ws2 = 5; % il alegem ca sa arate graficul cat mai bine
  44. b = (1/Ws2) * ones(1, Ws2);
  45. y_2 = filter(b, a, x_2)
  46.  
  47. figure;
  48. plot(time2, values2, 'b', time2, y_2, 'r');
  49. title('Filtrare date - Set 2');
  50. legend('Date brute', 'Date filtrate');
  51. Set 3
  52. x_3 = data3.set_date_n_n_3.Data;
  53. a = 1;
  54. Ws3 = 5; % il alegem ca sa arate graficul cat mai bine
  55. b = (1/Ws3) * ones(1, Ws3);
  56. y_3 = filter(b, a, x_3)
  57.  
  58. figure;
  59. plot(time3, values3, 'b', time3, y_3, 'r');
  60. title('Filtrare date - Set 3');
  61. legend('Date brute', 'Date filtrate');
  62. Afisarea raspunsului mediu
  63. min_length = min([length(y_1), length(y_2), length(y_3)]);
  64. y_1 = y_1(1:min_length);
  65. y_2 = y_2(1:min_length);
  66. y_3 = y_3(1:min_length);
  67.  
  68. % Calculul mediei aritmetice
  69. mean_values = (y_1 + y_2 + y_3)/3;
  70.  
  71. % Afisarea noului semnal
  72. figure;
  73. plot(mean_values, 'LineWidth', 1.5);
  74. title('Semnalul mediu');
  75. xlabel('Puncte de date');
  76. ylabel('Amplitudine');
  77. grid on;
  78. Informatii despre sistem:
  79. Timp tranzitoriu
  80. % Valoarea stationara
  81. y_stationar = mean(mean_values(end-10:end));
  82.  
  83. % Prag de 2%
  84. threshold = 0.02 * y_stationar;
  85.  
  86. % Identificarea timpului tranzitoriu
  87. tt_idx = find(abs(mean_values - y_stationar) > threshold, 1, 'last');
  88. tt = time1(tt_idx);
  89. Timp de crestere
  90. % 10% din valoarea stationara
  91. tc_10 = 0.1 * y_stationar;
  92.  
  93. % 90% din valoarea stationara
  94. tc_90 = 0.9 * y_stationar;
  95.  
  96. tc_idx_10 = find(mean_values >= tc_10, 1);
  97. tc_idx_90 = find(mean_values >= tc_90, 1);
  98.  
  99. tc = time1(tc_idx_90) - time1(tc_idx_10);
  100. Timp mort
  101. threshold_mort = 0.01 * y_stationar;
  102.  
  103. timp_mort_idx = find(mean_values > threshold_mort, 1);
  104.  
  105. timp_mort = time1(timp_mort_idx);
  106. Suprareglaj
  107. max_val = max(mean_values);
  108. suprareglaj = ((max_val - y_stationar) / y_stationar);
  109. Te (Constanta de timp echivalenta)
  110. Te_min = tc / 16;
  111. Te_max = tc / 9;
  112. Valoarea stationara
  113. y_stationar = mean(mean_values(end-10:end));
  114. Tabel cu rezultate
  115. results = table(tt, tc, timp_mort, suprareglaj, Te_min, y_stationar, ...
  116.     'VariableNames', {'Timp_tranzitoriu', 'Timp_crestere', 'Timp_mort', ...
  117.                       'Suprareglaj', 'Te_min', 'y_stationar'});
  118. disp(results);
  119. Identificarea ordinului sistemului:
  120. disp('Intrucat suprareglajul > 0 si observam oscilatii, sistemul este de ordin 2.');
  121. Identificarea sistemului:
  122. %% Determinarea lui T0 din varfurile alese
  123. % Varfuri la indexurile 39 și 47
  124. N1 = 42;
  125. N2 = 50;
  126.  
  127. % Pas de esantionare: 100 ms = 0.1 s
  128. Ts = 0.1;
  129.  
  130. % Calcul T0 = (N2 - N1) * Ts
  131. T0 = (N2 - N1) * 2
  132. fprintf('T0 determinat din grafic = %.2f s ', T0);
  133.  
  134. % Calcul zeta
  135. Mp   = suprareglaj;
  136. lnMp = log(Mp);
  137. zeta = -lnMp / sqrt(pi^2 + (lnMp)^2);
  138.  
  139. fprintf('Zeta = %.4f\n', zeta);
  140.  
  141. % Calcul omega_n
  142. omega_n = 2*pi / ( T0 * sqrt(1 - zeta^2) );
  143.  
  144. fprintf('omega_n = %.4f rad/s\n', omega_n);
  145.  
  146. % Construirea functiei de transfer
  147. num = omega_n^2;                        
  148. den = [1, 2*zeta*omega_n, omega_n^2];    
  149.  
  150. G = tf(num, den);  % Obiect Transfer Function
  151.  
  152. disp('Functia de transfer estimata este:');
  153. tf = sprintf('G(s) = %.3g / ( s^2 + %.3g s + %.3g )', ...
  154.                     omega_n^2, 2*zeta*omega_n, omega_n^2);
  155. disp(tf);
  156. disp(G);
  157. [Stabilitatea lui G]
  158. den = [1 2.26 63];
  159.  
  160. p = roots(den);
  161.  
  162. disp('Polii sistemului sunt:');
  163. disp(p);
  164.  
  165. if all(real(p) < 0)
  166.     disp('G este stabil (toti polii au parte reala negativa).');
  167. else
  168.     disp('G NU este stabil (exista poli cu parte reala >= 0).');
  169. end
  170. Calculul PID:
  171. Kr = 3.62
  172. Ti = 1.99
  173. Tf = 0.28
  174. Td = 0.6
  175. Calculul RST:
  176. % G - functia de transfer
  177.  
  178. T = 0.1;
  179.  
  180. G_discretized = c2d(G, T, 'zoh')
  181.  
  182. integrator = tf([1], [1 -1], T); % 1/(1-z^-1)
  183. %%%%%%%%%%%%%%%%%%%%%%%%%
  184. G_integrator = G_discretized * integrator;
  185.  
  186. [num_discretized, den_discretized] = tfdata(G_discretized, 'v');
  187. num_discretized
  188. den_discretized
  189.  
  190. clear tf  
  191.  
  192. G_z_minus1 = tf(num_discretized, den_discretized, T, 'Variable', 'z^-1');
  193.  
  194. G_z_minus1
  195.  
  196. A = [-1.875 0.8802]
  197. B = [0.002689 0.002577]
  198.  
  199. omega =  0.5026;
  200. zeta = 0.75;
  201.  
  202. num = omega^2;
  203. den = [1, 2 * zeta * omega, omega^2];
  204.  
  205. Hi = tf(num, den)
  206.  
  207. Hi_discretized = c2d(Hi, T, 'zoh');
  208. Hi_discretized
  209.  
  210. P = [-1.925 0.9274]
  211.  
  212. % ns = 1
  213. % nr = 1
  214. % np <= 3
  215.  
  216. Matrice = [1 0 0 0 ; -1.875 1 0.002689 0 ; 0.8802 -1.875 0.002577 0.002689 ; 0 0.8802 0 0.002577]
  217. P = [1 ; -1.925 ; 0.9274 ; 0]
  218. syms s1 r0 r1
  219. Coloana = [1; s1; r0; r1]
  220.  
  221. solutii = linsolve(Matrice, P)
  222. R = [-9.1661 8.6594]
  223. S = [1 -0.0254]
  224. Pentru testare:
  225. PID discretizat:
  226. num_PID = [6.34, 8.21, 3.62];
  227. den_PID = [0.56, 1.99, 0];
  228.  
  229. PID_tf = tf(num_PID, den_PID);
  230.  
  231. T = 0.1;
  232.  
  233. PID_tf_discretized = c2d(PID_tf, T, 'zoh')
  234.  
  235. [num_PID_discretized, den_PID_discretized] = tfdata(PID_tf_discretized, 'v');
  236.  
  237. num_PID_discretized
  238. den_PID_discretized
  239.  
  240. % A mers pentru referinta 90 si comanda 169 la pornire si dupa 255
  241. RST:
  242.  
  243.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement