Commit 5eddb20b authored by Benedikt Seeger's avatar Benedikt Seeger
Browse files

Merge branch 'master' into bene_master

parents e4cb3bb7 b86baa50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 22 17:15:45 2020
@author: bruns01
"""
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider, TextInput,Div
from bokeh.plotting import figure
from primes import primes
# Set up callbacks
def update_data(attrname, old, new):
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = primes[new]
# pri = primes[(primes<=10*p0) & (primes>p0)]
pri = primes[(primes<=10*p0)]
d = []
p = []
for fs in f_std:
try:
pr1 = (pri[pri/p0<=fs])[-1] # lower limit prime
f1 = pr1/p0 # lower limit frequency
r1 = (f1-fs)/fs
except:
r1 = 0.5
pr2 = (pri[pri/p0>fs])[0] # upper limit prime
f2 = pr2/p0 # upper limit frequency
r2 = (f2-fs)/fs
r = r1 if (np.abs(r1)<np.abs(r2)) else r2
d.append(r)
p.append((pr1 if (np.abs(r1)<np.abs(r2)) else pr2))
#print( f1 if (np.abs(r1)<np.abs(r2)) else f2)
#print( ("%d/%d" % (pr1,p0)) if (np.abs(r1)<np.abs(r2)) else ("%d/%d" % (pr2,p0)))
source.data = dict(x=f_std,y=np.array(d))
base.value = """Base = %d """ % p0
deviation.text = str(np.amax(np.abs(d))) # display maximum deviation
dd = 100*np.amax(np.abs(np.array(d)))
print("%2.2f %%" % dd)
print(p)
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = 7
base = TextInput(value="""Base = xx""")
deviation = Div(text="max")
# Set up plot
source = ColumnDataSource(data=dict(x=[], y=[]))
update_data("offset",0,5)
plot = figure(plot_height=400, plot_width=800, title="prime ratio frequencies",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[1.0, 10.0], y_range=[-0.1, 0.2])
plot.circle('x', 'y', source=source, radius=.05)
# Set up widgets
offset = Slider(title="offset", value=5, start=0, end=50, step=1)
offset.on_change('value', update_data)
# Set up layouts and add to document
inputs = row(offset, base, deviation)
curdoc().add_root(column(inputs, plot, width=800))
curdoc().title = "Sliders"
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 12 18:16:02 2020
@author: bruns01
Sequentieller Multisinusfit mit einer
schwachbesetzten Designmatrix
"""
import numpy as np
from scipy.sparse import coo_matrix
from scipy.sparse.linalg import lsqr
import matplotlib.pyplot as mp
from datetime import datetime
import SineTools as st
from primes import primes
f0 = 0.1
Np0 = 7.0
primes = np.array([7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, ])
primes = primes[1::2]
f = f0 * primes/Np0
T = 3*Np0 /f0
f_max = np.amax(f)
t = st.sampletimes(200,T)
p = 45.0+180.0*np.array([i for i in range(len(f))])
m = [1.0]*len(f)
y = st.multi_waveform_mp(f,m,p,t)+.3 + 0.5*(np.random.rand((len(t)))-0.5)
mp.plot(y,lw=3)
mp.show()
start = datetime.now()
for i in range(1):
print(i)
abc = st.seq_multi_threeparsinefit(f,y,t,periods=5)
end = datetime.now()
print("Delta=" + str((end-start)))
#print(st.seq_multi_amplitude(abc[0]))
mag = st.seq_multi_amplitude(abc[0])
print(np.mean(mag[:,1]))
print(np.sqrt(np.var(mag[:,1])))
mp.figure(1)
mp.clf()
mp.plot(y,".",ms=1)
mp.plot(abc[1],lw=1)
mp.show()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment