ecoc measurements

This commit is contained in:
Silas Labor Zizou
2025-04-13 16:29:12 +02:00
parent 00f1c557c0
commit 0236103b13
19 changed files with 709 additions and 359 deletions

View File

@@ -703,7 +703,8 @@ classdef Signal
end
if options.debug_plots
figure()
figure(121212);clf
subplot(1,2,1);
findpeaks(abs(co./max(co)),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum,'SortStr','descend')
end
@@ -711,7 +712,7 @@ classdef Signal
shifts = lags(pkpos);
shifts = shifts(shifts>=0);
% shifts = shifts(shifts>=0);
if numel(shifts) > 0
@@ -720,25 +721,21 @@ classdef Signal
isFlipped = 1;
end
for c = shifts(shifts>=0)
for c = shifts
sig = obj.delay(-c,'mode','samples');
sig.signal = sig.signal(1:length(b)).*-isFlipped;
S{end+1,1} = sig;
end
%
%return/keep the sinal with the highest correlation (only within positive shifts)
[~,idx]=max(pks(shifts>=0));
[~,idx]=max(pks);
obj.signal = S{idx}.signal;
%put signal with highest corr. to first index in S array
swap = S{1};
S{1} = S{idx};
S{idx} = swap;
for c = 1:numel(shifts(shifts>0))
for c = 1:numel(shifts)
S{c}.logbook = [];
end
@@ -750,11 +747,14 @@ classdef Signal
%plot all synced signals and the ref signal
if options.debug_plots
figure;hold on;
figure(121212);hold on;
subplot(1,2,2);
for i = 1:size(S,1)
hold on
plot(S{i}.normalize('mode','oneone').signal(1000:1100),'LineWidth',0.1,'Color',[0.2157 0.4941 0.7216]);
plot(b(1000:1100),'LineWidth',1);
end
drawnow;
end
@@ -913,14 +913,12 @@ classdef Signal
elseif mode == 1
% generate eye diagram using histogram
maxA = max(sig(100:end-100));
minA = min(sig(100:end-100));
maxA = max(sig(100:end-100))*2;
minA = min(sig(100:end-100))*2;
% maxA = 0.0015;
% minA = 0;
difference= maxA-minA;
data_ind_y=round((eye_mat-minA)/difference*(histpoints-1)) +1;
@@ -940,11 +938,9 @@ classdef Signal
% beautify
cm=flip(cbrewer2("RdYlBu",4096));
% cm=flip(cbrewer2("RdBu",4096));
cm(1,:) = [1,1,1];
cm(1,:) = [0,0,0];
cm(1,:) = [1,1,1]; % set zeros to white => clean background
colormap(cm);
% colormap('turbo');
ax.Colormap(1,:) = [1,1,1];
% ax.CLim = [0 50];
if isa(obj,'Opticalsignal')
title(['Optical Eye ',options.displayname])

View File

