%12bit
data12=[ 325, 325, 338, 336, 343, 308, 214, 61, 110, 752, 1765, 2678, 3063, 2509, 1638, 676, 49, 32, 158, 254, 288, 272, 294, 295, 296, 301, 319, 333, 324, 328, 363, 363, 373, 392, 391, 417, 443, 460, 486, 498, 528, 526, 544, 581, 582, 615, 629, 668, 748, 774, 810, 852, 864, 857, 827, 808, 764, 672, 582, 473, 374, 318, 293, 268, 329, 328, 337, 334, 346, 309, 212, 60, 179, 883, 1766, 2683, 3066, 2508, 1635, 552, 29, 31, 160, 262, 286, 272, 291, 299, 301, 297, 318, 340, 323, 334, 369, 367, 376, 395, 396, 426, 441, 460, 491, 490, 526, 532, 547, 581, 583, 618, 661, 663, 749, 775, 805, 852, 865, 858, 832, 806, 766, 671, 572, 474, 380, 317, 290, 273, 327, 329, 338, 335, 346, 308, 214, 55, 115, 865, 1770, 2681, 3062, 2510, 1638, 671, 28, 37, 155, 258, 290, 272, 287, 291, 301, 301, 311, 338, 332, 326, 363, 368, 376, 395, 385, 422, 445, 462, 488, 500, 527, 515, 540, 585, 584, 601, 640, 671, 744, 774, 813, 854, 859, 855, 836, 806, 760, 678, 578, 470, 377, 321, 288, 268, 332, 326, 337, 336, 347, 310, 210, 62, 120, 729, 1756, 2688, 3066, 2509, 1638, 678, 54, 35, 155, 263, 280, 270, 292, 297, 298, 299, 319, 335, 325, 330, 366, 359, 378, 398, 395, 421, 441, 452, 487, 498, 526, 525, 547, 585, 581, 614, 644, 671, 747, 768, 814, 855, 862, 860, 833, 805, 769, 672, 588, 476, 378, 319, 289, 274, 330, 329, 335, 336, 351, 306, 214, 66, 122, 863, 1766, 2678, 3069, 2509, 1639, 676, 30, 37, 155, 261, 293, 266, 291, 304, 302, 299, 320, 341, 327, 327, 368, 370, 378, 396, 397, 432, 445, 459, 489, 498, 530, 530, 545, 585, 585, 614, 639, 665, 747, 777, 817, 853, 853, 860, 837, 803, 764, 683, 577, 474, 373, 318, 290, 271, 331, 324, 334, 336, 348, 305, 212, 88, 179, 868, 1771, 2686, 3066, 2510, 1640, 536, 27, 25, 155, 264, 290, 272, 291, 303, 301, 293, 320, 341, 327, 336, 368, 367, 373, 397, 398, 421, 435, 464, 492, 495, 529, 529, 547, 584, 586, 611, 637, 668, 744, 777, 811, 850, 860, 861, 832, 806, 770, 671, 572, 471, 378, 318, 288, 272, 328, 329, 334, 336, 350, 311, 211, 64, 120, 865, 1761, 2682, 3068, 2507, 1640, 677, 31, 35, 151, 262, 292, 269, 288, 300, 299, 295, 320, 338, 327, 316, 365, 366, 373, 395, 398, 423, 440, 460, 490, 497, 522, 530, 549, 583, 584, 608, 644, 675, 741, 773, 816, 852, 858, 861, 833, 806, 756, 680, 580, 470, 376, 319, 291, 269, 331, 326, 335, 338, 347, 306, 216, 66, 116, 732, 1757, 2684, 3060, 2524, 1641, 671, 58, 35, 156, 261, 292, 272, 288, 294, 301, 303, 316, 338, 331, 326, 366, 368, 375, 392, 387, 426, 443, 452, 492, 501, 523, 532, 548, 583, 584, 614, 640, 670, 745, 776, 817, 844, 862, 863, 830, 802, 767, 682, 581, 468, 374, 317, 289, 272, 329, 329, 339, 338, 346, 309, 218, 65, 109, 733, 1629, 2674, 3067, 2508, 1640, 677, 52, 16, 156, 262, 288, 269, 288, 299, 292, 300, 323, 333, 328, 330, 366, 362, 376, 394, 411, 414, 443, 457, 482, 498, 528, 531, 547, 579, 586, 606, 638, 672, 747, 774, 812, 847, 864, 863, 825, 806, 767, 679, 584, 489, 377, 319, 284, 272, 321, 326, 340, 339, 344, 310, 218, 64, 117, 881, 1770, 2674, 3067, 2514, 1635, 668, 32, 36, 157, 258, 292, 273, 285, 298, 300, 302, 319, 333, 330, 332, 362, 366, 377, 395, 393, 420, 448, 463, 486, 499, 528, 525, 548, 583, 583, 609, 643, 668, 738, 776, 816, 845, 859, 862, 833, 803, 761, 682, 574, 465, 390, 319, 287, 268, 331, 326, 338, 337, 349, 307, 212, 66, 117, 732, 1768, 2681, 3065, 2509, 1640, 678, 48, 34, 156, 260, 285, 270, 291, 293, 300, 302, 318, 337, 329, 330, 365, 356, 376, 399, 395, 419, 439, 454, 488, 494, 528, 528, 546, 585, 584, 613, 643, 662, 746, 781, 811, 849, 861, 863, 831, 803, 766, 684, 581, 471, 375, 318, 289, 266, 324, 330, 336, 336, 347, 307, 203, 64, 120, 734, 1645, 2680, 3067, 2508, 1639, 678, 54, 17, 158, 263, 285, 270, 291, 295, 298, 302, 315, 335, 330, 331, 364, 363, 378, 393, 389, 424, 442, 448, 490, 499, 524, 529, 549, 581, 582, 616, 642, 671, 745, 774, 815, 845, 862, 865, 830, 803, 770, 680, 584, 475, 374, 322, 281, 270, 327, 326, 338, 338, 345, 308, 216, 59, 134, 873, 1766, 2682, 3066, 2507, 1637, 643, 24, 32, 157, 258, 286, 274, 289, 294, 297, 300, 315, 334, 330, 335, 360, 365, 375, 392, 394, 426, 440, 454, 492, 497, 523, 534, 547, 579, 586, 617, 637, 669, 748, 776, 812, 851, 862, 863, 822, 803, 769, 694, 574, 472, 379, 317, 285, 272, 320, 329, 337, 333, 347, 311, 214, 58, 117, 738, 1752, 2675, 3068, 2508, 1627, 680, 57, 27, 157, 264, 287, 268, 292, 298, 295, 296, 316, 337, 322, 329, 368, 364, 373, 391, 392, 423, 439, 448, 488, 499, 525, 524, 546, 583, 578, 616, 641, 661, 746, 773, 803, 851, 860, 856, 825, 797, 766, 677, 567, 472, 374, 314, 289, 271, 326, 330, 335, 330, 346, 309, 207, 63, 118, 731, 1618, 2645, 3067, 2509, 1640, 679, 54, 15, 154, 261, 285, 274, 293, 289, 302, 303, 316, 336, 330, 325, 366, 370, 375, 392, 395, 425, 439, 449, 482, 499, 518, 526, 549, 582, 585, 609, 642, 667, 745, 783, 810, 854, 866, 862, 832, 808, 767, 675, 590, 484, 370, 322, 294, 269, 326, 329, 338, 323, 347, 312, 215, 57, 118, 868, 1766, 2682, 3067, 2511, 1635, 677, 30, 32, 157, 262, 286, 269, 290, 301, 292, 298, 321, 339, 327, 327, 367, 367, 369, 396, 395, 415, 444, 461, 485, 499, 529, 525, 546, 586, 582, 610, 642, 670, 745, 770, 814, 853, 855, 862, 834, 803, 766, 676, 571, 472, 379, 318, 291, 269];
step12 = 1; % 1us pro 12bit
max12=4096;

