Create a custom spectral modelΒΆ

In this basic example we are going to build a custom spectral model.

In [10]:
from __future__ import print_function
import openturns as ot
import math as m
In [11]:
# Create the frequency grid:
fmin = 0.1
df = 0.5
N = int((10.0 - fmin)/ df)
myFrequencyGrid =  ot.RegularGrid(fmin, df, N)
In [12]:
# Define the spectral function:
def s(f):
    if(f <= 5.0):
        return 1.0
    else:
        x = f - 5.0
        return m.exp(-2.0 * x * x)
In [13]:
# Create the collection of HermitianMatrix:
myCollection = ot.HermitianMatrixCollection()
for k in range(N):
    frequency = myFrequencyGrid.getValue(k)
    matrix = ot.HermitianMatrix(1)
    matrix[0, 0] = s(frequency)
    myCollection.add(matrix)
In [14]:
# Create the spectral model:
mySpectralModel = ot.UserDefinedSpectralModel(myFrequencyGrid, myCollection)
print(mySpectralModel)
frequency=RegularGrid(start=0.1, step=0.5, n=19) dimension=1 DSPCollection=[[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (1,0) ]],[[ (0.980199,0) ]],[[ (0.486752,0) ]],[[ (0.0889216,0) ]],[[ (0.00597602,0) ]],[[ (0.000147748,0) ]],[[ (1.34381e-06,0) ]],[[ (4.49635e-09,0) ]],[[ (5.53461e-12,0) ]],[[ (2.50622e-15,0) ]]]#19