|
| 1 | + |
| 2 | +# Number of CSV files to load |
| 3 | +num_files = 8; |
| 4 | + |
| 5 | +# Load CSV files |
| 6 | +for i = 1:num_files |
| 7 | + var_uncalib_x(:,:,i) = csvread(["xcal_" char(i+48) ".csv"]); |
| 8 | + var_uncalib_y(:,:,i) = csvread(["ycal_" char(i+48) ".csv"]); |
| 9 | +endfor |
| 10 | + |
| 11 | +# Meshgrid for true x/y velocities |
| 12 | +xy_max = 120; |
| 13 | +dxy = 1; |
| 14 | +num_points = xy_max*2+1; |
| 15 | +tx = ty = linspace (-xy_max, xy_max, num_points); |
| 16 | +[xx_true, yy_true] = meshgrid (tx, ty); |
| 17 | + |
| 18 | +# Plot scales |
| 19 | +xy_ticks = -xy_max:10:xy_max; |
| 20 | +z_limits = [0.8, 1.2]; |
| 21 | +z_ticks = 0.8:0.01:1.2; |
| 22 | +c_limits_uncal_var = [.9, 1.0]; |
| 23 | +c_limits_scalar_var = [1.0, 1.1]; |
| 24 | +c_limits_cal_var = [.98, 1.02]; |
| 25 | + |
| 26 | +# Clip out of bounds data points |
| 27 | +var_uncalib_x(var_uncalib_x < 0.8) = 0.8; |
| 28 | +var_uncalib_y(var_uncalib_y < 0.8) = 0.8; |
| 29 | +var_uncalib_x(var_uncalib_x > 1.2) = 1.2; |
| 30 | +var_uncalib_y(var_uncalib_y > 1.2) = 1.2; |
| 31 | + |
| 32 | +# Compute average variation of uncalibrated sensors |
| 33 | +var_uncalib_avg_x = mean(var_uncalib_x, 3); |
| 34 | +var_uncalib_avg_y = mean(var_uncalib_y, 3); |
| 35 | + |
| 36 | +% Plot average X-axis variation |
| 37 | +figure 1; |
| 38 | +clf; |
| 39 | +mesh(xx_true, yy_true, var_uncalib_avg_x); |
| 40 | +xlim([-xy_max, xy_max]) |
| 41 | +ylim([-xy_max, xy_max]) |
| 42 | +xticks(xy_ticks) |
| 43 | +yticks(xy_ticks) |
| 44 | +zticks(z_ticks) |
| 45 | +zlim(z_limits) |
| 46 | +caxis(c_limits_uncal_var) |
| 47 | +title("Average X-Axis Variation") |
| 48 | +xlabel("True X Velocity (IPS)") |
| 49 | +ylabel("True Y Velocity (IPS)") |
| 50 | +zlabel("Resolution Variation (Measured Velocity / True Velocity)") |
| 51 | + |
| 52 | +% Plot average Y-axis variation |
| 53 | +figure 2; |
| 54 | +clf; |
| 55 | +mesh(xx_true, yy_true, var_uncalib_avg_y); |
| 56 | +xlim([-xy_max, xy_max]) |
| 57 | +ylim([-xy_max, xy_max]) |
| 58 | +xticks(xy_ticks) |
| 59 | +yticks(xy_ticks) |
| 60 | +zticks(z_ticks) |
| 61 | +zlim(z_limits) |
| 62 | +caxis(c_limits_uncal_var) |
| 63 | +title("Average Y-Axis Variation") |
| 64 | +xlabel("True X Velocity (IPS)") |
| 65 | +ylabel("True Y Velocity (IPS)") |
| 66 | +zlabel("Resolution Variation (Measured Velocity / True Velocity)") |
| 67 | + |
| 68 | +# Compute scalars versus measured velocity |
| 69 | +for i = 1:num_points |
| 70 | + for j = 1:num_points |
| 71 | + xx_meas(i,j) = var_uncalib_avg_x(i,j) * xx_true(i,j); |
| 72 | + yy_meas(i,j) = var_uncalib_avg_y(i,j) * yy_true(i,j); |
| 73 | + |
| 74 | + scalar_uncalib_avg_x(i,j) = 1 / var_uncalib_avg_x(i,j); |
| 75 | + scalar_uncalib_avg_y(i,j) = 1 / var_uncalib_avg_y(i,j); |
| 76 | + end |
| 77 | +end |
| 78 | + |
| 79 | +# Plot average X-axis scalars |
| 80 | +figure 3; |
| 81 | +clf; |
| 82 | +mesh(xx_meas, yy_meas, scalar_uncalib_avg_x); |
| 83 | +xlim([-xy_max, xy_max]) |
| 84 | +ylim([-xy_max, xy_max]) |
| 85 | +xticks(xy_ticks) |
| 86 | +yticks(xy_ticks) |
| 87 | +zticks(z_ticks) |
| 88 | +zlim(z_limits) |
| 89 | +caxis(c_limits_scalar_var) |
| 90 | +title("Average X-Axis Scalars") |
| 91 | +xlabel("Measured X Velocity (IPS)") |
| 92 | +ylabel("Measured Y Velocity (IPS)") |
| 93 | +zlabel("Resolution Scalars (True Velocity / Measured Velocity)") |
| 94 | + |
| 95 | +# Plot average Y-axis scalars |
| 96 | +figure 4; |
| 97 | +clf; |
| 98 | +mesh(xx_meas, yy_meas, scalar_uncalib_avg_y); |
| 99 | +xlim([-xy_max, xy_max]) |
| 100 | +ylim([-xy_max, xy_max]) |
| 101 | +xticks(xy_ticks) |
| 102 | +yticks(xy_ticks) |
| 103 | +zticks(z_ticks) |
| 104 | +zlim(z_limits) |
| 105 | +caxis(c_limits_scalar_var) |
| 106 | +title("Average Y-Axis Scalars") |
| 107 | +xlabel("Measured X Velocity (IPS)") |
| 108 | +ylabel("Measured Y Velocity (IPS)") |
| 109 | +zlabel("Resolution Scalars (True Velocity / Measured Velocity)") |
| 110 | + |
| 111 | +# Re-mesh scalars |
| 112 | +scalar_uncalib_avg_x_remesh = griddata(xx_meas, yy_meas, scalar_uncalib_avg_x, xx_true, yy_true); |
| 113 | +scalar_uncalib_avg_y_remesh = griddata(xx_meas, yy_meas, scalar_uncalib_avg_y, xx_true, yy_true); |
| 114 | + |
| 115 | +# Plot average X-axis scalars |
| 116 | +figure 5; |
| 117 | +clf; |
| 118 | +mesh(xx_true, yy_true, scalar_uncalib_avg_x_remesh); |
| 119 | +xlim([-xy_max, xy_max]) |
| 120 | +ylim([-xy_max, xy_max]) |
| 121 | +xticks(xy_ticks) |
| 122 | +yticks(xy_ticks) |
| 123 | +zticks(z_ticks) |
| 124 | +zlim(z_limits) |
| 125 | +caxis(c_limits_scalar_var) |
| 126 | +title("Average X-Axis Scalars") |
| 127 | +xlabel("Measured X Velocity (IPS)") |
| 128 | +ylabel("Measured Y Velocity (IPS)") |
| 129 | +zlabel("Resolution Scalars (True Velocity / Measured Velocity)") |
| 130 | + |
| 131 | +# Plot average Y-axis scalars |
| 132 | +figure 6; |
| 133 | +clf; |
| 134 | +mesh(xx_true, yy_true, scalar_uncalib_avg_y_remesh); |
| 135 | +xlim([-xy_max, xy_max]) |
| 136 | +ylim([-xy_max, xy_max]) |
| 137 | +xticks(xy_ticks) |
| 138 | +yticks(xy_ticks) |
| 139 | +zticks(z_ticks) |
| 140 | +zlim(z_limits) |
| 141 | +caxis(c_limits_scalar_var) |
| 142 | +title("Average Y-Axis Scalars") |
| 143 | +xlabel("Measured X Velocity (IPS)") |
| 144 | +ylabel("Measured Y Velocity (IPS)") |
| 145 | +zlabel("Resolution Scalars (True Velocity / Measured Velocity)") |
| 146 | + |
| 147 | +# Sparse grid for lookup table, values chosen by hand |
| 148 | +#lut_indices = [-100 -90 -80 -70 -65 -57 -50 -45 -40 -33 -27 -21 -15 -10 -7 -2 2 7 10 15 21 27 33 40 45 50 57 65 70 80 90 100]; |
| 149 | +lut_indices = [-100 -93 -88 -83 -78 -73 -68 -64 -59 -55 -50 -45 -41 -37 -33 -28 -26 -21 -17 -15 -12 -10 -7 -5 -3 0 3 5 7 10 12 15 17 21 26 28 33 37 41 45 50 55 59 64 68 73 78 83 88 93 100]; |
| 150 | +[xx_lut, yy_lut] = meshgrid (lut_indices, lut_indices); |
| 151 | + |
| 152 | +# Compute lookup table values |
| 153 | +#lut_scalars_x = griddata(xx_meas, yy_meas, scalar_uncalib_avg_x, xx_lut, yy_lut); |
| 154 | +#lut_scalars_y = griddata(xx_meas, yy_meas, scalar_uncalib_avg_y, xx_lut, yy_lut); |
| 155 | +lut_scalars_x = griddata(xx_true, yy_true, scalar_uncalib_avg_x_remesh, xx_lut, yy_lut); |
| 156 | +lut_scalars_y = griddata(xx_true, yy_true, scalar_uncalib_avg_y_remesh, xx_lut, yy_lut); |
| 157 | + |
| 158 | +# Overlap lookup table on scalar plots |
| 159 | +figure 5; |
| 160 | +hold on; |
| 161 | +mesh(xx_lut, yy_lut, lut_scalars_x) |
| 162 | +figure 6; |
| 163 | +hold on; |
| 164 | +mesh(xx_lut, yy_lut, lut_scalars_y) |
| 165 | + |
| 166 | +# Compute expected variation after implementing lookup table |
| 167 | +var_calib_avg_x = var_uncalib_avg_x .* interp2(xx_lut, yy_lut, lut_scalars_x, xx_true, yy_true); |
| 168 | +var_calib_avg_y = var_uncalib_avg_y .* interp2(xx_lut, yy_lut, lut_scalars_y, xx_true, yy_true); |
| 169 | + |
| 170 | +% Plot average X-axis variation after implementing lookup table |
| 171 | +figure 7; |
| 172 | +clf; |
| 173 | +mesh(xx_true, yy_true, var_calib_avg_x); |
| 174 | +xlim([-xy_max, xy_max]) |
| 175 | +ylim([-xy_max, xy_max]) |
| 176 | +xticks(xy_ticks) |
| 177 | +yticks(xy_ticks) |
| 178 | +zticks(z_ticks) |
| 179 | +zlim(z_limits) |
| 180 | +caxis(c_limits_cal_var) |
| 181 | +title("Average X-Axis Variation") |
| 182 | +xlabel("True X Velocity (IPS)") |
| 183 | +ylabel("True Y Velocity (IPS)") |
| 184 | +zlabel("Resolution Variation (Measured Velocity / True Velocity)") |
| 185 | + |
| 186 | +% Plot average Y-axis variation after implementing lookup table |
| 187 | +figure 8; |
| 188 | +clf; |
| 189 | +mesh(xx_true, yy_true, var_calib_avg_y); |
| 190 | +xlim([-xy_max, xy_max]) |
| 191 | +ylim([-xy_max, xy_max]) |
| 192 | +xticks(xy_ticks) |
| 193 | +yticks(xy_ticks) |
| 194 | +zticks(z_ticks) |
| 195 | +zlim(z_limits) |
| 196 | +caxis(c_limits_cal_var) |
| 197 | +title("Average Y-Axis Variation") |
| 198 | +xlabel("True X Velocity (IPS)") |
| 199 | +ylabel("True Y Velocity (IPS)") |
| 200 | +zlabel("Resolution Variation (Measured Velocity / True Velocity)") |
| 201 | + |
| 202 | +# Compute integer lookup table values. These are in increments of 0.2% per LSB |
| 203 | +# to minimize flash size |
| 204 | +lut_scalers_x_int = round((lut_scalars_x - 1) / .002); |
| 205 | +lut_scalers_y_int = round((lut_scalars_y - 1) / .002); |
| 206 | + |
| 207 | +lut_scalers_x_int(lut_scalers_x_int > 127) = 127; |
| 208 | +lut_scalers_x_int(lut_scalers_x_int < -128) = -128; |
| 209 | +lut_scalers_y_int(lut_scalers_y_int > 127) = 127; |
| 210 | +lut_scalers_y_int(lut_scalers_y_int < -128) = -128; |
| 211 | + |
| 212 | +# Save lookup table to CSV files |
| 213 | +csvwrite("lut_x.csv", lut_scalers_x_int) |
| 214 | +csvwrite("lut_y.csv", lut_scalers_y_int) |
| 215 | + |
0 commit comments