Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 16位二'的位平面分解;s补码有符号整数信号数据?_Python_Binary_Integer_Signal Processing_Signed - Fatal编程技术网

Python 16位二'的位平面分解;s补码有符号整数信号数据?

Python 16位二'的位平面分解;s补码有符号整数信号数据?,python,binary,integer,signal-processing,signed,Python,Binary,Integer,Signal Processing,Signed,我试图用python对16位2的补码有符号整数信号数据(心电图)进行位平面分解,所以我将得到16位信号数据位平面。我知道如何分解8位无符号整数图像信号,我重新实现了这个问题中的代码。我以为我应该得到位平面数据,其值包含负数,因为它最初是一个16位有符号整数,但我得到的是16位无符号整数信号,而不是16位有符号整数信号。 这是我的密码: import numpy as np def intToTcbin16(value): return format(value % (1 <<

我试图用python对16位2的补码有符号整数信号数据(心电图)进行位平面分解,所以我将得到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
将numpy导入为np
def intToTcbin16(值):

返回格式(值%(1在
十六
行中,将32768更改为-32768。其他一切看起来都正常

正如您所说,现有
位平面decomposeSignal()的平面
code将值重建为无符号16位数据,而不是有符号数据。但是,如果最高有效位为on,则表示的值为负值,我们应该从无符号值中减去2^16=65536。因此,最高有效位应贡献32768-65536=-32768,而不是+32768

例如:

值=−32700十进制
=10000000000000100二进制int16
↑        ↑   ↑
−2^15   2^6   2^2
−2^15 + 2^6 + 2^2 = −32700十进制=数值

侧注释:Numpy有很好的有效位函数,您可能会发现它有用。我会考虑用以提取位平面。

< P>在<代码>十六/代码>行中,将32768改为-32768。其他任何东西看起来都是正确的。

正如您所说,现有
位平面decomposeSignal()的平面
code将值重建为无符号16位数据,而不是有符号数据。但是,如果最高有效位为on,则表示的值为负值,我们应该从无符号值中减去2^16=65536。因此,最高有效位应贡献32768-65536=-32768,而不是+32768

例如:

值=−32700十进制
=10000000000000100二进制int16
↑        ↑   ↑
−2^15   2^6   2^2
−2^15 + 2^6 + 2^2 = −32700十进制=数值

侧注释:Numpy有很好的有效位函数,您可能会发现它有用。我会考虑使用来提取位平面。