%8bit
data8=[20, 20, 20, 21, 21, 21, 20, 16, 11, 2, 4, 30, 72, 120, 167, 191, 179, 139, 92, 42, 7, 0, 3, 10, 15, 18, 17, 17, 18, 18, 18, 18, 18, 20, 21, 21, 20, 21, 23, 23, 23, 24, 24, 25, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 36, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 4, 4, 30, 72, 120, 167, 190, 179, 139, 92, 42, 7, 0, 3, 9, 16, 18, 18, 17, 18, 19, 18, 20, 18, 19, 21, 21, 20, 21, 22, 23, 23, 24, 24, 24, 26, 26, 27, 28, 29, 30, 31, 33, 33, 32, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 10, 2, 4, 30, 72, 119, 167, 191, 179, 139, 92, 42, 7, 0, 3, 9, 16, 18, 17, 17, 17, 19, 18, 18, 18, 20, 21, 21, 20, 21, 23, 23, 22, 24, 24, 24, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 16, 11, 2, 7, 30, 72, 120, 167, 191, 173, 138, 92, 42, 7, 0, 4, 10, 15, 18, 17, 16, 18, 18, 18, 18, 18, 20, 21, 21, 19, 20, 23, 23, 22, 24, 24, 24, 26, 27, 27, 28, 30, 30, 32, 33, 32, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 2, 4, 30, 72, 120, 167, 190, 179, 139, 92, 42, 7, 0, 3, 9, 15, 18, 17, 17, 18, 19, 19, 18, 18, 19, 21, 21, 19, 21, 22, 22, 23, 24, 24, 24, 26, 27, 27, 28, 29, 30, 31, 33, 33, 32, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 2, 4, 30, 72, 120, 167, 191, 179, 139, 92, 42, 7, 0, 3, 9, 16, 18, 17, 17, 18, 19, 18, 18, 19, 20, 21, 21, 20, 21, 22, 23, 23, 24, 25, 24, 26, 27, 28, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 39, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 16, 11, 2, 7, 30, 72, 120, 167, 191, 176, 139, 92, 42, 7, 0, 3, 9, 15, 18, 17, 17, 18, 18, 18, 18, 18, 20, 21, 21, 20, 21, 23, 23, 22, 24, 24, 24, 26, 27, 27, 28, 30, 30, 32, 33, 32, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 16, 11, 2, 4, 30, 72, 120, 167, 191, 179, 139, 92, 42, 7, 0, 3, 10, 15, 18, 17, 17, 18, 18, 19, 18, 18, 20, 21, 21, 19, 21, 22, 23, 22, 23, 25, 24, 26, 26, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 2, 7, 30, 72, 120, 167, 192, 173, 139, 92, 42, 7, 0, 4, 9, 15, 18, 17, 17, 18, 18, 19, 18, 18, 20, 21, 21, 20, 21, 22, 22, 23, 24, 24, 24, 26, 27, 27, 28, 30, 30, 32, 32, 33, 33, 35, 36, 36, 37, 39, 40, 43, 46, 48, 49, 20, 20, 20, 21, 20, 21, 20, 17, 11, 2, 4, 29, 72, 120, 167, 190, 179, 139, 92, 42, 7, 0, 3, 9, 15, 18, 17, 17, 18, 19, 18, 20, 18, 20, 21, 21, 20, 20, 22, 23, 23, 24, 24, 24, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 22, 20, 17, 11, 4, 4, 30, 72, 120, 167, 190, 179, 139, 92, 42, 7, 0, 3, 10, 15, 18, 18, 17, 18, 18, 18, 18, 19, 20, 21, 21, 19, 21, 22, 23, 23, 24, 25, 24, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 39, 42, 46, 48, 48, 20, 20, 20, 21, 20, 21, 20, 17, 11, 4, 4, 29, 72, 119, 165, 190, 179, 139, 92, 42, 10, 0, 3, 9, 15, 18, 18, 16, 18, 18, 18, 19, 18, 20, 21, 21, 20, 21, 22, 23, 23, 24, 24, 24, 25, 27, 27, 28, 30, 30, 31, 32, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 10, 2, 7, 29, 72, 120, 167, 191, 176, 139, 92, 42, 7, 0, 3, 10, 15, 18, 17, 16, 18, 18, 19, 18, 18, 20, 21, 21, 19, 21, 23, 23, 23, 23, 24, 24, 26, 27, 27, 28, 30, 30, 32, 33, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 20, 21, 21, 20, 17, 11, 2, 4, 30, 72, 120, 167, 191, 179, 139, 92, 42, 7, 0, 3, 9, 16, 18, 17, 16, 18, 18, 18, 19, 18, 20, 21, 21, 20, 21, 23, 22, 22, 24, 24, 24, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 36, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 2, 7, 30, 72, 120, 167, 191, 174, 139, 92, 42, 7, 0, 3, 10, 16, 18, 17, 17, 18, 18, 18, 18, 19, 20, 21, 21, 20, 21, 22, 23, 23, 24, 25, 24, 26, 27, 27, 28, 30, 30, 31, 33, 33, 33, 35, 36, 37, 37, 39, 40, 42, 46, 48, 49, 20, 20, 20, 21, 21, 21, 20, 17, 11, 2, 4, 30, 72, 120, 167, 191, 179, 139, 92, 42, 7, 0, 3, 9, 15, 18, 17, 17, 18, 18, 18, 18, 18, 19, 21, 21, 20, 21, 23, 23, 22, 24, 24, 24, 26, 27, 27, 27, 30, 30, 31, 33, 32, 33, 35, 36, 36, 36, 39, 40, 42, 46, 48, 49];
step8 = 0.785; % üs pro 8bit
max8=256;

