mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-27 04:43:52 +01:00
set the sample rate to ratio 10
This commit is contained in:
13
gen_wave.py
13
gen_wave.py
@@ -6,7 +6,7 @@ import io, os
|
||||
if PLOT: import matplotlib.pyplot as plt
|
||||
if FFT: import numpy as np # Import numpy for FFT
|
||||
|
||||
sample_rate = 9500
|
||||
sample_rate = 11875
|
||||
|
||||
# this is modified from ChristopheJacquet's pydemod
|
||||
def rrcosfilter(NumSamples):
|
||||
@@ -57,9 +57,9 @@ 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
|
||||
offset = int(sample_rate*0.004)
|
||||
count = int(offset / 10**(len(str(offset)) - 1))
|
||||
l = int(sample_rate / 1187.5) // 2
|
||||
if count*l > l*16: raise Exception("Sample rate too small")
|
||||
print(f"{offset=} {count=} {l=}")
|
||||
|
||||
@@ -67,13 +67,11 @@ def generate():
|
||||
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]
|
||||
out = [i/(max(out)) for i in out]
|
||||
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")
|
||||
|
||||
if PLOT:
|
||||
@@ -92,6 +90,7 @@ def generate():
|
||||
# Plot the magnitude of the FFT
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(fft_freqs[:N//2], np.abs(fft_out)[:N//2]) # Plot only the positive frequencies
|
||||
plt.xlim(0,1187.5*3)
|
||||
plt.title("FFT of the waveform")
|
||||
plt.xlabel("Frequency (Hz)")
|
||||
plt.ylabel("Magnitude")
|
||||
|
||||
Reference in New Issue
Block a user