Commit before first big baudrate sweep

This commit is contained in:
Silas Labor Zizou
2024-10-24 19:41:59 +02:00
parent cfd1bdb513
commit bafc7f12b7
11 changed files with 588 additions and 318 deletions

View File

@@ -510,7 +510,7 @@ classdef Signal
end
%%
function [obj,S] = tsynch(obj,options)
function [obj,S,isFlipped] = tsynch(obj,options)
% time sync and cut
arguments
obj Signal
@@ -525,14 +525,16 @@ classdef Signal
q = obj.fs/options.fs_ref;
b = options.reference.resample("fs_in",options.fs_ref,"fs_out",obj.fs).normalize("mode","oneone").signal;
max_occurences = floor(length(a)/length(b));
%estimate delay between signals
[co,lags] = xcorr(a,b);
[~,pos] = max(co);
[~,pos] = max(abs(co));
D = lags(pos);
%estimate start pos of signal
maxpeaknum = floor(length(a)/length(b));
[pks,pkpos] = findpeaks(co./max(co),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum);
[pks,pkpos] = findpeaks(abs(co./max(co)),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum);
shifts = lags(pkpos);
%Cut occurences of ref signal from signal (only positive shifts)
@@ -543,6 +545,12 @@ classdef Signal
S{end+1,1} = sig;
end
%
isFlipped=0;
if all(sign(co(pkpos)))
isFlipped = 1;
end
%return/keep the sinal with the highest correlation (only within positive shifts)
[~,idx]=max(pks(shifts>0));
obj.signal = S{idx}.signal;

View File

@@ -202,19 +202,19 @@ classdef ChannelFreqResp < handle
function plot(obj)
figure(55);
clf;
%clf;
Havg = obj.H;
%1)
subplot(2,1,1);hold all;box on;title('Magnitude Freq. Response');
subplot(2,1,1);hold on;box on;title('Magnitude Freq. Response');
plot(obj.faxis/1e9, 20*log10(abs(obj.H_all)),'linewidth',0.1,'LineStyle','-','Color','#808080') ;
xlim([0.2 .5*max(obj.faxis)*1e-9]);
plot(obj.faxis/1e9, 20*log10(abs(Havg)),'LineWidth',2);
grid on;
%2)
subplot(2,1,2); hold all; box on; title('Phase Freq. Response');
subplot(2,1,2); hold on; box on; title('Phase Freq. Response');
plot(obj.faxis/1e9, angle(obj.H_all),'linewidth',0.1,'LineStyle','-','Color','#808080') ;
plot(obj.faxis/1e9, unwrap(angle(Havg)),'LineWidth',2) ;
xlim([0.2 .5*max(obj.faxis)*1e-9]);
@@ -228,7 +228,7 @@ classdef ChannelFreqResp < handle
Havg = Havg./mean(Havg(2:10));
%3)
subplot(2,1,1); hold all; box on; title('Inverse Magnitude Freq. Response');
subplot(2,1,1); hold on; box on; title('Inverse Magnitude Freq. Response');
plot(obj.faxis/1e9, 20*log10(abs(1./Havg)),"LineWidth",2,"Color",[0.3467 0.5360 0.6907]) ;
xlim([0.2 .5*max(obj.faxis)*1e-9]); grid on;
ylim([-1 15]);
@@ -236,12 +236,12 @@ classdef ChannelFreqResp < handle
yline(3,'LineWidth',2,'LineStyle','--');
%4)
subplot(2,1,2); hold all; box on; title('Inverse Phase Freq. Response');
subplot(2,1,2); hold on; box on; title('Inverse Phase Freq. Response');
plot(obj.faxis/1e9, unwrap(angle(1./Havg)),"LineWidth",2,"Color",[0.3467 0.5360 0.6907]) ;
xlim([0.2 .5*max(obj.faxis)*1e-9]); grid on;
%%% plot for publication
figure(98989);hold all;box on;title('Magnitude Freq. Response');
figure(98989);hold on;box on;title('Magnitude Freq. Response');
xlim([0.2 .5*max(obj.faxis)*1e-9]);
ylim([-20, 2]);
plot(obj.faxis/1e9, 20*log10(abs(Havg)),'LineWidth',2);

View File

