Example #1
0
File: call.py Project: JsAaron/cdr
def testCopy():
    cdrObj = CDR(
        "D:\\github\\cdr\\mmxai\\src\\templates\\brochures\\画册-医疗-竖-001.cdr")
    cdrObj1 = CDR(
        "D:\\github\\cdr\\mmxai\\src\\templates\\brochures\\Backup_of_画册-医疗-竖-001.cdr"
    )
    cdrObj.acrossCopyToLayer(cdrObj1, 6)
Example #2
0
File: call.py Project: JsAaron/cdr
def moveToMiddle():
    cdrObj = CDR()
    # cdrObj.moveToLandscapeMiddle("测试1")
    # cdrObj.moveToLeft(obj)
    # cdrObj.moveToRight('测试1')
    # cdrObj.moveToTop('测试1')
    # cdrObj.moveToBottom('测试1')
    # cdrObj.moveToVerticalMiddle('测试1')
    cdrObj.moveToCenter('测试1')
Example #3
0
File: call.py Project: JsAaron/cdr
def testPowerClip():
    d1 = CDR()
    layer = d1.getLayer("秒秒学装饰")
    # 必须设置活动的layer,这样调用vb.exe才会在这个layer的内部
    layer.Activate()
    imgShape = d1.addImage(layer,
                           "C:\\Users\\Administrator\\Desktop\\111\\1.png")
    #设置单位像素
    d1.doc.Unit = 5
    ellipse = layer.CreateEllipse(100, 100, 500, 500)
    imgShape.AddToSelection()
    imgShape.AddToPowerClip(ellipse)
Example #4
0
File: call.py Project: JsAaron/cdr
def paletteTest1():
    cdrObj = CDR()
    paletteObj = cdrObj.accessPalette('my')
    cdrObj.setPletteEnabled(paletteObj)  #启用
    # 创建一个颜色对象,使用指定格式
    color = cdrObj.createColorObj([110, 128, 255], 'unique_key', 'RGB')
    # 把颜色增加到调色板上
    cdrObj.addPletteColor(paletteObj, color)
Example #5
0
File: call.py Project: JsAaron/cdr
def testSaveCDR():
    cdrObj = CDR()

    # for thecolor in paletteObj.Colors():
    #     print(thecolor)
    standardColor = {
        "69_2_20_0": "深色背景",
        "1_0_0_0": "暮光之城色",
        "93_88_89_80": "仓色",
        "0_0_0_0": "白色",
        "100_88_47_61": "Stratos"
        # "6_4_4_0":"瓷色"
    }

    errorObj = cdrObj.standardizedColor(standardColor)
    print(errorObj)
Example #6
0
File: call.py Project: JsAaron/cdr
def setContent(pageIndex="", path=""):
    data = {
        'logo': {
            'pageIndex': 1,
            'value': 'C:\\Users\\Administrator\\Desktop\\111\\1.png'
        }
    }
    CDR().set(data)
Example #7
0
File: call.py Project: JsAaron/cdr
def testGroup():
    cdrObj = CDR()
    layer = cdrObj.getLayer("秒秒学装饰")
    s1 = layer.FindShape("test1")
    s2 = layer.FindShape("test2")
    s3 = layer.FindShape("test3")
    s4 = layer.FindShape("test4")

    # 创建4个边界三角形
    if s1 == None:
        s1 = cdrObj.drawDecorationTriangle("test1",
                                           {"background-color": [255, 0, 0]}, {
                                               "bottom": 300,
                                               "left": 600
                                           }, 'lefttop')
    if s2 == None:
        s2 = cdrObj.drawDecorationTriangle("test2",
                                           {"background-color": [255, 0, 0]}, {
                                               "top": 300,
                                               "right": 600
                                           }, 'rightbottom')
    if s3 == None:
        s3 = cdrObj.drawDecorationTriangle("test3",
                                           {"background-color": [255, 0, 0]}, {
                                               "top": 300,
                                               "right": 600
                                           }, 'rightbottom')
    if s4 == None:
        s4 = cdrObj.drawDecorationTriangle("test4",
                                           {"background-color": [255, 0, 0]}, {
                                               "top": 300,
                                               "right": 600
                                           }, 'rightbottom')
