WIP büro
This commit is contained in:
195
Classes/01_transmit/AWG.m
Normal file
195
Classes/01_transmit/AWG.m
Normal file
@@ -0,0 +1,195 @@
|
||||
classdef AWG
|
||||
%AWG Summary of this class goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
properties(Access=public)
|
||||
|
||||
preset
|
||||
kover %oversampling factor e.g. 16
|
||||
repetitions %repeat the signal to generate a longer sequence?
|
||||
fdac %needed
|
||||
normalize %want to normalize at first? either 0 or 1
|
||||
bit_resolution %bit res. of quantizer (e.g. 5 bit)
|
||||
dac_min
|
||||
dac_max
|
||||
|
||||
skew_active = 0;
|
||||
awg_skew ; %skew vector for each output channel
|
||||
|
||||
lpf_active = 0;
|
||||
lpf_type ;
|
||||
f_cutoff ;
|
||||
|
||||
signal_length;
|
||||
H_lpf;
|
||||
|
||||
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
function obj = AWG(options)
|
||||
%AWG Construct an instance of this class
|
||||
% Detailed explanation goes here
|
||||
|
||||
arguments
|
||||
options.preset = [] ;
|
||||
options.kover = 16;
|
||||
options.repetitions = 1;
|
||||
options.normalize = 1;
|
||||
options.fdac = 92e9;
|
||||
options.bit_resolution = 5.5
|
||||
options.dac_min = -0.5;
|
||||
options.dac_max = 0.5;
|
||||
options.skew_active = 0;
|
||||
options.awg_skew = 0;
|
||||
options.lpf_active = 0;
|
||||
options.lpf_type = 0;
|
||||
options.f_cutoff = 32e9;
|
||||
end
|
||||
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
if options.preset == "M8196A"
|
||||
% M8196A (92GBd) https://www.keysight.com/us/en/product/M8196A/92-gsa-s-arbitrary-waveform-generators.html
|
||||
obj.dac_max = 0.5;
|
||||
obj.dac_min = -.5;
|
||||
obj.f_cutoff = 50e9;
|
||||
elseif options.preset == "M8199B"
|
||||
%https://www.keysight.com/us/en/assets/3120-1465/data-sheets/M8199A-128-256-GSa-s-Arbitrary-Waveform-Generator.pdf
|
||||
% obj.fdac = 256e9;
|
||||
obj.dac_max = 0.5;
|
||||
obj.dac_min = -.5;
|
||||
obj.f_cutoff = 80e9;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = process(obj,signalclass_in)
|
||||
|
||||
|
||||
len_in = length(signalclass_in.signal);
|
||||
|
||||
% actual processing of the signal (steps 1. - 3.)
|
||||
signalclass_in.signal = obj.process_(signalclass_in.signal);
|
||||
|
||||
% 4. Apply LPF on the signal
|
||||
if obj.lpf_active
|
||||
lpf = Filter('filtdegree',5,"f_cutoff",obj.f_cutoff,"fsamp",obj.kover*obj.fdac,"filterType",obj.lpf_type);
|
||||
signalclass_in = lpf.process(signalclass_in);
|
||||
end
|
||||
|
||||
% cast the inform. signal to electrical signal
|
||||
signalclass_in = Electricalsignal(signalclass_in,"fs",obj.fdac*obj.kover,"logbook",signalclass_in.logbook);
|
||||
|
||||
% append to logbook
|
||||
lbdesc = ['AWG preset ', obj.preset, 'k_over:',num2str(obj.kover),'. f_dac:',num2str(obj.fdac*1e-9),'GHz. Resolution:',num2str(obj.bit_resolution),' bits.'];
|
||||
signalclass_in = signalclass_in.logbookentry(lbdesc);
|
||||
|
||||
% write to output
|
||||
signalclass_out = signalclass_in;
|
||||
|
||||
len_out = length(signalclass_out.signal);
|
||||
|
||||
if len_out ~= len_in * obj.kover
|
||||
warning("AWG: Output length maybe not correct.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function elec_out = process_(obj,data_in)
|
||||
%METHOD1 Summary of this method goes here
|
||||
% Detailed explanation goes here
|
||||
arguments(Input)
|
||||
obj
|
||||
data_in
|
||||
end
|
||||
|
||||
arguments(Output)
|
||||
elec_out
|
||||
end
|
||||
|
||||
obj.signal_length = length(data_in);
|
||||
|
||||
if obj.normalize
|
||||
% 0a Normalize the signal to 1 Vpp and set the amplitude of the signal
|
||||
data_in = data_in/(max(data_in)-min(data_in));
|
||||
else
|
||||
% 0b Cut the Signal at -1 and 1 and scale to amplitude
|
||||
data_in(data_in > 1) = 1;
|
||||
data_in(data_in < -1) = -1;
|
||||
end
|
||||
|
||||
% 1. Quantize the signal
|
||||
if obj.bit_resolution>0
|
||||
elec_out = obj.quantization(data_in) ;
|
||||
else
|
||||
elec_out = data_in;
|
||||
end
|
||||
|
||||
% 2. Sample and hold + repeat (data_out: 1xsignal length)
|
||||
elec_out = repmat(elec_out,obj.repetitions,obj.kover);
|
||||
elec_out = reshape(elec_out',[],1);
|
||||
|
||||
% 3. Add skew (not working so far)
|
||||
if obj.skew_active
|
||||
elec_out = obj.skew(elec_out);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
methods (Access=private)
|
||||
|
||||
function quant_out = quantization(obj,x_in)
|
||||
|
||||
steps = round(2^obj.bit_resolution) + rem(round(2^obj.bit_resolution),2) ;
|
||||
|
||||
if isreal(x_in)
|
||||
% shift signal and clip to quantizer intervall
|
||||
x_in = min(max(x_in-obj.dac_min,0),obj.dac_max-obj.dac_min);
|
||||
|
||||
% quantize signal
|
||||
x_in = round((steps-1)/(obj.dac_max-obj.dac_min)*x_in);
|
||||
|
||||
% scale and shift back
|
||||
quant_out = x_in*(obj.dac_max-obj.dac_min)/(steps-1) +obj.dac_min;
|
||||
|
||||
else
|
||||
|
||||
% shift signal and clip to quantizer intervall
|
||||
x_in = min(max(real(x_in)-obj.dac_min,0),obj.dac_max-obj.dac_min) + ...
|
||||
1i*min(max(imag(x_in)-obj.dac_min,0),obj.dac_max-obj.dac_min);
|
||||
|
||||
% quantize signal and shift back signal
|
||||
x_in = round((steps-1)/(obj.max-obj.dac_min)*x_in);
|
||||
|
||||
% scale and shift back
|
||||
quant_out = x_in*(obj.dac_max-obj.dac_min)/(steps-1) +(1+1i)*obj.dac_min;
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function skew_out = skew(obj,x_in)
|
||||
|
||||
% Exact delay calculation
|
||||
|
||||
% Calculate transfer function
|
||||
fsimu = obj.kover*obj.fdac;
|
||||
faxis = linspace(fsimu/2, fsimu/2, length(x_in)+1);
|
||||
faxis = fftshift(faxis(1:end-1));
|
||||
|
||||
skew_out = ifft(fft(x_in) .* exp(-1i*2*pi*obj.awg_skew*faxis)' );
|
||||
|
||||
skew_out = real(skew_out) ; % get rid of negligible imaginary part
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
183
Classes/01_transmit/PAMmapper.m
Normal file
183
Classes/01_transmit/PAMmapper.m
Normal file
@@ -0,0 +1,183 @@
|
||||
classdef PAMmapper
|
||||
%PAMMAPPER Summary of this class goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
properties
|
||||
M
|
||||
unipolar
|
||||
thresholds
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = PAMmapper(M, unipolar)
|
||||
%PAMMAPPER Construct an instance of this class
|
||||
% Detailed explanation goes here
|
||||
obj.M = M;
|
||||
obj.unipolar = unipolar;
|
||||
|
||||
obj.thresholds = obj.get_demodulation_thresholds();
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = map(obj,signalclass_in)
|
||||
signalclass_in.signal = obj.map_(signalclass_in.signal);
|
||||
signalclass_in = signalclass_in.logbookentry();
|
||||
signalclass_out = signalclass_in;
|
||||
end
|
||||
|
||||
function signalclass_out = demap(obj,signalclass_in)
|
||||
signalclass_in.signal = obj.demap_(signalclass_in.signal);
|
||||
signalclass_in = signalclass_in.logbookentry();
|
||||
signalclass_out = signalclass_in;
|
||||
end
|
||||
|
||||
function pam_sig = map_(obj,bitpattern)
|
||||
|
||||
switch log2(obj.M)
|
||||
case 1
|
||||
% 2-ASK: BPSK / OOK
|
||||
pam_sig=bitpattern(:,1);
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-1;
|
||||
end
|
||||
|
||||
case 2
|
||||
% 4-ASK:
|
||||
pam_sig=2*bitpattern(:,1)+(bitpattern(:,1)==bitpattern(:,2));
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-3;
|
||||
end
|
||||
|
||||
|
||||
case 3
|
||||
% 8-ASK:
|
||||
x1 = bitpattern(:,1);
|
||||
x2 = (bitpattern(:,1)==bitpattern(:,3));
|
||||
x3 = x2~=bitpattern(:,2);
|
||||
|
||||
pam_sig = 4*x1 + 2*x2 + x3;
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-7;
|
||||
end
|
||||
|
||||
|
||||
case 4
|
||||
% 16-ASK:
|
||||
x1 = bitpattern(:,1);
|
||||
x2 = (bitpattern(:,1)==bitpattern(:,4));
|
||||
x3 = x2~=bitpattern(:,3);
|
||||
x4 = x3~=bitpattern(:,2);
|
||||
|
||||
pam_sig = 8*x1 + 4*x2 + 2*x3 + x4;
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-15;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function thres = get_demodulation_thresholds(obj)
|
||||
%simply get the obj.thresholdseshold values for PAM
|
||||
|
||||
%28.03.2023 - Silas Oett. - Extracted from digi_demod.m
|
||||
%
|
||||
|
||||
obj.thresholds = 0;
|
||||
|
||||
switch log2(obj.M)
|
||||
|
||||
case 1
|
||||
% 2-ASK
|
||||
|
||||
if obj.unipolar
|
||||
thres=0.5;
|
||||
else %bi polar
|
||||
thres=0;
|
||||
end
|
||||
|
||||
case 2
|
||||
% 4-ASK
|
||||
if obj.unipolar==0
|
||||
thres=[-2,0,2];
|
||||
elseif obj.unipolar==1
|
||||
thres=[0.5,1.5,2.5];
|
||||
end
|
||||
|
||||
|
||||
case 3
|
||||
% 8-ASK
|
||||
if obj.unipolar==0
|
||||
thres=-6:2:6;
|
||||
elseif obj.unipolar==1
|
||||
thres=0.5:6.5;
|
||||
end
|
||||
|
||||
case 4
|
||||
% 16-ASK
|
||||
if obj.unipolar==0 && scale_mode==1
|
||||
thres=-14:2:14;
|
||||
elseif obj.unipolar==1 && scale_mode==1
|
||||
thres=0.5:14.5;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function [data_out] = demap_(obj,data_in)
|
||||
|
||||
data_in= data_in';
|
||||
% create output
|
||||
if ~isempty(obj.thresholds)
|
||||
a = squeeze(repmat(real(data_in),[1 1 length(obj.thresholds)])); %Eingangssignal in 3 spalten
|
||||
b = squeeze(repmat(reshape(obj.thresholds(:).',[1 1 length(obj.thresholds)]),[1 length(data_in) 1])); %Threshold in 3 Spalten
|
||||
comp_real = a > b; %check for each symbol/ sampling if it exeeds the obj.thresholdseshold 1, 2 or 3
|
||||
|
||||
comp_real=repmat(real(data_in),[1 1 length(obj.thresholds)]) > repmat(reshape(obj.thresholds(:).',[1 1 length(obj.thresholds)]),[1 length(data_in) 1]);
|
||||
|
||||
else
|
||||
comp_real=[];
|
||||
end
|
||||
|
||||
s1=size(comp_real,1);
|
||||
s2=size(comp_real,2);
|
||||
|
||||
|
||||
switch log2(obj.M)
|
||||
|
||||
case 1
|
||||
% 2-ASK
|
||||
|
||||
data_out=comp_real(:,:,1);
|
||||
|
||||
case 2
|
||||
% 4-ASK
|
||||
|
||||
data_out=[comp_real(:,:,2); ones(s1,s2)-comp_real(:,:,1)+comp_real(:,:,3)];
|
||||
|
||||
|
||||
case 3
|
||||
% 8-ASK
|
||||
data_out=[comp_real(:,:,4);
|
||||
comp_real(:,:,1)-comp_real(:,:,3)+comp_real(:,:,5)-comp_real(:,:,7);
|
||||
1-comp_real(:,:,2)+comp_real(:,:,6)];
|
||||
|
||||
case 4
|
||||
% 16-ASK
|
||||
data_out=[comp_real(:,:,8);
|
||||
comp_real(:,:,1)-comp_real(:,:,3)+comp_real(:,:,5)-comp_real(:,:,7)+comp_real(:,:,9)-comp_real(:,:,11)+comp_real(:,:,13)-comp_real(:,:,15);
|
||||
comp_real(:,:,2)-comp_real(:,:,6)+comp_real(:,:,10)-comp_real(:,:,14);
|
||||
1-comp_real(:,:,4)+comp_real(:,:,12)];
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
110
Classes/01_transmit/Pulseformer.m
Normal file
110
Classes/01_transmit/Pulseformer.m
Normal file
@@ -0,0 +1,110 @@
|
||||
classdef Pulseformer
|
||||
%Pulseformer Summary of this class goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
properties(Access=public)
|
||||
fdac
|
||||
fsym
|
||||
pulseform
|
||||
pulselength
|
||||
rrcalpha
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
function obj = Pulseformer(options)
|
||||
%NAME Construct an instance of this class
|
||||
% Detailed explanation goes here
|
||||
|
||||
arguments
|
||||
options.fdac double
|
||||
options.fsym double
|
||||
options.pulseform pulseform = pulseform.rrc
|
||||
options.pulselength double {mustBeInteger} = 32
|
||||
options.rrcalpha double = 0.05
|
||||
end
|
||||
|
||||
%
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
% do more stuff
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = process(obj,signalclass_in)
|
||||
|
||||
% actual processing of the signal (steps 1. - 3.)
|
||||
signalclass_in.signal = obj.process_(signalclass_in.signal);
|
||||
|
||||
% append to logbook
|
||||
lbdesc = ['Applied Pulseshaping'];
|
||||
signalclass_in = signalclass_in.logbookentry(lbdesc);
|
||||
|
||||
% write to output
|
||||
signalclass_out = signalclass_in;
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
methods (Access=private)
|
||||
% Cant be seen from outside! So put all your functions here that can/
|
||||
% shall not be called from outside
|
||||
|
||||
function data_out = process_(obj,data_in)
|
||||
%METHOD1 Summary of this method goes here
|
||||
% Detailed explanation goes here
|
||||
arguments(Input)
|
||||
obj
|
||||
data_in double
|
||||
end
|
||||
|
||||
arguments(Output)
|
||||
data_out double
|
||||
end
|
||||
|
||||
if ~rem(obj.fdac,obj.fsym)
|
||||
%ist ein Vielfaches
|
||||
sps = obj.fdac / obj.fsym;
|
||||
up = sps;
|
||||
dn = 1;
|
||||
else
|
||||
%ist kein Vielfaches
|
||||
up = obj.fdac / gcd(obj.fdac, obj.fsym);
|
||||
dn = obj.fsym / gcd(obj.fdac, obj.fsym);
|
||||
sps= up;
|
||||
end
|
||||
|
||||
if obj.pulseform == pulseform.rrc
|
||||
%Bau das Filter (hier rrc)
|
||||
racos_len = obj.pulselength ;
|
||||
alpha = obj.rrcalpha;
|
||||
h = rcosdesign(alpha,racos_len,sps);
|
||||
end
|
||||
|
||||
%Apply Filter using Matlab build in fctn.
|
||||
data_out = upfirdn(data_in,h,up,dn);
|
||||
|
||||
%cut signal, which is longer due to fir filter
|
||||
st = round(up/dn*racos_len/2); %we need to cut y_out
|
||||
en = round(st + (length(data_in)*up/dn) -1);
|
||||
|
||||
data_out = data_out(st:en);
|
||||
|
||||
%Check output integrity
|
||||
if round(up/dn * length(data_in)) ~= length(data_out)
|
||||
warning('Check signal length after pulse shaping');
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user