Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config free update #37

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bindings/c/include/cgenalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#ifndef CGENALYZER_H
#define CGENALYZER_H
#include "cgenalyzer_advanced.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down
14 changes: 6 additions & 8 deletions bindings/c/src/cgenalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
extern "C" {
int gn_config_free(gn_config *c)
{
if (!((*c)->obj_key))
if ((*c)->obj_key){
gn_mgr_remove((*c)->obj_key);
free((*c)->obj_key);
if (!((*c)->comp_key))
}
if ((*c)->comp_key){
gn_fa_remove_comp((*c)->obj_key, (*c)->comp_key);
free((*c)->comp_key);
if (!((*c)->tone_freq))
free((*c)->tone_freq);
if (!((*c)->tone_ampl))
free((*c)->tone_ampl);
if (!((*c)->tone_phase))
free((*c)->tone_phase);
}
if (((*c)->_fa_results_size) > 0)
{
for (size_t i = 0; i < (*c)->_fa_results_size; i++)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/examples/do_fourier_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c)
fft_out = [val for pair in zip(fft_out_i, fft_out_q) for val in pair]
genalyzer.config_set_sample_rate(data["fs"], c)
genalyzer.config_fa(freq_list[0], c)
all_results = genalyzer.get_fa_results(fft_out, c)
pprint.pprint(all_results)
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/do_fourier_analysis_pluto_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
genalyzer.config_set_sample_rate(data["fs"], c)

# Find tones
genalyzer.gn_config_fa_auto(ssb_width=120, c=c)
genalyzer.config_fa_auto(ssb_width=120, c=c)

# compute FFT
fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c)
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/real_analysis_advanced.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def main():
import genalyzer_advanced as gn
import genalyzer.advanced as gn

# print("Library path: {}".format(gn._genalyzer._libpath))
# print("Version: {}\n".format(gn.__version__))
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/genalyzer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
config_histz_nla,
config_fftz,
config_fa,
gn_config_fa_auto,
config_fa_auto,
gen_ramp,
gen_real_tone,
gen_complex_tone,
Expand Down
75 changes: 40 additions & 35 deletions bindings/python/genalyzer/simplified.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,22 +464,23 @@ def config_free(
_gn_config_free(byref(c._struct))


def config_gen_ramp(npts: int, ramp_start: int, ramp_stop: int, *args) -> GNConfig:
def config_gen_ramp(npts: int, ramp_start: int, ramp_stop: int, c: GNConfig = None) -> GNConfig:
"""Configure GNConfig struct to generate tone.
:param npts: number of sample points in the waveform
:param ramp_start: Input start value of ramp
:param ramp_stop: Input stop value of ramp
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]

npts = c_ulong(npts)
ramp_start = c_ulong(ramp_start)
ramp_stop = c_ulong(ramp_stop)

_gn_config_gen_ramp(npts, ramp_start, ramp_stop, byref(c._struct))
ret = _gn_config_gen_ramp(npts, ramp_start, ramp_stop, byref(c._struct))
if ret != 0:
raise Exception("config_gen_ramp failed")
return c


Expand All @@ -491,7 +492,7 @@ def config_gen_tone(
tone_freq: float,
tone_ampl: float,
tone_phase: float,
*args
c: GNConfig = None
) -> GNConfig:
"""Configure GNConfig struct to generate tone.
:param ttype: tone type
Expand All @@ -503,10 +504,9 @@ def config_gen_tone(
:param tone_phase: tone phase
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]

ttype = c_uint(ttype)
npts = c_ulong(npts)
sample_rate = c_double(sample_rate)
Expand All @@ -516,7 +516,7 @@ def config_gen_tone(
tone_ampl = (double_array)(*tone_ampl)
tone_phase = (double_array)(*tone_phase)

_gn_config_gen_tone(
ret = _gn_config_gen_tone(
ttype,
npts,
sample_rate,
Expand All @@ -526,53 +526,55 @@ def config_gen_tone(
tone_phase,
byref(c._struct),
)
if ret != 0:
raise Exception("config_gen_tone failed")
return c


def config_quantize(npts: int, fsr: float, qres: int, qnoise: float, *args) -> GNConfig:
def config_quantize(npts: int, fsr: float, qres: int, qnoise: float, c: GNConfig = None) -> GNConfig:
"""Configure GNConfig struct to perform quantization.
:param npts: number of sample points in the waveform
:param fsr: full-scale range
:param qres: quantization resolution
:param qnoise: quantization noise
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]


npts = c_ulong(npts)
fsr = c_double(fsr)
qres = c_int(qres)
qnoise = c_double(qnoise)

_gn_config_quantize(npts, fsr, qres, qnoise, byref(c._struct))
ret = _gn_config_quantize(npts, fsr, qres, qnoise, byref(c._struct))
if ret != 0:
raise Exception("config quantize failed")
return c


def config_histz_nla(npts: int, qres: int, *args) -> GNConfig:
def config_histz_nla(npts: int, qres: int, c: GNConfig = None) -> GNConfig:
"""Configure GNConfig struct to compute histogram or perform non-linearity analysis.
:param npts: number of sample points in the waveform
:param fsr: full-scale range
:param qres: quantization resolution
:param qnoise: quantization noise
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]


npts = c_ulong(npts)
qres = c_int(qres)

_gn_config_histz_nla(npts, qres, byref(c._struct))
ret = _gn_config_histz_nla(npts, qres, byref(c._struct))
if ret != 0:
raise Exception("config_histz_nla failed")
return c


def config_fftz(
npts: int, qres: int, navg: int, nfft: int, win: int, *args
npts: int, qres: int, navg: int, nfft: int, win: int, c: GNConfig = None
) -> GNConfig:
"""Configure GNConfig struct to compute FFT.
:param npts: number of sample points in the waveform
Expand All @@ -581,48 +583,51 @@ def config_fftz(
:param qnoise: quantization noise
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]


npts = c_ulong(npts)
qres = c_int(qres)
navg = c_ulong(navg)
nfft = c_ulong(nfft)
win = c_uint(win)

_gn_config_fftz(npts, qres, navg, nfft, win, byref(c._struct))
ret = _gn_config_fftz(npts, qres, navg, nfft, win, byref(c._struct))
if ret != 0:
raise Exception("config_fftz failed")
return c


def config_fa(fixed_tone_freq: float, *args) -> GNConfig:
def config_fa(fixed_tone_freq: float, c: GNConfig = None) -> GNConfig:
"""Configure GNConfig struct for Fourier analysis.
:param fixed_tone_freq: fixed tone frequency
:return: GNConfig object
"""
if len(args) == 0:
if c is None:
c = GNConfig()
elif len(args) == 1:
c = args[0]

fixed_tone_freq = c_double(fixed_tone_freq)

_gn_config_fa(fixed_tone_freq, byref(c._struct))
ret = _gn_config_fa(fixed_tone_freq, byref(c._struct))
if ret != 0:
raise Exception("config_fa failed")
return c


def gn_config_fa_auto(ssb_width: int, c: GNConfig):
def config_fa_auto(ssb_width: int, c: GNConfig = None):
"""Configure GNConfig struct for Fourier analysis where tones are
automatically found.
:param ssb_width: SSB width
:param c: GNConfig object
"""
if c is None:
c = GNConfig()
ssb_width = c_uint8(ssb_width)

ret = _gn_config_fa_auto(ssb_width, byref(c._struct))
if ret != 0:
raise Exception("gn_config_fa_auto failed")
raise Exception("config_fa_auto failed")
return c


def gen_ramp(c: GNConfig) -> List[float]:
Expand Down
Loading