Example #8
0
File: call.py Project: JsAaron/cdr
def drawDecorationTriangle():
    # CDR().groupDecorationTriangle()
    CDR().drawDecorationTriangle("test", {"background-color": [255, 0, 0]}, {
        "bottom": 300,
        "left": 600
    }, 'lefttop')
    CDR().drawDecorationTriangle("test", {"background-color": [255, 0, 0]}, {
        "bottom": 300,
        "right": 600
    }, 'righttop')
    CDR().drawDecorationTriangle("test", {"background-color": [255, 0, 0]}, {
        "top": 300,
        "left": 600
    }, 'leftbottom')
    CDR().drawDecorationTriangle("test", {"background-color": [255, 0, 0]}, {
        "top": 300,
        "right": 600
    }, 'rightbottom')
Example #9
0
File: call.py Project: JsAaron/cdr
def addShapeToGroup():
    cdrObj = CDR()
    layerObj = cdrObj.getLayer('秒秒学装饰')
    g1 = cdrObj.groupShapeObjs(
        layerObj,
        "占位组",
    )
    g2 = cdrObj.groupShapeObjs(layerObj, "子组占位组1", g1)
    g3 = cdrObj.groupShapeObjs(layerObj, "子组占位组2", g2)
    g4 = cdrObj.groupShapeObjs(layerObj, "子组占位组3", g3)

    s1 = layerObj.FindShape("test1")
    if s1 == None:
        s1 = cdrObj.drawDecorationTriangle("test1",
                                           {"background-color": [255, 0, 0]}, {
                                               "bottom": 300,
                                               "left": 600
                                           }, 'lefttop')

    # 增加一个对象到组
    cdrObj.addShapeToGroup(g4, s1)
