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