@@ -77,9 +77,42 @@ classdef PAMsource
bitpattern=[];
if obj.useprbs
for i = 1:log2(obj.M)
[bitpattern(:,i),seed] = prbs(O,N,seed);
% for i = 1:log2(obj.M)
% [bitpattern(:,i),seed] = prbs(O,N,seed);
% end
%%%%% MOVE-IT PRMS %%%%
state = struct();
para = struct();
if obj.M == 6
para.bl = 2^(obj.order-2);
para.dimension = 5;
else
para.bl = 2^(obj.order-1);
para.dimension = log2(obj.M); %2.5bits/sym -> 2 bit/sym
end
para.rand = 0;
para.order = floor(obj.order / log2(obj.M));
para.skip =0;
para.bruijn = 0;
para.reset_prms = 0;
para.method = 1;
data_in = [];
global loop;
loop = 0;
[data_out,state_] = prms(data_in, state, para);
loop = 1;
[data_out,state_out] = prms(data_in, state_, para);
bitpattern = data_out';
%%%%% END MOVE-IT %%%%%%%
else
s = RandStream('twister','Seed',obj.randkey);
for i = 1:log2(obj.M)
@@ -88,7 +121,7 @@ classdef PAMsource
end
if obj.M == 6
bitpattern = reshape(bitpattern,[],1);
bitpattern = reshape(bitpattern',[],1);
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
end
@@ -108,7 +141,7 @@ classdef PAMsource
end
% figure(12);hold on;histogram(symbols.signal,'Normalization','probability');
if obj.mrds_code
symbols = MRDS_coding("blocklength",obj.mrds_blocklength).encode(symbols);
end
@@ -128,7 +161,7 @@ classdef PAMsource
%%%%% Re-sample to f DAC %%%%%%
digi_sig = digi_sig.resample("fs_in",digi_sig.fs,"fs_out",obj.fs_out,"n",10,"beta",5);
% digi_sig.spectrum("fignum",111,"displayname","after pulseforming");
% digi_sig.spectrum("fignum",111,"displayname","after pulseforming");
%%%%% Hard clip digital signal to PAM range before DAC %%%%%%
if obj.applyclipping

View File

@@ -7,11 +7,12 @@ classdef Awg2Scope
Scope
mapping;
waitUntilClick
end
methods (Access=public)
function obj = Awg2Scope(Awg,Scope,mapping)
function obj = Awg2Scope(Awg,Scope,mapping,options)
%Simple class to call the Awg and Scope and map the signals
%accordingly in the correct formats with correct l
% ogbook
@@ -21,16 +22,19 @@ classdef Awg2Scope
Awg
Scope
mapping
options.waitUntilClick = 0;
end
obj.Awg = Awg;
obj.Scope = Scope;
obj.mapping = mapping; % AWG CH [1,2,3,4] -> Scope CH [0,0,0,1]
obj.waitUntilClick = options.waitUntilClick;
end
function [S1,S2,S3,S4] = process(obj,channels)
function [S1,S2,S3,S4] = process(obj,channels, options)
arguments
obj
@@ -41,15 +45,33 @@ classdef Awg2Scope
channels.signal4 Informationsignal = Informationsignal([])
% add new optional arguments here
options.waitUntilClick = obj.waitUntilClick;
end
%%% UPLOAD TO AWG %%%
[S1,S2,S3,S4]=obj.Awg.upload("signal1",channels.signal1,...
"signal2",channels.signal2,...
"signal3",channels.signal3,...
"signal4",channels.signal4...
);
%%% UPLOAD TO AWG %%%
scpe_sig_cell = obj.Scope.read();
%%% READ FROM SCOPE %%%
scpe_sig_cell = obj.Scope.read("waitUntilClick",options.waitUntilClick);
%%% READ FROM SCOPE %%%
% Map Scope measurement to output signal
% mapping index is the AWG chanel and mapping number is the

View File

@@ -51,90 +51,90 @@ classdef DC_supply < handle
success = [0,0];
try
% %connect to device
% if exist('v','var')
% %v = visadev("GPIB1::19::INSTR");
% v = obj.connectDevice();
% else
%
% end
% %connect to device
% if exist('v','var')
% %v = visadev("GPIB1::19::INSTR");
% v = obj.connectDevice();
% else
%
% end
v = visadev("GPIB1::19::INSTR");
v = visadev("GPIB1::19::INSTR");
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
end
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
end
cmd = 'INST:SEL?';
cmd = 'INST:SEL?';
writeline(v, cmd);
prev_selected_channel = readline(v);
for ch = 1:2
% choose channel
cmd = ['INST:SEL OUT',num2str(ch)];
writeline(v, cmd);
prev_selected_channel = readline(v);
for ch = 1:2
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
% choose channel
cmd = ['INST:SEL OUT',num2str(ch)];
writeline(v, cmd);
% desired voltage (round to two digits after comma)
des_volt = round(options.voltage(ch),2);
cnt = 0;
while abs(act_volt-des_volt) > 0
selected_channel = ['OUT',num2str(ch)];
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
% desired voltage (round to two digits after comma)
des_volt = round(options.voltage(ch),2);
% difference
diff_volt = act_volt-des_volt;
cnt = 0;
while abs(act_volt-des_volt) > 0
selected_channel = ['OUT',num2str(ch)];
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(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)];
writeline(v, cmd);
cnt = cnt+1;
if mod(cnt,100) == 0
wait(1);
end
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
% set new voltage
increment_voltage = -0.01* sign(diff_volt) ;
cmd = ['VOLT ',num2str(act_volt+increment_voltage)];
writeline(v, cmd);
cnt = cnt+1;
if mod(cnt,100) == 0
pause(1);
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);
else
success(ch) = 1;
end
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
end
% choose channel
cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))];
writeline(v, cmd);
% 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);
else
success(ch) = 1;
end
%disconnect
delete(v);
catch
end
% choose channel
cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))];
writeline(v, cmd);
%disconnect
delete(v);
end
function [voltage,current] = readVals(obj)

