Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tema SCPI
- Incarcarea datelor
- clear all
- data1 = load('Set1.mat');
- data2 = load('Set2.mat');
- data3 = load('Set3.mat');
- time1 = data1.set_date_n_n_1.Time;
- values1 = data1.set_date_n_n_1.Data;
- plot(time1, values1);
- xlabel('Timp [s]');
- ylabel('Valori');
- title('Date initiale');
- time2 = data2.set_date_n_n_2.Time;
- values2 = data2.set_date_n_n_2.Data;
- plot(time2, values2);
- xlabel('Timp [s]');
- ylabel('Valori');
- title('Date initiale');
- time3 = data3.set_date_n_n_3.Time;
- values3 = data3.set_date_n_n_3.Data;
- plot(time3, values3);
- xlabel('Timp [s]');
- ylabel('Valori');
- title('Date initiale');
- Filtrarea datelor
- Set 1
- x_1 = data1.set_date_n_n_1.Data;
- a = 1;
- Ws1 = 5; % il alegem ca sa arate graficul cat mai bine
- b = (1/Ws1) * ones(1, Ws1);
- y_1 = filter(b, a, x_1)
- figure;
- plot(time1, values1, 'b', time1, y_1, 'r');
- title('Filtrare date - Set 1');
- legend('Date brute', 'Date filtrate');
- Set 2
- x_2 = data2.set_date_n_n_2.Data;
- a = 1;
- Ws2 = 5; % il alegem ca sa arate graficul cat mai bine
- b = (1/Ws2) * ones(1, Ws2);
- y_2 = filter(b, a, x_2)
- figure;
- plot(time2, values2, 'b', time2, y_2, 'r');
- title('Filtrare date - Set 2');
- legend('Date brute', 'Date filtrate');
- Set 3
- x_3 = data3.set_date_n_n_3.Data;
- a = 1;
- Ws3 = 5; % il alegem ca sa arate graficul cat mai bine
- b = (1/Ws3) * ones(1, Ws3);
- y_3 = filter(b, a, x_3)
- figure;
- plot(time3, values3, 'b', time3, y_3, 'r');
- title('Filtrare date - Set 3');
- legend('Date brute', 'Date filtrate');
- Afisarea raspunsului mediu
- min_length = min([length(y_1), length(y_2), length(y_3)]);
- y_1 = y_1(1:min_length);
- y_2 = y_2(1:min_length);
- y_3 = y_3(1:min_length);
- % Calculul mediei aritmetice
- mean_values = (y_1 + y_2 + y_3)/3;
- % Afisarea noului semnal
- figure;
- plot(mean_values, 'LineWidth', 1.5);
- title('Semnalul mediu');
- xlabel('Puncte de date');
- ylabel('Amplitudine');
- grid on;
- Informatii despre sistem:
- Timp tranzitoriu
- % Valoarea stationara
- y_stationar = mean(mean_values(end-10:end));
- % Prag de 2%
- threshold = 0.02 * y_stationar;
- % Identificarea timpului tranzitoriu
- tt_idx = find(abs(mean_values - y_stationar) > threshold, 1, 'last');
- tt = time1(tt_idx);
- Timp de crestere
- % 10% din valoarea stationara
- tc_10 = 0.1 * y_stationar;
- % 90% din valoarea stationara
- tc_90 = 0.9 * y_stationar;
- tc_idx_10 = find(mean_values >= tc_10, 1);
- tc_idx_90 = find(mean_values >= tc_90, 1);
- tc = time1(tc_idx_90) - time1(tc_idx_10);
- Timp mort
- threshold_mort = 0.01 * y_stationar;
- timp_mort_idx = find(mean_values > threshold_mort, 1);
- timp_mort = time1(timp_mort_idx);
- Suprareglaj
- max_val = max(mean_values);
- suprareglaj = ((max_val - y_stationar) / y_stationar);
- Te (Constanta de timp echivalenta)
- Te_min = tc / 16;
- Te_max = tc / 9;
- Valoarea stationara
- y_stationar = mean(mean_values(end-10:end));
- Tabel cu rezultate
- results = table(tt, tc, timp_mort, suprareglaj, Te_min, y_stationar, ...
- 'VariableNames', {'Timp_tranzitoriu', 'Timp_crestere', 'Timp_mort', ...
- 'Suprareglaj', 'Te_min', 'y_stationar'});
- disp(results);
- Identificarea ordinului sistemului:
- disp('Intrucat suprareglajul > 0 si observam oscilatii, sistemul este de ordin 2.');
- Identificarea sistemului:
- %% Determinarea lui T0 din varfurile alese
- % Varfuri la indexurile 39 și 47
- N1 = 42;
- N2 = 50;
- % Pas de esantionare: 100 ms = 0.1 s
- Ts = 0.1;
- % Calcul T0 = (N2 - N1) * Ts
- T0 = (N2 - N1) * 2
- fprintf('T0 determinat din grafic = %.2f s ', T0);
- % Calcul zeta
- Mp = suprareglaj;
- lnMp = log(Mp);
- zeta = -lnMp / sqrt(pi^2 + (lnMp)^2);
- fprintf('Zeta = %.4f\n', zeta);
- % Calcul omega_n
- omega_n = 2*pi / ( T0 * sqrt(1 - zeta^2) );
- fprintf('omega_n = %.4f rad/s\n', omega_n);
- % Construirea functiei de transfer
- num = omega_n^2;
- den = [1, 2*zeta*omega_n, omega_n^2];
- G = tf(num, den); % Obiect Transfer Function
- disp('Functia de transfer estimata este:');
- tf = sprintf('G(s) = %.3g / ( s^2 + %.3g s + %.3g )', ...
- omega_n^2, 2*zeta*omega_n, omega_n^2);
- disp(tf);
- disp(G);
- [Stabilitatea lui G]
- den = [1 2.26 63];
- p = roots(den);
- disp('Polii sistemului sunt:');
- disp(p);
- if all(real(p) < 0)
- disp('G este stabil (toti polii au parte reala negativa).');
- else
- disp('G NU este stabil (exista poli cu parte reala >= 0).');
- end
- Calculul PID:
- Kr = 3.62
- Ti = 1.99
- Tf = 0.28
- Td = 0.6
- Calculul RST:
- % G - functia de transfer
- T = 0.1;
- G_discretized = c2d(G, T, 'zoh')
- integrator = tf([1], [1 -1], T); % 1/(1-z^-1)
- %%%%%%%%%%%%%%%%%%%%%%%%%
- G_integrator = G_discretized * integrator;
- [num_discretized, den_discretized] = tfdata(G_discretized, 'v');
- num_discretized
- den_discretized
- clear tf
- G_z_minus1 = tf(num_discretized, den_discretized, T, 'Variable', 'z^-1');
- G_z_minus1
- A = [-1.875 0.8802]
- B = [0.002689 0.002577]
- omega = 0.5026;
- zeta = 0.75;
- num = omega^2;
- den = [1, 2 * zeta * omega, omega^2];
- Hi = tf(num, den)
- Hi_discretized = c2d(Hi, T, 'zoh');
- Hi_discretized
- P = [-1.925 0.9274]
- % ns = 1
- % nr = 1
- % np <= 3
- 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]
- P = [1 ; -1.925 ; 0.9274 ; 0]
- syms s1 r0 r1
- Coloana = [1; s1; r0; r1]
- solutii = linsolve(Matrice, P)
- R = [-9.1661 8.6594]
- S = [1 -0.0254]
- Pentru testare:
- PID discretizat:
- num_PID = [6.34, 8.21, 3.62];
- den_PID = [0.56, 1.99, 0];
- PID_tf = tf(num_PID, den_PID);
- T = 0.1;
- PID_tf_discretized = c2d(PID_tf, T, 'zoh')
- [num_PID_discretized, den_PID_discretized] = tfdata(PID_tf_discretized, 'v');
- num_PID_discretized
- den_PID_discretized
- % A mers pentru referinta 90 si comanda 169 la pornire si dupa 255
- RST:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement