clear clc close all archivo = "adc_log_20260525_054227.txt"; Ke_adc = 3.3 / 4095; Vref_pwm = 12; PWM_mid = 512; PWM_max = 1023; ACS712_sens = 0.185; ADC_mid_i1 = 512; ADC_mid_i2 = 512; T = readtable(archivo); t = T.t_ms / 1000; A137 = T.A137; A138 = T.A138; A139 = T.A139; A140 = T.A140; A141 = T.A141; A142 = T.A142; A143 = T.A143; A144 = T.A144; theta = T.theta; theta_u = T.theta_u; theta_vel = T.theta_vel; pwm_a = T.pwm_a; pwm_b = T.pwm_b; pwm_c = T.pwm_c; enc_a = A140; enc_b = A143; enc_c = A144; i_a = ((A141 - ADC_mid_i1) * Ke_adc) / ACS712_sens; i_b = ((A142 - ADC_mid_i2) * Ke_adc) / ACS712_sens; v_a = ((pwm_a - PWM_mid) / PWM_mid) * Vref_pwm; v_b = ((pwm_b - PWM_mid) / PWM_mid) * Vref_pwm; v_c = ((pwm_c - PWM_mid) / PWM_mid) * Vref_pwm; figure plot(t, enc_a, "LineWidth", 1.4) hold on plot(t, enc_b, "LineWidth", 1.4) plot(t, enc_c, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("ADC value") title("Three-phase encoder raw signals") legend("A140", "A143", "A144", "Location", "best") figure plot(t, theta, "LineWidth", 1.4) hold on plot(t, theta_u, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("Angle [rad]") title("Rotor angle signals") legend("\theta", "\theta_u", "Location", "best") figure plot(t, theta_vel, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("Angular velocity [rad/s]") title("Rotor velocity") figure plot(t, pwm_a, "LineWidth", 1.4) hold on plot(t, pwm_b, "LineWidth", 1.4) plot(t, pwm_c, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("PWM value") title("PWM applied signals") legend("PWM A", "PWM B", "PWM C", "Location", "best") figure plot(t, v_a, "LineWidth", 1.4) hold on plot(t, v_b, "LineWidth", 1.4) plot(t, v_c, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("Voltage [V]") title("Estimated applied voltages") legend("v_a", "v_b", "v_c", "Location", "best") figure plot(t, i_a, "LineWidth", 1.4) hold on plot(t, i_b, "LineWidth", 1.4) grid on xlabel("Time [s]") ylabel("Current [A]") title("Measured current signals") legend("i_a", "i_b", "Location", "best") figure subplot(3,1,1) plot(t, enc_a, "LineWidth", 1.2) hold on plot(t, enc_b, "LineWidth", 1.2) plot(t, enc_c, "LineWidth", 1.2) grid on ylabel("ADC") title("Encoder") subplot(3,1,2) plot(t, i_a, "LineWidth", 1.2) hold on plot(t, i_b, "LineWidth", 1.2) grid on ylabel("Current [A]") title("Currents") subplot(3,1,3) plot(t, v_a, "LineWidth", 1.2) hold on plot(t, v_b, "LineWidth", 1.2) plot(t, v_c, "LineWidth", 1.2) grid on xlabel("Time [s]") ylabel("Voltage [V]") title("Applied voltages") legend("v_a", "v_b", "v_c", "Location", "best")