import math import io, os import matplotlib.pyplot as plt sample_rate = 9500 # next 2 funcs are modified from ChristopheJacquet's pydemod def rrcosfilter(NumSamples): T_delta = 1/float(sample_rate) sample_num = list(range(NumSamples)) h_rrc = [0.0] * NumSamples SymbolPeriod = 1/(2*1187.5) for x in sample_num: t = (x-NumSamples/2)*T_delta if t == 0.0: h_rrc[x] = 1.0 - 1 + (4/math.pi) elif t == SymbolPeriod/4: h_rrc[x] = (1/math.sqrt(2))*(((1+2/math.pi)* \ (math.sin(math.pi/4))) + ((1-2/math.pi)*(math.cos(math.pi/4)))) elif t == -SymbolPeriod/4: h_rrc[x] = (1/math.sqrt(2))*(((1+2/math.pi)* \ (math.sin(math.pi/4))) + ((1-2/math.pi)*(math.cos(math.pi/4)))) else: h_rrc[x] = (4*(t/SymbolPeriod)*math.cos(math.pi*t*2/SymbolPeriod))/ \ (math.pi*t*(1-(4*t/SymbolPeriod)*(4*t/SymbolPeriod))/SymbolPeriod) return h_rrc def convolve(a, b): out = [0] * (len(a) + len(b) - 1) for i in range(len(a)): for j in range(len(b)): out[i+j] += a[i] * b[j] return out PATH = os.path.dirname(os.path.abspath(__file__)) outc = io.open(f"{PATH}/src/waveforms.c", mode="w", encoding="utf8") outh = io.open(f"{PATH}/src/waveforms.h", mode="w", encoding="utf8") header = u""" /* This file was automatically generated by "gen_wave.py". (C) 2014 Christophe Jacquet. (C) 2023 Anthony96922. (C) 2025 kuba201. Released under the GNU GPL v3 license. */ """ outc.write(header) outh.write(header) def generate(): offset = int(sample_rate*0.004) # 190 khz = 760 count = int(offset / 10**(len(str(offset)) - 1)) # 760 / 100 = 7 l = int(sample_rate / 1187.5) // 2 # 16/2 = 8 if l == 1: raise Exception("Sample rate too small") print(f"{offset=} {count=} {l=}") sample = [0.0] * (count*l) sample[l] = 1 sample[2*l] = -1 # Apply the data-shaping filter sf = rrcosfilter(l*16) shapedSamples = convolve(sample, sf) # Slice the array like numpy would out = shapedSamples[offset-l*count:offset+l*count] plt.plot(sf, label="sf") plt.plot(shapedSamples, label="shapedSamples") plt.plot(out, label="out") plt.legend() plt.grid(True) plt.show() outc.write(u"float waveform_biphase[{size}] = {{{values}}};\n\n".format( values = u", ".join(map(str, [val / 2.5 for val in out])), size = len(out))) # note: need to limit the amplitude so as not to saturate when the biphase # waveforms are summed outh.write(u"extern float waveform_biphase[{size}];\n".format(size=len(out))) generate() outc.close() outh.close()