FSK (带算法 pyhackrf 发送)

发布时间:2024年01月13日
import numpy as np
import pyhackrf2 as pyhackrf
import threading

bits =[1, 0, 1, 0, 1, 1, 0, 0, 0, 1]

def bit_array_to_number(bits,end,start=0):
    if end < 1:
        return 0
    acc = 1
    ret =0
    for i in range(start,end):
        ret += bits[end-1-i]*acc
        acc *= 2
    return ret


def fsk_mod(fw):
    i = 0
    i_p = 0
    f = 0
    f_p = 0
    pc = np.zeros((100000))
    i = bit_array_to_number(bits,i*2,i*2)
    i_p = bit_array_to_number(bits,i*2,(i-1)*2)
    
    f = fw[i]
    f_p = fw[i_p]

    if f != f_p:
        t = ( i * 100 + 0 - 1 ) / 1e6
        pc[i] = (pc[i-1] + 2 * np.pi * (f_p - f) * t) / (2 * np.pi)
    else:
        pc[i] = pc[i-1]
    return pc



fw = [-20e3, -10e3, 10e3, 20e3]

data = np.zeros((100000))
data = fsk_mod(fw)
data = np.array(data).astype(np.int8).tobytes()

class hackrf_threading(threading.Thread):
    def __init__(self):
        self.hackrf = pyhackrf.HackRF()
        self.hackrf.center_freq = 433.92e6
        self.hackrf.lna_gain = 40
        self.hackrf.txvga_gain = 47
        self.hackrf.filter_bandwidth = self.hackrf.set_bw(1000000)
        self.hackrf.buffer = bytearray(data)

    def run(self):
        self.hackrf.start_tx()


h = hackrf_threading()
h.run()

文章来源:https://blog.csdn.net/nn_84/article/details/135566354
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。