View File

@@ -193,8 +193,9 @@ classdef OptAtten < handle
differ = abs(state.outputpower(i)-options.value(i));
%create msgbox when necessary
if differ >= 2
hMsgBox = msgbox(['Output Power at attenuator slot ' num2str(2) ' differs by 2dB or more!']);
uiwait(hMsgBox);
warning(['Output Power at attenuator slot ' num2str(2) ' differs by ', num2str(differ), 'or more!'])
% hMsgBox = msgbox(['Output Power at attenuator slot ' num2str(2) ' differs by 2dB or more!']);
% uiwait(hMsgBox);
end
end
end

View File

@@ -12,6 +12,8 @@ classdef ScopeKeysight
interpolate
recordLen
IPaddress
waitUntilClick
end
methods (Access=public)
@@ -30,6 +32,7 @@ classdef ScopeKeysight
options.interpolate logical = 0;
options.recordLen double = 1000000;
options.IPaddress
options.waitUntilClick = 0;
end
%
@@ -55,6 +58,7 @@ classdef ScopeKeysight
arguments
obj
options.channel logical = obj.channel
options.waitUntilClick = obj.waitUntilClick;
end
%%%%%%%%%%%%%%%%%%%%%%%%
@@ -119,14 +123,43 @@ classdef ScopeKeysight
obj.writeNcheck(v,sprintf(':CHANnel%u:DISPlay ON',n));% display captured data trace
end
set(v,'Timeout',150);
if obj.autoScale
obj.writeNcheck(v,':AUTOscale');
for n = 1:4
range = str2double(obj.writeReceiveCheck(v,sprintf(':CHANnel%u:RANGe?',n)));
obj.writeNcheck(v,sprintf(':CHANnel%u:RANGe %.3f',n,range/1.2));
%use this to finetune autoscaling - VERY helpful
% higher value leads to higher scaling
fintunefactor = 1.4; % within [1,...,2]
obj.writeNcheck(v,sprintf(':CHANnel%u:RANGe %.3f',n,range/fintunefactor));
end
else
obj.writeNcheck(v,':SINGLE');
%obj.writeNcheck(v,':SINGLE');
end
% After Autoscale, let the user adjust the scope scaling...
% "options.waitUntilClick" was a shit name but now this is it :-)
if options.waitUntilClick
% Create a dialog box with the desired text
d = dialog('Name', 'Scale Scope then press continue', 'Position', [300, 300, 300, 180]);
% Add a text label with the instruction
uicontrol('Parent', d, ...
'Style', 'text', ...
'Position', [20, 100, 260, 40], ...
'String', 'Please adjust scope scaling now, then press continue', ...
'HorizontalAlignment', 'center');
% Add a button to close the dialog and resume execution
uicontrol('Parent', d, ...
'Style', 'pushbutton', ...
'Position', [100, 40, 100, 40], ...
'String', 'Continue', ...
'Callback', 'uiresume(gcbf); delete(gcbf)');
% Pause execution until the dialog box is closed
uiwait(d);
end
if obj.extRef