Example #10
0
class DFE(object):
    """Behavioral model of a decision feedback equalizer (DFE)."""

    def __init__(self, n_taps, gain, delta_t, alpha, ui, n_spb, decision_scaler, mod_type=0, bandwidth=100.e9,
                       n_ave=10, n_lock_ave=500, rel_lock_tol=0.01, lock_sustain=500, ideal=True):
        """
        Inputs:

          Required:

          - n_taps           # of taps in adaptive filter

          - gain             adaptive filter tap weight correction gain

          - delta_t          CDR proportional branch constant (ps)

          - alpha            CDR integral branch constant (normalized to delta_t)

          - ui               nominal unit interval (ps)

          - n_spb            # of samples per unit interval

          - decision_scaler  multiplicative constant applied to the result of
                             the sign function, when making a "1 vs. 0" decision.
                             Sets the target magnitude for the DFE.

          Optional:

          - mod_type         The modulation type:
                             - 0: NRZ
                             - 1: Duo-binary
                             - 2: PAM-4

          - bandwidth        The bandwidth, at the summing node (Hz).

          - n_ave            The number of averages to take, before adapting.
                             (Also, the number of CDR adjustments per DFE adaptation.)

          - n_lock_ave       The number of unit interval estimates to
                             consider, when determining locked status.

          - rel_lock_tol     The relative tolerance for determining lock.

          - lock_sustain     Length of the histerysis vector used for
                             lock flagging.

          - ideal            Boolean flag. When true, use an ideal summing node.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        # Design summing node filter.
        fs     = n_spb / ui
        (b, a) = iirfilter(gNch_taps - 1, bandwidth/(fs/2), btype='lowpass')
        self.summing_filter = LfilterSS(b, a)

        # Initialize class variables.
        self.tap_weights       = [0.0] * n_taps
        self.tap_values        = [0.0] * n_taps
        self.gain              = gain
        self.ui                = ui
        self.decision_scaler   = decision_scaler
        self.mod_type          = mod_type
        self.cdr               = CDR(delta_t, alpha, ui, n_lock_ave, rel_lock_tol, lock_sustain)
        self.n_ave             = n_ave
        self.corrections       = zeros(n_taps)
        self.ideal             = ideal

        thresholds = []
        if  (mod_type == 0): # NRZ
            pass
        elif(mod_type == 1): # Duo-binary
            thresholds.append(-decision_scaler / 2.)
            thresholds.append( decision_scaler / 2.)
        elif(mod_type == 2): # PAM-4
            thresholds.append(-decision_scaler * 2. / 3.)
            thresholds.append(0.)
            thresholds.append( decision_scaler * 2. / 3.)
        else:
            raise Exception("ERROR: DFE.__init__(): Unrecognized modulation type requested!")
        self.thresholds = thresholds

    def step(self, decision, error, update):
        """
        Step the DFE, according to the new decision and error inputs.

        Args:
            decision(float): Current slicer output.
            error(float): Difference between summing node and slicer outputs.
            update(bool): If true, update tap weights.

        Returns:
            res(float): New backward filter output value.
        """

        # Copy class object variables into local function namespace, for efficiency.
        tap_weights = self.tap_weights
        tap_values  = self.tap_values
        gain        = self.gain
        n_ave       = self.n_ave
        summing_filter = self.summing_filter

        # Calculate this step's corrections and add to running total.
        corrections = [old + new for (old, new) in zip(self.corrections,
                                                       [val * error * gain for val in tap_values])]

        # Update the tap weights with the average corrections, if appropriate.
        if(update):
            tap_weights = [weight + correction / n_ave for (weight, correction) in zip(tap_weights, corrections)]
            corrections = zeros(len(corrections)) # Start the averaging process over, again.

        # Step the filter delay chain and generate the new output.
        tap_values  = [decision] + tap_values[:-1]
        filter_out  = sum(array(tap_weights) * array(tap_values))

        # Copy local values back to their respective class object variables.
        self.tap_weights = tap_weights
        self.tap_values  = tap_values
        self.corrections = corrections

        return filter_out

    def decide(self, x):
        """
        Make the bit decisions, according to modulation type.

        Args:
            x(float): The signal value, at the decision time.

        Returns:
            tuple(float, [int]): The members of the returned tuple are:

                decision:
                    One of:

                        - {-1, 1}              (NRZ)
                        - {-1, 0, +1}          (Duo-binary)
                        - {-1, -1/3, +1/3, +1} (PAM-4)

                        according to what the ideal signal level should have been.
                        ('decision_scaler' normalized)

                bits: The list of bits recovered.

        Raises:
            Exception: If the requested modulation type is unknown.

        """

        mod_type   = self.mod_type
        thresholds = self.thresholds

        if  (mod_type == 0): # NRZ
            decision = sign(x)
            if(decision > 0):
                bits = [1]
            else:
                bits = [0]
        elif(mod_type == 1): # Duo-binary
            if((x > self.thresholds[0]) ^ (x > self.thresholds[1])):
                decision = 0
                bits     = [1]
            else:
                decision = sign(x)
                bits     = [0]
        elif(mod_type == 2): # PAM-4
            if  (x > self.thresholds[2]):
                decision = 1
                bits     = [1, 1]
            elif(x > self.thresholds[1]):
                decision = 1. / 3.
                bits     = [1, 0]
            elif(x > self.thresholds[0]):
                decision = -1. / 3.
                bits     = [0, 1]
            else:
                decision = -1
                bits     = [0, 0]
        else:
            raise Exception("ERROR: DFE.decide(): Unrecognized modulation type requested!")

        return decision, bits

    def run(self, sample_times, signal):
        """
        Run the DFE on the input signal.

        Args:
            sample_times([float]): Vector of time values at wich
                corresponding signal values were sampled.
            signal([float]): Vector of sampled signal values.

        Returns:
            tuple(([float], [[float]], [float], [int], [bool], [float], [int])):
                The members of the returned tuple, in order, are:

                    res([float]):
                        Samples of the summing node output, taken at the
                        times given in *sample_times*.
                    tap_weights([[float]]):
                        List of list of tap weights showing how the DFE
                        adapted over time.
                    ui_ests([float]):
                        List of unit interval estimates, showing how the
                        CDR adapted.
                    clocks([int]):
                        List of mostly zeros with ones at the recovered
                        clocking instants. Useful for overlaying the
                        clock times on signal waveforms, in plots.
                    lockeds([bool]):
                        List of Booleans indicating state of CDR lock.
                    clock_times([float]):
                        List of clocking instants, as recovered by the CDR.
                    bits([int]):
                        List of recovered bits.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        ui                = self.ui
        decision_scaler   = self.decision_scaler
        n_ave             = self.n_ave
        summing_filter    = self.summing_filter
        ideal             = self.ideal
        mod_type          = self.mod_type
        thresholds        = self.thresholds

        clk_cntr           = 0
        smpl_cntr          = 0
        filter_out         = 0
        nxt_filter_out     = 0
        last_clock_sample  = 0
        next_boundary_time = 0
        next_clock_time    = ui / 2.
        locked             = False

        res         = []
        tap_weights = [self.tap_weights]
        ui_ests     = []
        lockeds     = []
        clocks      = zeros(len(sample_times))
        clock_times = [next_clock_time]
        bits        = []
        for (t, x) in zip(sample_times, signal):
            if(not ideal):
                sum_out = summing_filter.step(x - filter_out)
            else:
                sum_out = x - filter_out
            res.append(sum_out)
            if(t >= next_boundary_time):
                boundary_sample = sum_out
                filter_out = nxt_filter_out
                next_boundary_time += ui # Necessary, in order to prevent premature reentry.
            if(t >= next_clock_time):
                clk_cntr += 1
                clocks[smpl_cntr] = 1
                current_clock_sample = sum_out
                samples = [last_clock_sample, boundary_sample, current_clock_sample]
                if  (mod_type == 0): # NRZ
                    pass
                elif(mod_type == 1): # Duo-binary
                    samples = array(samples)
                    if(samples.mean() < 0.):
                        samples -= thresholds[0]
                    else:
                        samples -= thresholds[1]
                    samples = list(samples)
                elif(mod_type == 2): # PAM-4
                    pass
                else:
                    raise Exception("ERROR: DFE.run(): Unrecognized modulation type!")
                ui, locked     = self.cdr.adapt(samples)
                decision, new_bits = self.decide(sum_out)
                bits.extend(new_bits)
                slicer_output = decision * decision_scaler
                error  = sum_out - slicer_output
                update = locked and (clk_cntr % n_ave) == 0
                if(locked): # We only want error accumulation to happen, when we're locked.
                    nxt_filter_out = self.step(slicer_output, error, update)
                else:
                    nxt_filter_out = self.step(decision, 0., update)
                tap_weights.append(self.tap_weights)
                last_clock_sample  = sum_out
                next_boundary_time = next_clock_time + ui / 2.
                next_clock_time   += ui
                clock_times.append(next_clock_time)
            ui_ests.append(ui)
            lockeds.append(locked)
            smpl_cntr += 1

        self.ui                = ui               

        return (res, tap_weights, ui_ests, clocks, lockeds, clock_times, bits)
Example #11
0
    def __init__(self, n_taps, gain, delta_t, alpha, ui, n_spb, decision_scaler, mod_type=0, bandwidth=100.e9,
                       n_ave=10, n_lock_ave=500, rel_lock_tol=0.01, lock_sustain=500, ideal=True):
        """
        Inputs:

          Required:

          - n_taps           # of taps in adaptive filter

          - gain             adaptive filter tap weight correction gain

          - delta_t          CDR proportional branch constant (ps)

          - alpha            CDR integral branch constant (normalized to delta_t)

          - ui               nominal unit interval (ps)

          - n_spb            # of samples per unit interval

          - decision_scaler  multiplicative constant applied to the result of
                             the sign function, when making a "1 vs. 0" decision.
                             Sets the target magnitude for the DFE.

          Optional:

          - mod_type         The modulation type:
                             - 0: NRZ
                             - 1: Duo-binary
                             - 2: PAM-4

          - bandwidth        The bandwidth, at the summing node (Hz).

          - n_ave            The number of averages to take, before adapting.
                             (Also, the number of CDR adjustments per DFE adaptation.)

          - n_lock_ave       The number of unit interval estimates to
                             consider, when determining locked status.

          - rel_lock_tol     The relative tolerance for determining lock.

          - lock_sustain     Length of the histerysis vector used for
                             lock flagging.

          - ideal            Boolean flag. When true, use an ideal summing node.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        # Design summing node filter.
        fs     = n_spb / ui
        (b, a) = iirfilter(gNch_taps - 1, bandwidth/(fs/2), btype='lowpass')
        self.summing_filter = LfilterSS(b, a)

        # Initialize class variables.
        self.tap_weights       = [0.0] * n_taps
        self.tap_values        = [0.0] * n_taps
        self.gain              = gain
        self.ui                = ui
        self.decision_scaler   = decision_scaler
        self.mod_type          = mod_type
        self.cdr               = CDR(delta_t, alpha, ui, n_lock_ave, rel_lock_tol, lock_sustain)
        self.n_ave             = n_ave
        self.corrections       = zeros(n_taps)
        self.ideal             = ideal

        thresholds = []
        if  (mod_type == 0): # NRZ
            pass
        elif(mod_type == 1): # Duo-binary
            thresholds.append(-decision_scaler / 2.)
            thresholds.append( decision_scaler / 2.)
        elif(mod_type == 2): # PAM-4
            thresholds.append(-decision_scaler * 2. / 3.)
            thresholds.append(0.)
            thresholds.append( decision_scaler * 2. / 3.)
        else:
            raise Exception("ERROR: DFE.__init__(): Unrecognized modulation type requested!")
        self.thresholds = thresholds
Example #12
0
File: call.py Project: JsAaron/cdr
def open():
    print(CDR('C:\\Users\\Administrator\\Desktop\\11.cdr'))
Example #13
0
File: call.py Project: JsAaron/cdr
def increaseFontSize():
    cdrObj = CDR()
    cdrObj.loadPalette('C:\\Users\\Administrator\\Desktop\\123\\cw.xml')
Example #14
0
File: call.py Project: JsAaron/cdr
def combineTest():
    cdrObj = CDR()
    obj = cdrObj.insertParaText(
        [0, 0, 120, 500], '测试1',
        '我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf1111我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf111111'
    )
    cdrObj.setColor(obj, [255, 0, 0])
    cdrObj.addFontSize(obj, 24)
    cdrObj.moveToCenter(obj)
    cdrObj.modifyParaText(
        obj,
        'dfs123123大1sdfasfsfsdf2312dfsadfsfsdf11111我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf11111我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf11111我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf11111我是内容123123大1sdfasfsfsdf2312dfsadfsfsdf11111',
        [5, 50, 100, 50], '', '')
    cdrObj.setFontSize(obj, 10)
Example #15
0
File: call.py Project: JsAaron/cdr
def testColor():
    cdrObj = CDR()
    # cdrObj.setColor('测试1',[255,0,0])
    cdrObj.createPage(5)
Example #16
0
File: call.py Project: JsAaron/cdr
def paletteTest2():
    cdrObj = CDR()
    paletteObj = cdrObj.accessPalette('my')
    newColor = cdrObj.createColorObj([0, 255, 255], 'unique_key', 'RGB')
    cdrObj.replacePletteColorByName(paletteObj, newColor)
Example #17
0
File: call.py Project: JsAaron/cdr
def testFont():
    # font = TTFont('‪simsun.ttf')
    cdrObj = CDR()
    for k in cdrObj.app.FontList:
        print(k)
Example #18
0
File: call.py Project: JsAaron/cdr
def getContent(pageIndex=""):
    print('返回', CDR().get(pageIndex))
Example #19
0
 def make(self, mode=CDRSamplerMode.NORMAL):
     raw_CDR = {k: v.make(mode) for k, v in self.attributes.items()}
     return CDR(raw_CDR)
Example #20
0
class DFE(object):
    """Behavioral model of a decision feedback equalizer (DFE)."""
    def __init__(self,
                 n_taps,
                 gain,
                 delta_t,
                 alpha,
                 ui,
                 n_spb,
                 decision_scaler,
                 mod_type=0,
                 bandwidth=100.e9,
                 n_ave=10,
                 n_lock_ave=500,
                 rel_lock_tol=0.01,
                 lock_sustain=500,
                 ideal=True):
        """
        Inputs:

          Required:

          - n_taps           # of taps in adaptive filter

          - gain             adaptive filter tap weight correction gain

          - delta_t          CDR proportional branch constant (ps)

          - alpha            CDR integral branch constant (normalized to delta_t)

          - ui               nominal unit interval (ps)

          - n_spb            # of samples per unit interval

          - decision_scaler  multiplicative constant applied to the result of
                             the sign function, when making a "1 vs. 0" decision.
                             Sets the target magnitude for the DFE.

          Optional:

          - mod_type         The modulation type:
                             - 0: NRZ
                             - 1: Duo-binary
                             - 2: PAM-4

          - bandwidth        The bandwidth, at the summing node (Hz).

          - n_ave            The number of averages to take, before adapting.
                             (Also, the number of CDR adjustments per DFE adaptation.)

          - n_lock_ave       The number of unit interval estimates to
                             consider, when determining locked status.

          - rel_lock_tol     The relative tolerance for determining lock.

          - lock_sustain     Length of the histerysis vector used for
                             lock flagging.

          - ideal            Boolean flag. When true, use an ideal summing node.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        # Design summing node filter.
        fs = n_spb / ui
        (b, a) = iirfilter(gNch_taps - 1,
                           bandwidth / (fs / 2),
                           btype='lowpass')
        self.summing_filter = LfilterSS(b, a)

        # Initialize class variables.
        self.tap_weights = [0.0] * n_taps
        self.tap_values = [0.0] * n_taps
        self.gain = gain
        self.ui = ui
        self.decision_scaler = decision_scaler
        self.mod_type = mod_type
        self.cdr = CDR(delta_t, alpha, ui, n_lock_ave, rel_lock_tol,
                       lock_sustain)
        self.n_ave = n_ave
        self.corrections = zeros(n_taps)
        self.ideal = ideal

        thresholds = []
        if (mod_type == 0):  # NRZ
            pass
        elif (mod_type == 1):  # Duo-binary
            thresholds.append(-decision_scaler / 2.)
            thresholds.append(decision_scaler / 2.)
        elif (mod_type == 2):  # PAM-4
            thresholds.append(-decision_scaler * 2. / 3.)
            thresholds.append(0.)
            thresholds.append(decision_scaler * 2. / 3.)
        else:
            raise Exception(
                "ERROR: DFE.__init__(): Unrecognized modulation type requested!"
            )
        self.thresholds = thresholds

    def step(self, decision, error, update):
        """
        Step the DFE, according to the new decision and error inputs.

        Args:
            decision(float): Current slicer output.
            error(float): Difference between summing node and slicer outputs.
            update(bool): If true, update tap weights.

        Returns:
            res(float): New backward filter output value.
        """

        # Copy class object variables into local function namespace, for efficiency.
        tap_weights = self.tap_weights
        tap_values = self.tap_values
        gain = self.gain
        n_ave = self.n_ave
        summing_filter = self.summing_filter

        # Calculate this step's corrections and add to running total.
        corrections = [
            old + new for (old, new) in zip(
                self.corrections, [val * error * gain for val in tap_values])
        ]

        # Update the tap weights with the average corrections, if appropriate.
        if (update):
            tap_weights = [
                weight + correction / n_ave
                for (weight, correction) in zip(tap_weights, corrections)
            ]
            corrections = zeros(
                len(corrections))  # Start the averaging process over, again.

        # Step the filter delay chain and generate the new output.
        tap_values = [decision] + tap_values[:-1]
        filter_out = sum(array(tap_weights) * array(tap_values))

        # Copy local values back to their respective class object variables.
        self.tap_weights = tap_weights
        self.tap_values = tap_values
        self.corrections = corrections

        return filter_out

    def decide(self, x):
        """
        Make the bit decisions, according to modulation type.

        Args:
            x(float): The signal value, at the decision time.

        Returns:
            tuple(float, [int]): The members of the returned tuple are:

                decision:
                    One of:

                        - {-1, 1}              (NRZ)
                        - {-1, 0, +1}          (Duo-binary)
                        - {-1, -1/3, +1/3, +1} (PAM-4)

                        according to what the ideal signal level should have been.
                        ('decision_scaler' normalized)

                bits: The list of bits recovered.

        Raises:
            Exception: If the requested modulation type is unknown.

        """

        mod_type = self.mod_type
        thresholds = self.thresholds

        if (mod_type == 0):  # NRZ
            decision = sign(x)
            if (decision > 0):
                bits = [1]
            else:
                bits = [0]
        elif (mod_type == 1):  # Duo-binary
            if ((x > self.thresholds[0]) ^ (x > self.thresholds[1])):
                decision = 0
                bits = [1]
            else:
                decision = sign(x)
                bits = [0]
        elif (mod_type == 2):  # PAM-4
            if (x > self.thresholds[2]):
                decision = 1
                bits = [1, 1]
            elif (x > self.thresholds[1]):
                decision = 1. / 3.
                bits = [1, 0]
            elif (x > self.thresholds[0]):
                decision = -1. / 3.
                bits = [0, 1]
            else:
                decision = -1
                bits = [0, 0]
        else:
            raise Exception(
                "ERROR: DFE.decide(): Unrecognized modulation type requested!")

        return decision, bits

    def run(self, sample_times, signal):
        """
        Run the DFE on the input signal.

        Args:
            sample_times([float]): Vector of time values at wich
                corresponding signal values were sampled.
            signal([float]): Vector of sampled signal values.

        Returns:
            tuple(([float], [[float]], [float], [int], [bool], [float], [int])):
                The members of the returned tuple, in order, are:

                    res([float]):
                        Samples of the summing node output, taken at the
                        times given in *sample_times*.
                    tap_weights([[float]]):
                        List of list of tap weights showing how the DFE
                        adapted over time.
                    ui_ests([float]):
                        List of unit interval estimates, showing how the
                        CDR adapted.
                    clocks([int]):
                        List of mostly zeros with ones at the recovered
                        clocking instants. Useful for overlaying the
                        clock times on signal waveforms, in plots.
                    lockeds([bool]):
                        List of Booleans indicating state of CDR lock.
                    clock_times([float]):
                        List of clocking instants, as recovered by the CDR.
                    bits([int]):
                        List of recovered bits.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        ui = self.ui
        decision_scaler = self.decision_scaler
        n_ave = self.n_ave
        summing_filter = self.summing_filter
        ideal = self.ideal
        mod_type = self.mod_type
        thresholds = self.thresholds

        clk_cntr = 0
        smpl_cntr = 0
        filter_out = 0
        nxt_filter_out = 0
        last_clock_sample = 0
        next_boundary_time = 0
        next_clock_time = ui / 2.
        locked = False

        res = []
        tap_weights = [self.tap_weights]
        ui_ests = []
        lockeds = []
        clocks = zeros(len(sample_times))
        clock_times = [next_clock_time]
        bits = []
        for (t, x) in zip(sample_times, signal):
            if (not ideal):
                sum_out = summing_filter.step(x - filter_out)
            else:
                sum_out = x - filter_out
            res.append(sum_out)
            if (t >= next_boundary_time):
                boundary_sample = sum_out
                filter_out = nxt_filter_out
                next_boundary_time += ui  # Necessary, in order to prevent premature reentry.
            if (t >= next_clock_time):
                clk_cntr += 1
                clocks[smpl_cntr] = 1
                current_clock_sample = sum_out
                samples = [
                    last_clock_sample, boundary_sample, current_clock_sample
                ]
                if (mod_type == 0):  # NRZ
                    pass
                elif (mod_type == 1):  # Duo-binary
                    samples = array(samples)
                    if (samples.mean() < 0.):
                        samples -= thresholds[0]
                    else:
                        samples -= thresholds[1]
                    samples = list(samples)
                elif (mod_type == 2):  # PAM-4
                    pass
                else:
                    raise Exception(
                        "ERROR: DFE.run(): Unrecognized modulation type!")
                ui, locked = self.cdr.adapt(samples)
                decision, new_bits = self.decide(sum_out)
                bits.extend(new_bits)
                slicer_output = decision * decision_scaler
                error = sum_out - slicer_output
                update = locked and (clk_cntr % n_ave) == 0
                if (
                        locked
                ):  # We only want error accumulation to happen, when we're locked.
                    nxt_filter_out = self.step(slicer_output, error, update)
                else:
                    nxt_filter_out = self.step(decision, 0., update)
                tap_weights.append(self.tap_weights)
                last_clock_sample = sum_out
                next_boundary_time = next_clock_time + ui / 2.
                next_clock_time += ui
                clock_times.append(next_clock_time)
            ui_ests.append(ui)
            lockeds.append(locked)
            smpl_cntr += 1

        self.ui = ui

        return (res, tap_weights, ui_ests, clocks, lockeds, clock_times, bits)
Example #21
0
File: call.py Project: JsAaron/cdr
def replacePart():
    cdrObj = CDR()
Example #22
0
File: call.py Project: JsAaron/cdr
def paletteTest3():
    cdrObj = CDR()
    print(cdrObj.app.Printers)
Example #23
0
    def __init__(self,
                 n_taps,
                 gain,
                 delta_t,
                 alpha,
                 ui,
                 n_spb,
                 decision_scaler,
                 mod_type=0,
                 bandwidth=100.e9,
                 n_ave=10,
                 n_lock_ave=500,
                 rel_lock_tol=0.01,
                 lock_sustain=500,
                 ideal=True):
        """
        Inputs:

          Required:

          - n_taps           # of taps in adaptive filter

          - gain             adaptive filter tap weight correction gain

          - delta_t          CDR proportional branch constant (ps)

          - alpha            CDR integral branch constant (normalized to delta_t)

          - ui               nominal unit interval (ps)

          - n_spb            # of samples per unit interval

          - decision_scaler  multiplicative constant applied to the result of
                             the sign function, when making a "1 vs. 0" decision.
                             Sets the target magnitude for the DFE.

          Optional:

          - mod_type         The modulation type:
                             - 0: NRZ
                             - 1: Duo-binary
                             - 2: PAM-4

          - bandwidth        The bandwidth, at the summing node (Hz).

          - n_ave            The number of averages to take, before adapting.
                             (Also, the number of CDR adjustments per DFE adaptation.)

          - n_lock_ave       The number of unit interval estimates to
                             consider, when determining locked status.

          - rel_lock_tol     The relative tolerance for determining lock.

          - lock_sustain     Length of the histerysis vector used for
                             lock flagging.

          - ideal            Boolean flag. When true, use an ideal summing node.

        Raises:
            Exception: If the requested modulation type is unknown.
        """

        # Design summing node filter.
        fs = n_spb / ui
        (b, a) = iirfilter(gNch_taps - 1,
                           bandwidth / (fs / 2),
                           btype='lowpass')
        self.summing_filter = LfilterSS(b, a)

        # Initialize class variables.
        self.tap_weights = [0.0] * n_taps
        self.tap_values = [0.0] * n_taps
        self.gain = gain
        self.ui = ui
        self.decision_scaler = decision_scaler
        self.mod_type = mod_type
        self.cdr = CDR(delta_t, alpha, ui, n_lock_ave, rel_lock_tol,
                       lock_sustain)
        self.n_ave = n_ave
        self.corrections = zeros(n_taps)
        self.ideal = ideal

        thresholds = []
        if (mod_type == 0):  # NRZ
            pass
        elif (mod_type == 1):  # Duo-binary
            thresholds.append(-decision_scaler / 2.)
            thresholds.append(decision_scaler / 2.)
        elif (mod_type == 2):  # PAM-4
            thresholds.append(-decision_scaler * 2. / 3.)
            thresholds.append(0.)
            thresholds.append(decision_scaler * 2. / 3.)
        else:
            raise Exception(
                "ERROR: DFE.__init__(): Unrecognized modulation type requested!"
            )
        self.thresholds = thresholds
Example #24
0
File: call.py Project: JsAaron/cdr
def togglePage():
    print(CDR().togglePage(2))
Example #25
0
from cdr import CDR

docPath = 'D:\\AILab\\Data\\CDRs\\test.docx'
TEST = 'C:\\Users\\Administrator\\Desktop\\test.cdr'

cdr = CDR(TEST)
cdr.togglePage(1)

layer = cdr.doc.ActiveLayer
shape = cdr.doc.ActiveShape

cdr.togglePage(1)
story = shape.Text.Story
paragraphs = story.paragraphs

modifyParagraph = []

for paragraph in paragraphs:
    thetext = paragraph.WideText
    if '\t' in thetext:
        # print('thetext',thetext)
        splits = thetext.split('\t')
        prefix = splits[0]
        theord = ord(prefix[0])
        if theord > 61000:
            remain = ''
            if len(splits) > 0:
                remain = splits[1]

            paragraph.Text = remain.strip() + "\r"
            paragraph.ApplyBulletEffect(prefix, None, paragraph.Size, -1)
Example #26
0
File: call.py Project: JsAaron/cdr
def testExportImage():
    cdrObj = CDR()
    cdrObj.exportBitmap(
        'C:\\Users\\Administrator\\Desktop\\111\\test\\test.png', 6)
    pass