% 6bit
data6=[5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 29, 39, 46, 47, 41, 32, 22, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 1, 5, 13, 22, 32, 41, 46, 47, 41, 32, 22, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,12 ), 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 5, 13, 22, 31, 40, 46, 47, 41, 32, 22, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 1, 5, 12, 20, 29, 39, 46, 47, 41, 32, 22, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 30, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5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 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 30, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 30, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,12 ), 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 29, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 0, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 6, 6, 6, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 29, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 0, 0, 4, 11, 20, 29, 39, 46, 47, 41, 32, 23, 12, 4, 0, 0, 1, 2, 3, 4 *ones(1,11 ), 5, 5, 5, 4, 5, 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8];
step6 = 0.643; % us pro 6bit
max6=64

vref= 3.324;

x12=reshape(data12,64,16)';
x8=reshape(data8,64,16)';
x6=reshape(data6,64,16)';
close all;


samples = length(x12);
s12=(1:samples)*step12;
x12=x12/max12*vref;
figure(1);
hold on;
for i=1:1:4
  plot(s12,x12(i,:),'-x');
endfor
grid on;
xlabel("time [us]");
ylabel("voltage [V]");
h=get(gcf, "currentaxes");
set(h, "fontsize", 12, "linewidth", 2);


samples = length(x8);
s8=(1:samples)*step8;
x8=x8/max8*vref;
figure(2);
hold on;
for i=1:1:4
  plot(s8,x8(i,:),'-x');
endfor
grid on;
xlabel("time [us]");
ylabel("voltage [V]");
h=get(gcf, "currentaxes");
set(h, "fontsize", 12, "linewidth", 2);


samples = length(x6);
s6=(1:samples)*step6;
x6=x6/max6*vref;
figure(3);
hold on;
for i=1:1:4
  plot(s6,x6(i,:),'-x');
endfor
grid on;
xlabel("time [us]");
ylabel("voltage [V]");
h=get(gcf, "currentaxes");
set(h, "fontsize", 12, "linewidth", 2);



figure(4);
hold on;
size(s6)
size(x6)
  plot(s6,x6(1,:),'-xr');
  plot(s8,x8(1,:),'-xg');
  plot(s12,x12(1,:),'-xb');
  legend("6bit","8bit","12bit")

grid on;
xlabel("time [us]");
ylabel("voltage [V]");
h=get(gcf, "currentaxes");
set(h, "fontsize", 12, "linewidth", 2);




