You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FSK解调后无法获取正确二进制序列的问题求助

FSK解调后无法获取正确二进制序列的问题求助

我现在在处理一个文件中特定信号的FSK解调任务,步骤是读取文件、过滤出目标信号,然后进行解调。目前我能确定的是:

  • 所有FSK解调参数都是正确的(这个信号我用其他程序测试过,解调完全正常)
  • 滤波器工作正常(单独导出滤波后的目标信号是正确的)

但现在遇到了棘手的问题:解调出的二进制序列完全不对,不仅长度比预期的长,内容也和预期不符。

以下是我的完整代码,恳请各位帮忙排查问题所在:

import numpy as np
from scipy.signal import butter, filtfilt, resample_poly
from tkinter import filedialog
import math

lowcut, highcut = 1452550, 1498792 # F_min and F_max (position of my target signal in the file)

# Demodulation FSK
def demodulation_fsk(data, frequencies, fs):
    t = np.linspace(0, len(data)/fs, len(data), endpoint=False)
    demodulated_signals = np.zeros((len(frequencies), len(data)))
    for i, freq in enumerate(frequencies):
        fsk_signal = data * np.exp(-1.j * 2 * np.pi * freq * t)
        demodulated_signal = np.abs(np.fft.fft(fsk_signal))
        demodulated_signals[i, :] = demodulated_signal
    demodulated = np.argmax(demodulated_signals, axis=0)
    return demodulated

# Get binary train
def recup_TB(demod, niveau_FSK):
    num_bits = int(math.log2(niveau_FSK))
    bit_string = "".join(format(x, f'0{num_bits}b') for x in demod) # FSK2 (1 bit) : 0 or 1, FSK4 (2 bits) : 00, 01 , 10 or 11, FSK8 (3 bits) : 000, 001, 010, 100, ...
    return bit_string

filename = filedialog.askopenfilename(title="Selection d'un fichier IQ")
if filename != "":
    data = np.fromfile(filename, dtype=np.int16).astype(np.float32).view(np.complex64) # opening the file, visualisation of the data in complex64

    # Filter on my target signal in the file
    freq_echan = 15625000 # my default sampling frequency (from my original file)
    order = 1
    fcenter = (highcut + lowcut) / 2
    largeur = (highcut - lowcut) / 2
    t = np.arange(len(data)) / freq_echan
    iq_shifted = data * np.exp(-1.j * 2 * np.pi * fcenter * t)
    b, a = butter(order, largeur / (freq_echan / 2), btype="low")
    y = filtfilt(b, a, iq_shifted)
    common = math.gcd(int(freq_echan), int(2 * largeur))
    up = int(2 * largeur // common)
    down = int(freq_echan // common)
    data = resample_poly(y, up, down)

    # Parameters
    fc = (highcut + lowcut) / 2 # center of my signal
    fs = int(highcut - lowcut) # Use bandwith as new sampling frequency
    rapidite_modulation = 19000 # in Bauds (Bd)
    symbol_duration = 1 / rapidite_modulation
    samples_per_symbol = int(symbol_duration * fc)
    shift = 10000 # in Hz
    niveau_FSK = 2
    if niveau_FSK == 2:
        frequencies = [fc - (shift / 2), fc + (shift / 2)]
    if niveau_FSK == 4:
        frequencies = [fc - (2 * shift / 2), fc - (shift / 2), fc + (shift / 2), fc + (2 * shift / 2)]
    if niveau_FSK == 8:
        frequencies = [fc - (4 * shift / 2), fc - (3 * shift / 2), fc - (2 * shift / 2), fc - (shift / 2), fc + (shift / 2), fc + (2 * shift / 2), fc + (3 * shift / 2), fc + (4 * shift / 2)]
    if niveau_FSK == 16:
        frequencies = [fc - (8 * shift / 2), fc - (7 * shift / 2), fc - (6 * shift / 2), fc - (5 * shift / 2), fc - (4 * shift / 2), fc - (3 * shift / 2), fc - (2 * shift / 2), fc - (shift / 2), fc + (shift / 2), fc + (2 * shift / 2), fc + (3 * shift / 2), fc + (4 * shift / 2), fc + (5 * shift / 2), fc + (6 * shift / 2), fc + (7 * shift / 2), fc + (8 * shift / 2)]
 
    demod = demodulation_fsk(data, frequencies, fs)
    TB = recup_TB(demod, niveau_FSK)
    print(TB)

备注:内容来源于stack exchange,提问作者Bast38

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 13:48:01