# We fix the parameter of the Cauchy model amplitude = [5] scale = [3] model = ot.CauchyModel(scale, amplitude) gp = ot.SpectralGaussianProcess(model, myTimeGrid) # Get a time series or a sample of time series # myTimeSeries = gp.getRealization() mySample = gp.getSample(1000) mySegmentNumber = 10 myOverlapSize = 0.3 # Build a spectral model factory myFactory = ot.WelchFactory(ot.Hanning(), mySegmentNumber, myOverlapSize) # Estimation on a TimeSeries or on a ProcessSample # myEstimatedModel_TS = myFactory.build(myTimeSeries) myEstimatedModel_PS = myFactory.buildAsUserDefinedSpectralModel(mySample) # Change the filtering window myFactory.setFilteringWindows(ot.Hamming()) # Get the FFT algorithm myFFT = myFactory.getFFTAlgorithm() # Get the frequencyGrid frequencyGrid = myEstimatedModel_PS.getFrequencyGrid() # With the model, we want to compare values
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View filteringWindow = ot.Hanning() numPoints = 512 data = ot.Sample(numPoints, 2) for i in range(numPoints): x = -0.1 + (1.2 * i) / (numPoints - 1.0) data[i, 0] = x data[i, 1] = filteringWindow(x) graph = ot.Graph() graph.setXTitle('$tau$') graph.setYTitle('W') graph.add(ot.Curve(data)) graph.setColors(['red']) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(filteringWindow)) filtering_axis = fig.add_subplot(111) View(graph, figure=fig, axes=[filtering_axis], add_legend=False)
covmodel = ot.ExponentialModel(scale, amplitude) # Create a stationary Normal process with that covariance model process = ot.GaussianProcess(covmodel, tgrid) # Create a time series and a sample of time series tseries = process.getRealization() sample = process.getSample(1000) # %% # Build a factory of stationary covariance function covarianceFactory = ot.StationaryCovarianceModelFactory() # Set the spectral factory algorithm segmentNumber = 5 spectralFactory = ot.WelchFactory(ot.Hanning(), segmentNumber) covarianceFactory.setSpectralModelFactory(spectralFactory) # Check the current spectral factory print(covarianceFactory.getSpectralModelFactory()) # %% # Case 1 : Estimation on a ProcessSample # The spectral model factory computes the spectral density function # without using the block and overlap arguments of the Welch factories estimatedModel_PS = covarianceFactory.build(sample) # Case 2 : Estimation on a TimeSeries # The spectral model factory compute the spectral density function using
# We fix the parameter of the Cauchy model amplitude = [5.0] scale = [3.0] model = ot.CauchyModel(amplitude, scale) process = ot.SpectralGaussianProcess(model, tgrid) # Get a time series or a sample of time series tseries = process.getRealization() sample = process.getSample(1000) # %% # Build a spectral model factory segmentNumber = 10 overlapSize = 0.3 factory = ot.WelchFactory(ot.Hanning(), segmentNumber, overlapSize) # %% # Estimation on a TimeSeries or on a ProcessSample estimatedModel_TS = factory.build(tseries) estimatedModel_PS = factory.build(sample) # %% # Change the filtering window factory.setFilteringWindows(ot.Hamming()) # %% # Get the frequencyGrid frequencyGrid = ot.SpectralGaussianProcess(estimatedModel_PS, tgrid).getFrequencyGrid()