0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00

add fft to the genwave

This commit is contained in:
2025-03-11 20:56:33 +01:00
parent ca749bd1ad
commit c65a69a328

View File

@@ -1,6 +1,10 @@
PLOT = True
FFT = PLOT and True
import math
import io, os
import matplotlib.pyplot as plt
if PLOT: import matplotlib.pyplot as plt
if FFT: import numpy as np # Import numpy for FFT
sample_rate = 9500
@@ -72,22 +76,34 @@ def generate():
out = [i/(max(sf)+0.1) for i in out]
if max(out) > 1 or min(out) < -1: print("clipped")
# plt.plot(sf, label="sf")
# plt.plot(shapedSamples, label="shapedSamples")
plt.plot(out, label="out")
plt.legend()
plt.grid(True)
plt.show()
if PLOT:
# Plot the waveform
plt.plot(out, label="out")
plt.legend()
plt.grid(True)
plt.show()
if FFT:
# Compute the FFT of the waveform
N = len(out)
fft_out = np.fft.fft(out)
fft_freqs = np.fft.fftfreq(N, d=1/sample_rate)
# 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.title("FFT of the waveform")
plt.xlabel("Frequency (Hz)")
plt.ylabel("Magnitude")
plt.grid(True)
plt.show()
outc.write(u"float waveform_biphase[{size}] = {{{values}}};\n\n".format(
values = u", ".join(map(str, 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()