changes from zurich; my mac
This commit is contained in:
@@ -8,13 +8,21 @@ classdef PAMmapper
|
||||
thresholds
|
||||
levels
|
||||
scaling
|
||||
eth_style
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = PAMmapper(M, unipolar)
|
||||
function obj = PAMmapper(M, unipolar, options)
|
||||
%PAMMAPPER Construct an instance of this class
|
||||
% Detailed explanation goes here
|
||||
arguments
|
||||
M
|
||||
unipolar
|
||||
options.eth_style = 0;
|
||||
end
|
||||
|
||||
obj.M = M;
|
||||
|
||||
obj.unipolar = unipolar;
|
||||
|
||||
obj.thresholds = obj.get_demodulation_thresholds();
|
||||
@@ -23,6 +31,8 @@ classdef PAMmapper
|
||||
|
||||
obj.scaling = rms(obj.get_levels());
|
||||
|
||||
obj.eth_style = options.eth_style;
|
||||
|
||||
end
|
||||
|
||||
function out = map(obj,signal_in)
|
||||
@@ -66,18 +76,25 @@ classdef PAMmapper
|
||||
switch obj.M
|
||||
case 2
|
||||
% 2-ASK: BPSK / OOK
|
||||
pam_sig=bitpattern(:,1);
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-1;
|
||||
if ~obj.eth_style
|
||||
pam_sig = bitpattern(:,1);
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-1;
|
||||
end
|
||||
else
|
||||
pam_sig = -2*bitpattern(:,1) + 1;
|
||||
end
|
||||
|
||||
case 4
|
||||
% 4-ASK:
|
||||
pam_sig=2*bitpattern(:,1)+(bitpattern(:,1)==bitpattern(:,2));
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-3;
|
||||
if ~obj.eth_style
|
||||
pam_sig=2*bitpattern(:,1)+(bitpattern(:,1)==bitpattern(:,2));
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-3;
|
||||
end
|
||||
else
|
||||
pam_sig = (2*bitpattern(:,1)-1).*(-2*bitpattern(:,2)+3);
|
||||
end
|
||||
|
||||
pam_sig = pam_sig/sqrt(5);
|
||||
@@ -97,15 +114,22 @@ classdef PAMmapper
|
||||
pam_sig = pam_sig/sqrt(10);
|
||||
|
||||
case 8
|
||||
|
||||
% 8-ASK:
|
||||
x1 = bitpattern(:,1);
|
||||
x2 = (bitpattern(:,1)==bitpattern(:,3));
|
||||
x3 = x2~=bitpattern(:,2);
|
||||
if ~obj.eth_style
|
||||
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
|
||||
else
|
||||
|
||||
pam_sig = 4*x1 + 2*x2 + x3;
|
||||
pam_sig = (bitpattern(:,1)*2-1).*(4+(2*bitpattern(:,2)-1).*(-2*bitpattern(:,3)+3));
|
||||
|
||||
if obj.unipolar==0
|
||||
pam_sig=2*pam_sig-7;
|
||||
end
|
||||
|
||||
pam_sig = pam_sig/sqrt(21);
|
||||
@@ -233,13 +257,19 @@ classdef PAMmapper
|
||||
|
||||
case 2
|
||||
% 2-ASK
|
||||
|
||||
data_out=comp_real(:,:,1);
|
||||
if ~obj.eth_style
|
||||
data_out=comp_real(:,:,1);
|
||||
else
|
||||
data_out=abs(comp_real(:,:,1)-1);
|
||||
end
|
||||
|
||||
case 4
|
||||
% 4-ASK
|
||||
|
||||
data_out=[comp_real(:,:,2); ones(s1,s2) - comp_real(:,:,1) + comp_real(:,:,3)];
|
||||
if ~obj.eth_style
|
||||
data_out=[comp_real(:,:,2); ones(s1,s2) - comp_real(:,:,1) + comp_real(:,:,3)];
|
||||
else
|
||||
data_out= [(data_in>=0); (abs(data_in)<=1)];
|
||||
end
|
||||
|
||||
case 6
|
||||
|
||||
@@ -262,13 +292,18 @@ classdef PAMmapper
|
||||
data_out(m:m+4) = bitget(dd_idx-1,5:-1:1);
|
||||
m = m+5;
|
||||
end
|
||||
|
||||
|
||||
|
||||
case 8
|
||||
% 8-ASK
|
||||
if ~obj.eth_style
|
||||
data_out=[comp_real(:,:,4);
|
||||
comp_real(:,:,1)-comp_real(:,:,3)+comp_real(:,:,5)-comp_real(:,:,7);
|
||||
1-comp_real(:,:,2)+comp_real(:,:,6)];
|
||||
else
|
||||
data_out = [(data_in>=0); (abs(data_in)>(4/sqrt(21))); (abs(data_in)>=(2/sqrt(21)))&(abs(data_in)<=(6/sqrt(21)))];
|
||||
end
|
||||
|
||||
case 16
|
||||
% 16-ASK
|
||||
|
||||
@@ -83,6 +83,8 @@ classdef PAMsource
|
||||
|
||||
%%%%% MOVE-IT PRMS %%%%
|
||||
|
||||
|
||||
|
||||
state = struct();
|
||||
|
||||
para = struct();
|
||||
@@ -103,6 +105,8 @@ classdef PAMsource
|
||||
para.reset_prms = 0;
|
||||
para.method = 1;
|
||||
|
||||
|
||||
|
||||
data_in = [];
|
||||
global loop;
|
||||
loop = 0;
|
||||
@@ -151,12 +155,16 @@ classdef PAMsource
|
||||
sym_max = max(symbols.signal);
|
||||
end
|
||||
|
||||
% symbols.move_it_spectrum("fignum",222,"displayname","Symbols only");
|
||||
|
||||
|
||||
% symbols.spectrum("fignum",222,"displayname","Symbols only","normalizeTo0dB",1);
|
||||
|
||||
% 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 = 'racos';
|
||||
|
||||
pulsf.process(symbols);
|
||||
|
||||
%%%%% Pulse-forming %%%%%%
|
||||
if obj.applypulseform
|
||||
digi_sig = obj.pulseformer.process(symbols);
|
||||
@@ -164,10 +172,13 @@ classdef PAMsource
|
||||
digi_sig = symbols;
|
||||
end
|
||||
|
||||
%%%%% 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",112,"displayname","2) after pulseforming");
|
||||
|
||||
%%%%% Re-sample to f DAC %%%%%%
|
||||
n = 10;
|
||||
digi_sig = digi_sig.resample("fs_in",digi_sig.fs,"fs_out",obj.fs_out,"n",n,"beta",5);
|
||||
% digi_sig.spectrum("fignum",111,"displayname",['3) Shaped + Resampled; n: ',num2str(n)]);
|
||||
|
||||
% digi_sig.spectrum("fignum",111,"displayname","after pulseforming");
|
||||
|
||||
%%%%% Hard clip digital signal to PAM range before DAC %%%%%%
|
||||
if obj.applyclipping
|
||||
|
||||
@@ -3,13 +3,15 @@ classdef Pulseformer
|
||||
% Detailed explanation goes here
|
||||
|
||||
properties(Access=public)
|
||||
fdac
|
||||
|
||||
end
|
||||
properties(Access=private)
|
||||
properties(Access=public)
|
||||
fdac
|
||||
fsym
|
||||
pulse
|
||||
pulselength
|
||||
rrcalpha
|
||||
alpha
|
||||
matched
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
@@ -20,9 +22,10 @@ classdef Pulseformer
|
||||
arguments
|
||||
options.fdac double
|
||||
options.fsym double
|
||||
options.pulse pulseform = pulseform.rrc
|
||||
options.pulse pulseform = pulseform.rc
|
||||
options.pulselength double {mustBeInteger} = 32
|
||||
options.rrcalpha double = 0.05
|
||||
options.alpha double = 0.05
|
||||
options.matched = 0;
|
||||
end
|
||||
|
||||
%
|
||||
@@ -86,49 +89,72 @@ classdef Pulseformer
|
||||
sps= up;
|
||||
end
|
||||
|
||||
if obj.pulse == pulseform.rrc
|
||||
%Bau das Filter (hier rrc)
|
||||
racos_len = obj.pulselength*2;
|
||||
alpha = obj.rrcalpha;
|
||||
h = rcosdesign(alpha,racos_len,sps,"normal");
|
||||
if obj.pulse == pulseform.rc
|
||||
filtertype = 'normal';
|
||||
elseif pulseform.rrc
|
||||
filtertype = 'sqrt';
|
||||
end
|
||||
|
||||
%Bau das Filter (hier rc)
|
||||
racos_len = obj.pulselength*2;
|
||||
h = rcosdesign(obj.alpha,racos_len,sps,filtertype);
|
||||
h = h./ max(h);
|
||||
|
||||
if obj.matched
|
||||
h = 1./h;
|
||||
end
|
||||
|
||||
manual_cyclic_convolution = 1;
|
||||
upfirdn_convolution = 0;
|
||||
|
||||
if manual_cyclic_convolution
|
||||
|
||||
% Apply filter the long way (from move_it)
|
||||
data_in = data_in';
|
||||
blen = length(data_in)*sps;
|
||||
|
||||
% oversample symbol sequence
|
||||
symbolov=zeros(size(data_in,1),blen);
|
||||
symbolov(:,1:sps:blen-sps+1)=data_in;
|
||||
H=fft(h,blen);
|
||||
|
||||
% Convolution of Bit sequence with impulse response
|
||||
data_out=ifft( fft(symbolov.') .* repmat( H,size(data_in,1),1 ).' ).';
|
||||
data_out = circshift(data_out,[0 -(obj.pulselength*sps)]);
|
||||
|
||||
if rem(obj.fdac,obj.fsym)
|
||||
data_out = data_out(1:dn:end);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if upfirdn_convolution
|
||||
|
||||
%Apply Filter using Matlab build in fctn.
|
||||
h = rcosdesign(obj.alpha,racos_len,sps,"normal");
|
||||
h = h./ max(h);
|
||||
data_out_ = upfirdn(data_in,h,up,dn);
|
||||
|
||||
%cut signal, which is longer due to fir filter
|
||||
st = round(up/dn*racos_len/2)+1; %we need to cut y_out
|
||||
en = round(st + (length(data_in)*up/dn));
|
||||
data_out_ = data_out_(st:en);
|
||||
|
||||
end
|
||||
|
||||
% Apply filter the long way (from move_it)
|
||||
% block length in samples
|
||||
|
||||
data_in = data_in';
|
||||
blen = length(data_in)*sps;
|
||||
|
||||
% oversample symbol sequence
|
||||
|
||||
symbolov=zeros(size(data_in,1),blen);
|
||||
symbolov(:,1:sps:blen-sps+1)=data_in;
|
||||
|
||||
H=fft(h,blen);
|
||||
|
||||
% Convolution of Bit sequence with impulse response
|
||||
|
||||
% cyclic convolution
|
||||
data_out=ifft( fft(symbolov.') .* repmat( H,size(data_in,1),1 ).' ).';
|
||||
|
||||
data_out = circshift(data_out,[0 -(obj.pulselength*sps)]);
|
||||
|
||||
if rem(obj.fdac,obj.fsym)
|
||||
data_out = data_out(1:dn:end); %!
|
||||
if upfirdn_convolution && manual_cyclic_convolution
|
||||
figure()
|
||||
subplot(2,1,1)
|
||||
title("Convolution vs. Upfirdn and Cut")
|
||||
hold on
|
||||
plot(data_out_(1:200),'DisplayName','Matlab upfirdn');
|
||||
plot(data_out(1:200),'DisplayName','By Hand cyclic convolution')
|
||||
subplot(2,1,2)
|
||||
hold on
|
||||
plot(data_out(1:2000),'DisplayName','OUT');
|
||||
plot(data_in(1:2000),'DisplayName','IN');
|
||||
end
|
||||
|
||||
|
||||
% %Apply Filter using Matlab build in fctn.
|
||||
% h = rcosdesign(alpha,racos_len,sps);
|
||||
% h = h./ max(h);
|
||||
%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);
|
||||
|
||||
%scaling?! see pulsef module line 696
|
||||
% scale = max(max([abs(real(data_out)) abs(imag(data_out))])); %find max value from real and imag part
|
||||
% data_out = data_out./scale;
|
||||
|
||||
Reference in New Issue
Block a user