Simple Xpressive function Generator in Python.
Not an expert in Xpressive but I like to generate random stuff. So I have wrote a small python script where a formula can be set and outputs a function that can be used in Xpressive as expression on O1.
Code: Select all
import numpy as np
import cmath
import math
import random
print(f"{'Freq (Hz)':<42} | {'Cosine Component Formula':<45} | {'Sine Component Formula':<15}")
print("-" * 90)
t = 0.5
x = ""
for k in range(1, 10):
if(k>random.randint(2, 5)):
break
eval = ['sin','sinew', 'trianglew', 'squarew', 'saww']
#'abs', 'sin', 'cos', 'tan', 'cot', 'asin', 'acos', 'atan', 'atan2', 'sinh',
#'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'sinc', 'hypot',
#'exp', 'log', 'log2', 'log10', 'logn', 'pow', 'sqrt', 'min', 'max', 'floor', 'ceil',
#'round', 'trunc', 'frac', 'avg', 'sgn', 'mod']
# Filter out negligible ambient noise or silence
if k:
randnum = random.randint(1, 9);
randomunicos = random.uniform(0.5, 7.5)
randomunisin = random.uniform(0.5, 7.5)
randomfreq = random.randint(41, 227)
#round(random.uniform(33.33, 66.66), 2)
#x = x + f"{eval[random.randint(0, 5)]}(t * {randomfreq} * exp(-t * .1)) * exp(-t * .{randnum})"
x = x + f"{eval[random.randint(0, 4)]} (t * {randomfreq} * exp(-t * .{randnum}) ) "
print(f"{randomfreq:<42.1f} | {randomunicos:<45} | {randomunisin:<15}")
print("-" * 90)
print(x)Output Example
Code: Select all
Freq (Hz) | Cosine Component Formula | Sine Component Formula
------------------------------------------------------------------------------------------
223.0 | 1.6458303668121976 | 3.3729510793230104
86.0 | 5.191355095525813 | 0.5670091219740144
172.0 | 5.934424313930378 | 2.9379080980547427
------------------------------------------------------------------------------------------
sin (t * 223 * exp(-t * .7) ) sinew (t * 86 * exp(-t * .7) ) saww (t * 172 * exp(-t * .7) )
Random Generated Expressions Examples
Code: Select all
Example 1:
sin (t * 223 * exp(-t * .7) ) sinew (t * 86 * exp(-t * .7) ) saww (t * 172 * exp(-t * .7) )
Example 2:
sinew (t * 194 * exp(-t * .6) ) sinew (t * 108 * exp(-t * .8) ) sinew (t * 42 * exp(-t * .2) ) squarew (t * 1630 * exp(-t * .2) )
Example 3:
sin (t * 1785 * exp(-t * .9) ) sin (t * 556 * exp(-t * .7) ) sin (t * 200 * exp(-t * .5) ) sin (t * 201 * exp(-t * .2) ) sin (t * 60 * exp(-t * .8) )