diff --git a/.vscode/.server-controller-port.log b/.vscode/.server-controller-port.log index 23786b3..46f44c9 100644 --- a/.vscode/.server-controller-port.log +++ b/.vscode/.server-controller-port.log @@ -1,5 +1,5 @@ { "port": 13452, - "time": 1745432304494, + "time": 1745844256741, "version": "0.0.3" } \ No newline at end of file diff --git a/gen_wave.py b/gen_wave.py index 54087ad..e1219e6e 100644 --- a/gen_wave.py +++ b/gen_wave.py @@ -7,7 +7,7 @@ if PLOT: import matplotlib.pyplot as plt if FFT: import numpy as np DATA_RATE = 1187.5 -SIZE_RATIO = 2 +SIZE_RATIO = 1 ratio = 16 sample_rate = DATA_RATE*ratio @@ -23,17 +23,12 @@ def rrcosfilter(NumSamples): 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) + 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) + blackman = [0.42 + 0.5*math.cos(math.pi*i/(NumSamples-1)) + 0.08*math.cos(2.0*math.pi*i/(NumSamples-1)) for i in range(NumSamples)] + h_rrc = [h_rrc[i] * blackman[i] for i in range(NumSamples)] return h_rrc @@ -63,36 +58,14 @@ outc.write(header) outh.write(header) def generate(): - l = ratio // 2 - - sample = [0.0] * (16*l) - sample[l] = 1 - sample[2*l] = -1 - - sf = rrcosfilter(l*16) - shapedSamples = convolve(sample, sf) - - lowest = 0 - lowest_idx = 0 - highest = 0 - highest_idx = 0 - for i,j in enumerate(shapedSamples): - if j < lowest: - lowest = j - lowest_idx = i - if j > highest: - highest = j - highest_idx = i - middle = int((lowest_idx+highest_idx)/2) - - out = shapedSamples[middle-int(ratio*SIZE_RATIO):middle+int(ratio*SIZE_RATIO)] - out = [2 * (i - min(out)) / (max(out) - min(out)) - 1 for i in out] - if max(out) > 1 or min(out) < -1: raise Exception("Clipped") - print(f"{len(out)=} {len(out)/sample_rate=} {(len(out)/sample_rate)/(1/DATA_RATE)=} {1/DATA_RATE=}") + t = [i / sample_rate for i in range(ratio)] + out = [math.sin(2 * math.pi * DATA_RATE * time) for time in t] + print(f"{len(out)=} {len(out)/sample_rate=} {1/DATA_RATE=}") if PLOT: - plt.plot(out, label="out") + plt.plot(out*4, label="out") plt.legend() + plt.axvline(x=len(out)*2, color='r', linestyle='--', label='center') plt.grid(True) plt.show() @@ -103,7 +76,7 @@ def generate(): plt.figure(figsize=(10, 6)) plt.plot(fft_freqs[:N//2], np.abs(fft_out)[:N//2]) - plt.xlim(0,DATA_RATE*3) + plt.xlim(0,DATA_RATE*2.5) plt.title("FFT of the waveform") plt.xlabel("Frequency (Hz)") plt.ylabel("Magnitude") diff --git a/src/rds.h b/src/rds.h index 049dee8..41dac6d 100644 --- a/src/rds.h +++ b/src/rds.h @@ -12,7 +12,7 @@ #define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE + POLY_DEG)) #define RDS_SAMPLE_RATE 19000 #define SAMPLES_PER_BIT 16 -#define FILTER_SIZE 64 +#define FILTER_SIZE 16 #define SAMPLE_BUFFER_SIZE (SAMPLES_PER_BIT + FILTER_SIZE) #define STREAMS 2 diff --git a/src/waveforms.c b/src/waveforms.c index e012269..a1fdf2e 100644 --- a/src/waveforms.c +++ b/src/waveforms.c @@ -6,5 +6,5 @@ Released under the GNU GPL v3 license. */ -float waveform_biphase[64] = {0.001905215527506554, 0.0014857449947831558, 0.0, -0.0018260510389287443, -0.002879473467708782, -0.0022799681256350235, 0.0, 0.0028998088186253934, 0.004662004662004504, 0.003770143371148116, 0.0, -0.005034068109133871, -0.008325008325008265, -0.006947655510042394, 0.0, 0.01000275871035683, 0.017316017316017396, 0.015236086644829783, 0.0, -0.025132981969720025, -0.04761904761904756, -0.046927146866075575, 0.0, 0.11019845940569595, 0.2857142857142856, 0.5076664070057264, 0.7363107781851077, 0.9183204950474642, 1.0, 0.9428090415820631, 0.7363107781851077, 0.4040610178208841, 0.0, -0.4040610178208842, -0.7363107781851077, -0.9428090415820631, -1.0, -0.918320495047464, -0.7363107781851077, -0.5076664070057264, -0.2857142857142857, -0.11019845940569584, 0.0, 0.046927146866075464, 0.04761904761904745, 0.025132981969720136, 0.0, -0.015236086644829672, -0.017316017316017285, -0.010002758710356718, 0.0, 0.006947655510042505, 0.008325008325008376, 0.005034068109133871, 0.0, -0.003770143371148116, -0.004662004662004615, -0.0028998088186253934, 0.0, 0.0022799681256351345, 0.002879473467708893, 0.0018260510389287443, 0.0, -0.0014857449947831558}; +float waveform_biphase[16] = {0.0, 0.3826834323650898, 0.7071067811865475, 0.9238795325112867, 1.0, 0.9238795325112867, 0.7071067811865476, 0.3826834323650899, 1.2246467991473532e-16, -0.3826834323650892, -0.7071067811865475, -0.9238795325112868, -1.0, -0.923879532511287, -0.7071067811865477, -0.3826834323650904}; diff --git a/src/waveforms.h b/src/waveforms.h index 227c793..930ee51 100644 --- a/src/waveforms.h +++ b/src/waveforms.h @@ -6,4 +6,4 @@ Released under the GNU GPL v3 license. */ -extern float waveform_biphase[64]; +extern float waveform_biphase[16];