【问题标题】:Bitplane decomposition of 16 bit two's complement signed integer signal data?16位二进制补码有符号整数信号数据的位平面分解?
【发布时间】:2021-03-27 08:27:03
【问题描述】:

我正在尝试在 python 中对 16 位二进制补码有符号整数信号数据(心电图)进行位平面分解,因此我将获得 16 个信号数据位平面。我知道如何分解一个 8 位无符号整数图像信号,我重新实现了这个问题中的代码。我认为我应该获得其值包含负数的位平面数据,因为它最初是一个 16 位有符号整数,但我得到的结果是 16 位无符号整数信号而不是 16 位有符号整数信号。
这是我的代码:

import numpy as np
def intToTcbin16(value):
    return format(value % (1 << 16), '016b')
def Tcbin16ToInt(bin):
    while len(bin)<16 :
            bin = '0'+bin
    if bin[0] == '0':
            return int(bin, 2)
    else:
            return -1 * (int(''.join('1' if x == '0' else '0' for x in bin), 2) + 1)
def bitplanedecomposesignal(ecgdat):
    lst = []
    for j in range(len(ecgdat)):
        lst.append(intToTcbin16(ecgdat[j]))
    sixteen = (np.array([Tcbin16ToInt(i[0]) for i in lst],dtype = np.int16)*32768)
    fiveteen = (np.array([Tcbin16ToInt(i[1]) for i in lst],dtype = np.int16)*16384)
    fourteen = (np.array([Tcbin16ToInt(i[2]) for i in lst],dtype = np.int16)*8192)
    thirteen = (np.array([Tcbin16ToInt(i[3]) for i in lst],dtype = np.int16)*4096)
    twelve = (np.array([Tcbin16ToInt(i[4]) for i in lst],dtype = np.int16)*2048)
    eleven = (np.array([Tcbin16ToInt(i[5]) for i in lst],dtype = np.int16)*1024)
    ten = (np.array([Tcbin16ToInt(i[6]) for i in lst],dtype = np.int16)*512)
    nine = (np.array([Tcbin16ToInt(i[7]) for i in lst],dtype = np.int16)*256)
    eight = (np.array([Tcbin16ToInt(i[8]) for i in lst],dtype = np.int16)*128)
    seven = (np.array([Tcbin16ToInt(i[9]) for i in lst],dtype = np.int16)*64)
    six = (np.array([Tcbin16ToInt(i[10]) for i in lst],dtype = np.int16)*32)
    five = (np.array([Tcbin16ToInt(i[11]) for i in lst],dtype = np.int16)*16)
    four = (np.array([Tcbin16ToInt(i[12]) for i in lst],dtype = np.int16)*8)
    three = (np.array([Tcbin16ToInt(i[13]) for i in lst],dtype = np.int16)*4)
    two = (np.array([Tcbin16ToInt(i[14]) for i in lst],dtype = np.int16)*2)
    one = (np.array([Tcbin16ToInt(i[15]) for i in lst],dtype = np.int16)*1)
    return sixteen,fiveteen,fourteen,thirteen,twelve,eleven,ten,nine,eight,seven,six,five,four,three,two,one

这是分解前的信号图:

例如,这是分解后的第 16 位平面信号图:

我做错了什么?如何做对?以及如何重新组合?

【问题讨论】:

    标签: python binary integer signal-processing signed


    【解决方案1】:

    sixteen 行中,将 32768 更改为 -32768。其他一切看起来都不错。

    就像你说的那样,现有bitplanedecomposesignal() 代码的平面将值重构为无符号的 16 位数据而不是有符号的数据。但是,如果最高有效位打开,则表示值为负,我们应该从无符号值中减去 2^16 = 65536。所以最重要的位应该贡献 32768 - 65536 = -32768 而不是 +32768。

    例子:

    value = −32700 decimal
          = 1000000001000100 binary int16
            ↑        ↑   ↑
           −2^15   2^6   2^2
    
           −2^15 + 2^6 + 2^2 = −32700 decimal = value
    

    旁注:Numpy 具有高效的按位函数,您可能会发现它们很有用。我会考虑使用np.bitwise_and 来提取位平面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多