Files
imdd_silas/projects/Lab_2024/bias_sweep_evaluation.m
2024-10-24 19:41:59 +02:00

170 lines
5.0 KiB
Matlab

filename = "C:\Users\sioe\Documents\High_Speed_Measurement_2024\bias_testing\PAM4_b2b_bias_sweep_20241023_130342_wh.mat";
a = load(filename);
wh2 = a.obj;
m = wh2.getStoValue('m',wh2.parameter.vbias.values(1),wh2.parameter.awg_vpp.values(1));
v_bias_vals = wh2.parameter.vbias.values;
awg_vpp_vals = wh2.parameter.awg_vpp.values;
ber_ffe= [];
ber_mlse= [];
rop_measured= [];
pd_in_measured= [];
rop_measured = [];
cnt = 0;
for awg_vpp_cur = awg_vpp_vals
cnt = cnt+1;
ber_ffe(cnt,:) = wh2.getStoValue('ber_ffe',v_bias_vals,awg_vpp_cur)';
ber_mlse(cnt,:) = wh2.getStoValue('ber_mlse',v_bias_vals,awg_vpp_cur);
rop_measured(cnt,:) = wh2.getStoValue('rop',v_bias_vals,awg_vpp_cur);
pd_in_measured(cnt,:) = wh2.getStoValue('pd_in',v_bias_vals,awg_vpp_cur);
end
[bestber,bestindex] = min(bers,[],'all');
[awg_pos,v_bias_pos]=ind2sub(size(bers),bestindex);
bestawgvpp=awg_vpp_vals(awg_pos);
bestvbias=v_bias_vals(v_bias_pos);
disp(['Best Vpp: ',num2str(bestvbias),' V; Best Vpp AWG: ',num2str(bestawgvpp),' V' ])
figure(100)
hold on
plot(v_bias_vals,ber_ffe,'DisplayName',['FFE only']);
plot(v_bias_vals,ber_mlse,'DisplayName',['MLSE']);
yline(3.8e-3, 'DisplayName', 'HD-FEC', 'LineStyle', '--', 'HandleVisibility', 'off');
xlabel('V bias');
ylabel('Bit Error Rate (BER)');
title('Bit Error Rate vs. V bias');
set(gca, 'yscale', 'log');
set(gca, 'Box', 'on');
grid on;
grid minor;
legend('Interpreter', 'none');
figure();
sgtitle(['PAM ', num2str(m)])
subplot1 = subplot(1,2,1);
% Compute the logarithm of BER data
% Adding a small epsilon to avoid log(0)
epsilon = 1e-12;
log_bers = log10(bers + epsilon);
% Set limits for z-data scaling in log scale
zmin = log10(1e-4 + epsilon);
zmax = log10(0.5 + epsilon);
% Plot the filled contour plot with log-scaled z-data
contourf_handle = contourf(v_bias_vals, awg_vpp_vals, log_bers, 'Parent', subplot1, "ShowText",true,"LabelFormat", @mylabelfun);
% Set x and y labels with subscripts for clarity
xlabel('V_{bias}');
ylabel('V_{pp} AWG');
title('BER (Mind used Equalizer!)');
% Adjust the grid to display white lines
grid on;
set(subplot1, 'GridColor', [1 1 1]); % Set grid color to white
% Set limits for z-data scaling
clim([zmin zmax]);
% Adjust the colormap
colormap(flipud(cbrewer2('RdBu',64)));
% Add a colorbar and adjust its ticks to represent actual BER values
c = colorbar;
% Set colorbar ticks at log-spaced intervals
tick_values = [1e-4 1e-3 1e-2 1e-1 0.5];
tick_positions = log10(tick_values + epsilon);
set(c, 'Ticks', tick_positions, 'TickLabels', arrayfun(@num2str, tick_values, 'UniformOutput', false));
% Store variables in the figure's application data for use in the data tip function
setappdata(gcf, 'v_bias_vals', v_bias_vals);
setappdata(gcf, 'awg_vpp_vals', awg_vpp_vals);
setappdata(gcf, 'bers', bers);
setappdata(gcf, 'power', rop_measured); % Store the Power data
% Set up the data cursor mode to display custom data tips
dcm_obj = datacursormode(gcf);
set(dcm_obj, 'UpdateFcn', @customDataTip);
hold on
scatter(bestvbias,bestawgvpp,100,"red",'Marker','x','LineWidth',2);
subplot2 = subplot(1,2,2);
% Plot the filled contour plot
contourf_handle = contourf(v_bias_vals, awg_vpp_vals, rop_measured, 'Parent', subplot2,"ShowText",true);
% Set x and y labels
xlabel('V_{bias}');
ylabel('V_{pp} AWG');
title('Power at Rx');
% Adjust the grid to display white lines
grid on;
set(subplot2, 'GridColor', [1 1 1]); % Set grid color to white
% Set limits for z-data scaling
clim([-5 -3]);
% Adjust the colormap
colormap(flipud(cbrewer2('RdBu',64)));
% Add a colorbar
colorbar;
% Store variables in the figure's application data for use in the data tip function
setappdata(gcf, 'v_bias_vals', v_bias_vals);
setappdata(gcf, 'awg_vpp_vals', awg_vpp_vals);
setappdata(gcf, 'bers', bers);
setappdata(gcf, 'power', rop_measured); % Store the Power data
% Set up the data cursor mode to display custom data tips
dcm_obj = datacursormode(gcf);
set(dcm_obj, 'UpdateFcn', @customDataTip);
function labels = mylabelfun(vals)
lab = 10.^vals;
labels = arrayfun(@(x) num2str(x, '%.1e'), lab, 'UniformOutput', false);
end
% Define the custom data tip function
function txt = customDataTip(~, event_obj)
% Retrieve stored variables
v_bias_vals = getappdata(gcf, 'v_bias_vals');
awg_vpp_vals = getappdata(gcf, 'awg_vpp_vals');
bers = getappdata(gcf, 'bers');
power = getappdata(gcf, 'power'); % Retrieve the Power data
% Get the position of the data cursor
pos = event_obj.Position;
xdata = pos(1);
ydata = pos(2);
% Find the nearest indices in the data arrays
[~, xInd] = min(abs(v_bias_vals - xdata));
[~, yInd] = min(abs(awg_vpp_vals - ydata));
% Get the corresponding BER and Power values
berValue = bers(yInd, xInd);
powerValue = power(yInd, xInd); % Get the Power value
% Format the text for the data tip
txt = {['V_{bias} = ', num2str(xdata)], ...
['V_{pp} AWG = ', num2str(ydata)], ...
['BER = ', num2str(berValue, '%.1e')], ...
['Power = ', num2str(powerValue)]};
end