@@ -38,6 +38,9 @@ classdef ChannelFreqResp < handle
Nfft
df
faxis
fileName
path
end
methods (Access=public)
@@ -194,7 +197,9 @@ classdef ChannelFreqResp < handle
obj.H_apply = H_inv;
Target.signal = real((ifft( ( fft(real( Target.signal' )) .* H_inv ) )));
H_inv = reshape(H_inv,size(Target.signal));
Target.signal = real((ifft( ( fft(real( Target.signal )) .* H_inv ) )));
Target.signal = Target.signal';
end
@@ -250,8 +255,18 @@ classdef ChannelFreqResp < handle
% Havg_smooth = smooth(Havg,10);
symaxis = (obj.faxis-(obj.f_ref/2))/1e9;
Havg = fftshift(Havg);
%Havg = smooth(Havg);
plot(symaxis, 20*log10(abs(Havg)),'LineWidth',0.5);
Havg = smooth(Havg);
Havg = Havg./max(Havg);
if ~isempty(obj.fileName)
dpname = obj.fileName;
else
dpname = 'Measured System response';
end
plot(symaxis, 20*log10(abs(Havg)),'LineWidth',0.5,'DisplayName',dpname);
legend('Interpreter','latex')
grid on;
@@ -368,6 +383,8 @@ classdef ChannelFreqResp < handle
end
fprintf('Frequency response information successfully loaded from %s\n', fullFileName);
obj.fileName = options.fileName;
obj.path = options.loadPath;
end
end

View File

@@ -11,6 +11,7 @@ classdef PAMsource
db_precode
db_encode
duobinary_mode
mrds_code
mrds_blocklength
@@ -38,6 +39,7 @@ classdef PAMsource
options.db_precode = 0;
options.db_encode = 0;
options.duobinary_mode = db_mode.no_db;
options.mrds_code = 0;
options.mrds_blocklength = 512;
@@ -102,8 +104,7 @@ classdef PAMsource
para.reset_prms = 0;
para.method = 1;
data_in = [];
global loop;
loop = 0;
@@ -134,43 +135,52 @@ classdef PAMsource
symbols.fs = obj.fsym;
%%%%%% Duobinary %%%%%%%%%%%
if obj.db_precode
symbols = Duobinary().precode(symbols);
switch obj.duobinary_mode
case db_mode.no_db
case db_mode.db_precoded
symbols = Duobinary().precode(symbols);
case db_mode.db_encoded
symbols = Duobinary().precode(symbols);
symbols = Duobinary().encode(symbols);
end
if obj.db_encode
symbols = Duobinary().encode(symbols);
end
% figure(12);hold on;histogram(symbols.signal,'Normalization','probability');
%%%%%% MRDS %%%%%%%%%%%
if obj.mrds_code
symbols = MRDS_coding("blocklength",obj.mrds_blocklength).encode(symbols);
end
%%%%%% SAVE MIN-MAX FOR CLIP %%%%%%%%%%%
if obj.applyclipping
sym_min = min(symbols.signal);
sym_max = max(symbols.signal);
end
%%%%% Pulse-forming %%%%%%
if obj.applypulseform
%%% MY CODE
digi_sig = obj.pulseformer.process(symbols);
if 0
digi_sig = obj.pulseformer.process(symbols);
%%% MOVEIT WRAPPER BETA
% symbols.spectrum("fignum",111,"displayname","1) RAW SIGNAL");
%
% pulsf = Moveit_wrapper('pulsef');
% pulsf.para.alpharacos = obj.pulseformer.alpha;
% pulsf.para.f_sym = obj.fsym;
% pulsf.para.fs = obj.fsym;
% pulsf.para.pulse = 2;
%
% digi_sig = pulsf.process(symbols);
else
%%% MOVEIT WRAPPER BETA
% symbols.spectrum("fignum",111,"displayname","1) RAW SIGNAL");
pulsf = Moveit_wrapper('pulsef');
pulsf.para.alpharacos = obj.pulseformer.alpha;
pulsf.para.f_sym = obj.pulseformer.fsym;
pulsf.para.fs = obj.pulseformer.fdac;
pulsf.para.pulse = 1;
digi_sig = pulsf.process(symbols);
digi_sig.fs = obj.pulseformer.fdac;
end
% Design raised cosine filter with given order in symbols
% digi_sig = symbols;
% sps = 4;

View File

@@ -6,10 +6,8 @@ classdef Pulseformer
end
properties(Access=public)
fs
fdac
fsym
matched_sps
output_sps
pulse
pulselength
alpha
@@ -22,10 +20,8 @@ classdef Pulseformer
% Detailed explanation goes here
arguments
options.fs double
options.fdac double
options.fsym double
options.matched_sps double
options.output_sps double
options.pulse pulseform = pulseform.rc
options.pulselength double {mustBeInteger} = 32
options.alpha double = 0.05
@@ -54,11 +50,7 @@ classdef Pulseformer
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write fs to signal
if obj.matched
signalclass_in.fs = obj.fsym .* obj.output_sps;%.* (obj.fdac./obj.fsym);
else
signalclass_in.fs = obj.fs;%.* (obj.fdac./obj.fsym);
end
signalclass_in.fs = obj.fdac;%.* (obj.fdac./obj.fsym);
% write to output
signalclass_out = signalclass_in;
@@ -85,19 +77,15 @@ classdef Pulseformer
data_out
end
if ~isempty(obj.output_sps)
obj.fsym = obj.fsym.*obj.output_sps;
end
if ~rem(obj.fs,obj.fsym)
if ~rem(obj.fdac,obj.fsym)
%ist ein Vielfaches
sps = obj.fs / obj.fsym;
sps = obj.fdac / obj.fsym;
p = sps;
q = 1;
else
%ist kein Vielfaches
p = obj.fsym / gcd(obj.fs, obj.fsym); %upsampling p->->->
q = obj.fs/ gcd(obj.fs, obj.fsym); %downsampling <-q
p = obj.fsym / gcd(obj.fdac, obj.fsym); %upsampling p->->->
q = obj.fdac/ gcd(obj.fdac, obj.fsym); %downsampling <-q
sps= q; %sps während dem pulse shaping
end
@@ -117,7 +105,6 @@ classdef Pulseformer
end
manual_cyclic_convolution = 0;
upsample_filter = 0;
upfirdn_convolution = 1;
if manual_cyclic_convolution
@@ -135,28 +122,16 @@ classdef Pulseformer
data_out=ifft( fft(symbolov.') .* repmat( H,size(data_in,1),1 ).' ).';
data_out = circshift(data_out,[0 -(obj.pulselength*sps)]);
if rem(obj.fs,obj.fsym)
if rem(obj.fdac,obj.fsym)
data_out = data_out(1:q:end);
end
end
if upsample_filter
data_out_ = upsample(data_in,p);
mfOutput = filter(h, 1, data_out_); % Matched filter output
figure()
hold on
stem(mfOutput(1:1000),'Marker','o','MarkerSize',1,'LineStyle','-','LineWidth',1);
stem(data_out_(1:1000),'Marker','o','MarkerSize',1,'LineStyle','-','LineWidth',1);
end
if upfirdn_convolution
%Apply Filter using Matlab build in fctn.
data_out_ = upfirdn(data_in,h,p,q);
%cut signal, which is longer due to fir filter
@@ -183,7 +158,7 @@ classdef Pulseformer
% scale = max(max([abs(real(data_out)) abs(imag(data_out))])); %find max value from real and imag part
% data_out = data_out./scale;
data_out = data_out';
% data_out = data_out';
%Check output integrity
if abs(round(p/q * length(data_in)) - length(data_out)) > 4

View File

@@ -69,16 +69,16 @@ classdef AwgKeysight
obj.sampleMemorySize = 512000;
case awg_model.M8199A
obj.numChannels = 4;
obj.waveformGranularity = 512;
obj.sampleMemorySize = 1024000; %to check
obj.waveformGranularity = 256;
obj.sampleMemorySize = 512000; %see documentation "strg+f: granularity"
case awg_model.M8199A_ILV
obj.numChannels = 2;
obj.waveformGranularity = 512;
obj.sampleMemorySize = 1024000; %to check
obj.waveformGranularity = 512; %see documentation "strg+f: granularity"
obj.sampleMemorySize = 1024000;
case awg_model.M8199B
obj.numChannels = 2;
obj.waveformGranularity = 512;
obj.sampleMemorySize = 1024000; %to check
obj.waveformGranularity = 512; %see documentation "strg+f: granularity"
obj.sampleMemorySize = 1024000;
end
end
@@ -175,7 +175,10 @@ classdef AwgKeysight
% The waveform granularity is e.g. 128. This means that the waveform length must be a multiple of this granularity. The minimum waveform length is 128 samples.
if rem(length(signal{s}),obj.waveformGranularity) ~= 0
signal{s} = [signal{s} signal{s}(:,1:(obj.waveformGranularity-rem(length(signal{s}),obj.waveformGranularity)))];
fill_length = (obj.waveformGranularity-rem(length(signal{s}),obj.waveformGranularity));
segment__fill_samples = signal{s}(:,1:fill_length);
signal{s} = [signal{s} segment__fill_samples];
debug = 0;
if debug
@@ -196,7 +199,7 @@ classdef AwgKeysight
siglen = min(length(signal{s}),obj.sampleMemorySize);
signal{s} = signal{s}(1:siglen);
if siglen==obj.sampleMemorySize
warning(['Signal ',num2str(s),' was truncated to ',num2str(obj.sampleMemorySize),' to fit into AWG sample memory'])
warning(['Signal ',num2str(s),' too long was truncated to ',num2str(obj.sampleMemorySize),' to fit into AWG sample memory! Reduce Num Symbols or Sampling Rate!'])
end
@@ -362,6 +365,7 @@ classdef AwgKeysight
writeline(visaobj,char(command));
writeline(visaobj,':syst:err?');
err_aw=readline(visaobj);
assert(strfind(err_aw,"No error"),['AWG System Error? after command: ', char(command)])

View File

@@ -53,7 +53,29 @@ classdef OptAtten < handle
try
%connect to device
v = visadev('TCPIP::134.245.243.248::INSTR');
ipAddress = 'TCPIP::134.245.243.248::INSTR';
maxRetries = 5;
pauseTime = 2; % seconds between retries
v = [];
success = false;
for attempt = 1:maxRetries
try
v = visadev(ipAddress);
success = true;
break; % Exit loop if successful
catch ME
fprintf('Connection attempt %d failed: %s\n', attempt, ME.message);
pause(pauseTime);
end
end
if ~success
error(' Could not connect to device after %d attempts.', maxRetries);
end
debug = 0;
if debug
@@ -315,7 +337,8 @@ classdef OptAtten < handle
p3 = obj.power_state(3);
p4 = obj.power_state(4);
if options.silent == 0
delete(v);
if options.silent ~= 0
fprintf("\n CH1: %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n \n",p1, p2, p3, p4);
end
end

View File

@@ -32,14 +32,30 @@ classdef Thor_PDFA < handle
end
end
obj.getStatus();
end
function o = connectSerial(obj)
% Connect to the PDFA
o = serialport(obj.serialport_number, 9600);
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
flush(o);
try
% Connect to the PDFA
o = serialport(obj.serialport_number, 9600);
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
flush(o);
catch ME
disp(['Error connecting to PDFA: ', ME.message]);
% List available serial ports
availablePorts = serialportlist("available");
if isempty(availablePorts)
disp('No available serial ports found.');
else
disp('Available serial ports:');
disp(availablePorts);
end
end
end

View File

@@ -217,12 +217,31 @@ classdef DBHandler < handle
end
% Append the new row to the database table
try
sqlwrite(obj.conn, tableName, newRow);
% disp(['Successfully appended new row to the table ', tableName]);
catch e
error('Failed to append to the table %s: %s', tableName, e.message);
% Parameters for retry logic
maxRetries = 5;
basePause = 0.05; % seconds
attempt = 0;
success = false;
while ~success && attempt <= maxRetries
try
sqlwrite(obj.conn, tableName, newRow);
success = true; % Write successful
catch e
if contains(e.message, 'database is locked') || contains(e.message, 'cannot rollback transaction')
attempt = attempt + 1;
pauseTime = basePause * (1 + rand()); % Add random jitter to reduce collision chance
fprintf('Database locked. Retry %d/%d after %.3f seconds...\n', attempt, maxRetries, pauseTime);
pause(pauseTime);
else
error('Failed to append to the table %s: %s', tableName, e.message);
end
end
end
if ~success
error('Failed to append to table %s after %d retries due to database lock.', tableName, maxRetries);
end
% Retrieve the measurement_id of the newly inserted row for linking other tables
@@ -539,27 +558,38 @@ classdef DBHandler < handle
end
end
% --- Adaptive FROM Clause ---
% Use "Runs" as the main table and add LEFT JOINs for every other table in obj.tables
% (except "sqlite_sequence") that has a run_id field.
mainTable = 'Runs';
fromClause = ['FROM ', mainTable, ' '];
% Prepare join buffers
normalJoins = '';
equalizerJoin = '';
tableNamesAll = fieldnames(obj.tables);
for t = 1:numel(tableNamesAll)
tableName = tableNamesAll{t};
if strcmpi(tableName, mainTable) || strcmpi(tableName, 'sqlite_sequence')
continue;
end
if isfield(obj.tables.(tableName), 'run_id')
% most tables are directly linked to runs table
fromClause = [fromClause, 'LEFT JOIN ', tableName, ' ON ', mainTable, '.run_id = ', tableName, '.run_id '];
% Direct join to Runs
normalJoins = [normalJoins, 'LEFT JOIN ', tableName, ' ON ', mainTable, '.run_id = ', tableName, '.run_id '];
elseif isfield(obj.tables.(tableName), 'eq_id')
% equalizer is only linked to results table
fromClause = [fromClause, 'LEFT JOIN ', tableName, ' ON ', 'Results', '.eqParam_id = ', tableName, '.eq_id '];
% Equalizer depends on Results, collect this join separately
equalizerJoin = ['LEFT JOIN ', tableName, ' ON Results.eqParam_id = ', tableName, '.eq_id '];
end
end
% Combine joins: normal joins first, Equalizer last
fromClause = [fromClause, normalJoins, equalizerJoin];
% --- WHERE Clause Construction ---
baseQuery = [selectClause, ' ', fromClause, 'WHERE '];
filterClauses = [];

View File

@@ -49,29 +49,30 @@ classdef Moveit_wrapper < handle
isSignalClass = 0;
if isa(signal_in,"Signal")
signal_out = signal_in;
signalclass_out = signal_in;
signal_in = signal_in.signal;
isSignalClass = 1;
end
% signal_in = signal_in.';
signal_in = signal_in.';
% INIT MOVEIT
global loop;
loop = 0;
signal_out = obj.moveit_init(signal_in);
signal_init = obj.moveit_init(signal_in);
% RUN MOVEIT
global loop;
loop = 1;
signal_out = obj.moveit_init(signal_out);
signal_out = obj.moveit_simulation_computation(signal_in);
if isSignalClass
% append to logbook
signalclass_out.signal = signal_out;
signal_out=signalclass_out;
lbdesc = ['Logbookentry'];
signal_out = signal_out.logbookentry(lbdesc);
signal_out.signal = signal_out;
end
end