Esempio n. 1
0
def setSpectrum(settings):
    """Initialize spectrum calculation"""
    fft_settings.update(settings)
    sp = []
    for _ in range(ntracks):
        sp.append(spectral(**fft_settings))
    return sp
Esempio n. 2
0
def setSpectrum(new_settings):
    """Initialize spectrum calculation"""
    global fft_settings
    fft_settings.update(new_settings)
    #remove unrequired keys
    fft_settings = filterDictByKeysSet(
        fft_settings,
        inspect.signature(spectral).parameters)  #keep required parameters
    sp = []
    for _ in range(ntracks):
        sp.append(spectral(**fft_settings))
    return sp
Esempio n. 3
0
def setSpectrum(new_settings):
    """Initialize spectrum calculation"""
    global new_fft_settings
    fft_settings_ = copy.deepcopy(fft_settings)
    fft_settings_.update(new_settings)
    # remove unrequired keys
    fft_settings_ = filterDictByKeysSet(fft_settings_, inspect.signature(
        spectral).parameters)  # keep required parameters
    print("fft_settings_", fft_settings_)
#    import pdb; pdb.set_trace()
    new_fft_settings = fft_settings_
    sp = []
    for _ in range(ntracks):
        sp.append(spectral(**fft_settings_))
    return sp
Esempio n. 4
0
def window_demo(data, fft_settings):
    """Plot window shape, adds up to 5 plots. Returns base64 png image"""
    global ax
    fft_settings_ = copy.deepcopy(fft_settings)
    new_fft_settings = dictKeysStrrep(data["FFTsettings"], "fft-")
    winParam_ = filterDictByKeyStr(new_fft_settings, "window-")
    winParam_ = dictKeysStrrep(winParam_, "window-")
    fft_settings_.update(new_fft_settings)
    fft_settings_["winParam"].update(
        winParam_)  #update initial window parameters with new
    #keep required parameters
    fft_settings_ = filterDictByKeysSet(fft_settings_,
                                        inspect.signature(spectral).parameters)
    sp = spectral(**fft_settings_)
    w1 = sp.w

    if not ax:
        _, ax = plt.subplots()

    if len(lines) >= 5:  #limit to 5 curves
        lines.pop(0)[0].remove()
        # recompute the ax.dataLim
        ax.relim()
        # update ax.viewLim using the new dataLim
        ax.autoscale_view()
        plt.draw()
    #legend: window + winparam if exist
    lines.append(
        ax.plot(w1,
                lw=0.5,
                label=fft_settings_['win'] +
                ('' if winParam_ == {} else str(winParam_))))
    ax.legend(prop={'size': 8})

    #Matplotlib to base64 picture https://stackoverflow.com/questions/31492525/converting-matplotlib-png-to-base64-for-viewing-in-html-template
    figfile = BytesIO()
    plt.savefig(figfile, format='png')
    figfile.seek(0)  # rewind to beginning of file

    figdata_png = base64.b64encode(figfile.getvalue())
    #    base64_string = base64_bytes.decode(figdata_png)

    return figdata_png.decode('utf8')
Esempio n. 5
0
import numpy as np
from matplotlib import pyplot as plt
from spectralc3 import spectral
import calc

fs=100
t=np.arange(0,10,1/fs)
y=np.sin(2*np.pi*7*t)+0.3*np.sin(2*np.pi*14*t+np.pi/2)
plt.figure()
plt.plot(t,y)
plt.xlabel('t(s)')

plt.figure()

#fs, fftlines, overlap=overlap, win='hann', averaging='exp',nAverage=10
sp = spectral(fs, fs*5, overlap=0.75, win='hanning', averaging='overall',nAverage=10,winParam={"sym":False},detrend='constant')
w1 = sp.w

sp.add(y)
Y, f = sp.get()

plt.semilogy(f,Y)
plt.xlabel('f(Hz)')

sp = spectral(fs, fs*5, overlap=0.75, win='general_cosine', averaging='overall',nAverage=10,winParam={"sym":False,"a":[1, 1.942604, 1.340318, 0.440811, 0.043097]},detrend='constant')
w2 = sp.w
sp.add(y)
Y, f = sp.get()
plt.semilogy(f,Y)
plt.legend()