From 9571f73b24ffb8baa63b8977c69cd12eb5e77d0e Mon Sep 17 00:00:00 2001 From: "Silas [Labor]" Date: Tue, 24 Sep 2024 11:30:25 +0200 Subject: [PATCH] Minor Changes and Lab Preps --- Classes/05_Lab/DC_supply.m | 124 ++++++++++++++++++++++ Tests/05_Lab/DC_Supply_test.m | 16 +++ Tests/generateTests.m | 3 +- projects/Lab_analysis/eq_lab.m | 59 ++++++++++ projects/standard_system/imdd_minimal_2.m | 4 +- 5 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 Classes/05_Lab/DC_supply.m create mode 100644 Tests/05_Lab/DC_Supply_test.m create mode 100644 projects/Lab_analysis/eq_lab.m diff --git a/Classes/05_Lab/DC_supply.m b/Classes/05_Lab/DC_supply.m new file mode 100644 index 0000000..4cb1377 --- /dev/null +++ b/Classes/05_Lab/DC_supply.m @@ -0,0 +1,124 @@ +classdef DC_supply + % Simple control of DC supply via fixed GBIB address. + % Agilent E3646A + + properties(Access=public) + active + voltage + end + + methods (Access=public) + + function obj = DC_supply(options) + + + arguments + options.active bool = true + options.voltage double = [0,0]; + end + + % + fn = fieldnames(options); + for n = 1:numel(fn) + try + obj.(fn{n}) = options.(fn{n}); + end + end + + assert(size(obj.voltage,1)==1,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]'); + assert(size(obj.voltage,2)==2,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]'); + + end + + function success = set(obj) + + success = false; + + try + %connect to device + v = visadev("GPIB0::19::INSTR"); + % fopen(v); + + writeline(v, '*IDN?;'); + disp(['DC Source: ' readline(v)]); + + cmd = 'INST:SEL?'; + fprintf(v, cmd); + selected_channel = fscanf(v); + + for ch = 1:2 + + % choose channel + cmd = ['INST:SEL OUT',num2str(ch)]; + fprintf(v, cmd); + + % get current voltage level + cmd = ['VOLT?']; + fprintf(v, cmd); + act_volt = str2num(fscanf(v)); + + % desired voltage (round to two digits after comma) + des_volt = round(obj.voltage(ch),2); + + cnt = 0; + while abs(act_volt-des_volt) > 0 + + selected_channel = ['OUT',num2str(ch)]; + + % get current voltage level + cmd = ['VOLT?']; + fprintf(v, cmd); + act_volt = str2num(fscanf(v)); + + % difference + diff_volt = act_volt-des_volt; + + % set new voltage + increment_voltage = -0.01* sign(diff_volt) ; + cmd = ['VOLT ',num2str(act_volt+increment_voltage)]; + fprintf(v, cmd); + + cnt = cnt+1; + if mod(cnt,100) == 0 + wait(1); + end + + % get current voltage level + cmd = ['VOLT?']; + fprintf(v, cmd); + act_volt = str2num(fscanf(v)); + + end + + % check if voltage is set + if act_volt ~= des_volt + hMsgBox = msgbox('An error occurred in dc supply module. Check if voltage is set correctly.'); + uiwait(hMsgBox); + end + + end + + % choose channel + cmd = ['INST:SEL ',selected_channel]; + fprintf(v, cmd); + + %disconnect + fclose(v); + delete(v); + + catch + + + end + + + end + + end + + methods (Access=private) + + + + end +end diff --git a/Tests/05_Lab/DC_Supply_test.m b/Tests/05_Lab/DC_Supply_test.m new file mode 100644 index 0000000..b4855e7 --- /dev/null +++ b/Tests/05_Lab/DC_Supply_test.m @@ -0,0 +1,16 @@ +classdef DC_Supply_test < matlab.unittest.TestCase + % Test class for DC_Supply + + methods (Test) + function testExample(testCase) + % Example test case for DC_Supply + % Add your test code here + + dc_supply = DC_supply("voltage",[0,9],"active",1); + + dc_supply.set(); + + testCase.verifyTrue(true); + end + end +end diff --git a/Tests/generateTests.m b/Tests/generateTests.m index 998f0a3..f31fa47 100644 --- a/Tests/generateTests.m +++ b/Tests/generateTests.m @@ -1,10 +1,11 @@ function generateTests() if ismac - cd('/Users/silasoettinghaus/Documents/MATLAB/imdd_simulation'); + cd('/Users/silasoettinghaus/Documents/MATLAB/imdd_simulation'); else end + % Define the root folders for classes and tests classesFolder = 'Classes'; % Folder containing the class files testsFolder = 'Tests'; % Folder where test files should be created diff --git a/projects/Lab_analysis/eq_lab.m b/projects/Lab_analysis/eq_lab.m new file mode 100644 index 0000000..5e912f4 --- /dev/null +++ b/projects/Lab_analysis/eq_lab.m @@ -0,0 +1,59 @@ + +%% Parameter to simulate and save +params = struct; + +params.M = [4]; +params.datarate = [300]; +params.rop = [0]; + +precomp_mode = 2; %0=do nothing ; 1= measure; 2=precomp active + +if ismac + precomp_path = "/Users/silasoettinghaus/Documents/MATLAB/imdd_simulation/projects/standard_system"; +else + precomp_path = "C:\Users\Silas\Documents\MATLAB\imdd_simulation\projects\standard_system\"; +end + +precomp_fn = "400G_simulative_setup"; +usemrds = 0; + +name = ['wh_',strrep(num2str(now),'.','')]; + +wh = DataStorage(params); + +wh.addStorage("ber_ffe"); + +%% Init Params +link_length = 0; %meter +pn_key = 2; +laser_linewidth = 0; + +endcnt = prod(wh.dim); +cnt=0; + +disp(['Start Simulation of ',num2str(endcnt),' loops...']) +tic + + +% SETUP HERE: %% +fsym = 92e9; + +Symbols = Informationsignal(digi_mod_out',"fs",92e9); + +Scpe_sig = Electricalsignal(awg2scope_keysight_out.no1',"fs",160e9); +Scpe_sig = Scpe_sig.resample("fs_in",160e9,"fs_out",2*92e9); + +Bits = Informationsignal(prms_out',"fs",92e9); + +%%%%%% Sync Rx signal with reference %%%%%% +[Scpe_sig,S] = Scpe_sig.tsynch("reference",Symbols,"fs_ref",fsym); + +%%%%% EQUALIZE %%%%%% +% Eq = FFE("epochs_tr",5,"epochs_dd",5,"len_tr",4096*2,"mu_dd",1e-4,"mu_tr",0,"order",25,"sps",2,"decide",1); +Eq = VNLE("epochs_tr",5,"epochs_dd",5,"len_tr",4096*2,"mu_dd",[0.0004 0.0005 0.0006],"mu_tr",0,"order",[50,7,7],"sps",2,"decide",1); +[EQ_sig] = Eq.process(Scpe_sig,Symbols); +Rx_bits = PAMmapper(M,0).demap(EQ_sig); +[~,errors_bm,ber_ffe,errors] = calc_ber(Rx_bits.signal,Bits.signal,"skip_front",100,"skip_end",150,"returnErrorLocation",1); +disp(['BER: ',sprintf('%.1E',ber_ffe),' - - - ',num2str(fsym*1e-9),' GBd']); + + diff --git a/projects/standard_system/imdd_minimal_2.m b/projects/standard_system/imdd_minimal_2.m index 1a5bf4d..50dc18b 100644 --- a/projects/standard_system/imdd_minimal_2.m +++ b/projects/standard_system/imdd_minimal_2.m @@ -6,7 +6,7 @@ params.M = [4]; params.datarate = [300]; params.rop = [0]; -precomp_mode = 2; %0=do nothing ; 1= measure; 2=precomp active +precomp_mode = 0; %0=do nothing ; 1= measure; 2=precomp active if ismac precomp_path = "/Users/silasoettinghaus/Documents/MATLAB/imdd_simulation/projects/standard_system"; @@ -148,7 +148,7 @@ for M = wh.parameter.M.values %%%%%% Sync Rx signal with reference %%%%%% - [Scpe_sig,D,cuts] = Scpe_sig.tsynch("reference",Symbols,"fs_ref",fsym); + [Scpe_sig,S] = Scpe_sig.tsynch("reference",Symbols,"fs_ref",fsym); %%%%% EQUALIZE %%%%%%