mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-04 14:07:30 +00:00
Bugfixes and improvements for new hardware
This commit is contained in:
parent
7d9d5e27eb
commit
4cbd60e62d
33 changed files with 747 additions and 193 deletions
46
FPGA/WindowCoefficientGenerator.py
Normal file
46
FPGA/WindowCoefficientGenerator.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import math
|
||||
|
||||
# Adapt these constants to your window requirements
|
||||
NUMBER_OF_COEFFICIENTS = 128
|
||||
BITS_PER_COEFFICIENT = 16
|
||||
|
||||
# If set to true, the coefficients will be scaled to include the window amplitude correction factor.
|
||||
# They will also be scaled to 1/8 to have enough headroom for the correction.
|
||||
INCLUDE_AMPLITUDE_CORRECTION = True
|
||||
|
||||
# Don't change anything below this line
|
||||
|
||||
class Window:
|
||||
def __init__(self, name, function, correction):
|
||||
self.name = name
|
||||
self.function = function
|
||||
self.correction = correction
|
||||
|
||||
def StartFile(self):
|
||||
self.file = open(self.name+".txt", "w")
|
||||
|
||||
def AddCoefficient(self, normalized_index):
|
||||
if not hasattr(self, 'file'):
|
||||
self.StartFile()
|
||||
value = self.function(normalized_index)
|
||||
if INCLUDE_AMPLITUDE_CORRECTION:
|
||||
value = value * self.correction / 8.0
|
||||
value = int(value * (2 ** (BITS_PER_COEFFICIENT-1)))
|
||||
# prevent overflow
|
||||
if value >= (2 ** (BITS_PER_COEFFICIENT-1)):
|
||||
value = value - 1
|
||||
output = "{0:b}".format(value)
|
||||
self.file.write(output.zfill(BITS_PER_COEFFICIENT)+"\n")
|
||||
|
||||
def calc_hann(i):
|
||||
return math.sin(math.pi * i) ** 2
|
||||
|
||||
WindowList = []
|
||||
WindowList.append(Window("Hann", calc_hann, 2.0))
|
||||
|
||||
for i in range(NUMBER_OF_COEFFICIENTS):
|
||||
norm_i = (i+0.5) / NUMBER_OF_COEFFICIENTS
|
||||
for w in WindowList:
|
||||
w.AddCoefficient(norm_i)
|
||||
Loading…
Add table
Add a link
Reference in a new issue