File:Kalman Polynom Test.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 450 × 315 pixels, file size: 108 KB)

Captions

Captions

Example of Kalman filter applied to noisy polynomial.

Summary[edit]

Description
Deutsch: Der Kalman-Filter wird auf ein Polynom 3. Grades angewendet und versucht aus den verrauschten Daten die Polynomparameter zu schätzen. Im Laufe der Iterationen nährt sich die Schätzung immer mehr an den unverrauschten Verlauf an.
Date
Source Own work
Author Physikinger
SVG development
InfoField
 
The SVG code is valid.
 
This plot was created with Matplotlib.
Source code
InfoField

Python code

# This source code is public domain
# Autor: Christian Schirm

import numpy
import matplotlib.pyplot as plt

# Generate polynomial
nSteps = 301
coeff = [-50, 70, -16, 1]
sigmaNoise = 50
sigmaPrior = 100
xMax = 10

ts = numpy.linspace(0,xMax,nSteps)
deltaT = ts[1] - ts[0]
nPoly = len(coeff)
A = numpy.array([ts**i for i in range(nPoly)])
y_polynomial = coeff @ A

# Noise
numpy.random.seed(1)
noise = sigmaNoise*numpy.random.randn(nSteps)

# Add noise to the signal
y = y_polynomial + noise

# Prepare Kalman estimation
D = numpy.zeros((nPoly,nPoly))
D[(numpy.arange(nPoly-1), numpy.arange(nPoly-1)+1)] = 1
Dt = D*deltaT
F = numpy.identity(nPoly) + Dt + Dt @ Dt/2 + Dt @ Dt @ Dt/6
H = numpy.zeros((1,nPoly))
H[0,0] = 1

# Initialize Kalman estimation
x = numpy.zeros(nPoly)
components = A / nSteps
# P = sigmaPrior**2 * numpy.identity(nPoly)
P = sigmaPrior**2 * numpy.linalg.inv(components @ components.T)  # Constant variance prior model

# Start Kalman iteration
yEst = []
ySigma = []
for i in range(len(y)):
    # Propagate
    if i > 0:
        x = F @ x
        P = F @ P @ F.T

    # Estimate
    K = P @ H.T @ numpy.linalg.inv(H @ P @ H.T + sigmaNoise**2)
    x = x + K @ (y[i] - H @ x)
    P = (numpy.identity(nPoly) - K @ H) @ P
    ySigma.append(P[0,0])
    yEst.append(x[0])

ySigma = numpy.sqrt(ySigma)

# Plot
plt.figure(figsize=(5,3.5))
plt.plot(ts,y_polynomial,'C3-', label='Polynom 3. Grades', zorder=1)
plt.plot(ts,y,'.-', color='C1', markersize=4, linewidth=0.4, alpha=0.6, label='Polynom + Rauschen', zorder=2)
plt.plot(ts,yEst,'C0-',  label='Kalman-Schätzung', zorder=3)
plt.fill_between(ts,y_polynomial-ySigma, y_polynomial+ySigma, color='0.2', alpha=0.17,
        label='Fehlerschätzung\n(relativ zu wahrer Kurve)', lw=0, zorder=0)
plt.xlabel('Zeit')
plt.legend(loc=4)
plt.tight_layout()
plt.savefig('Kalman_Polynom_Test.svg')
plt.savefig('Kalman_Polynom_Test.png')
# plt.show()

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current20:29, 8 October 2023Thumbnail for version as of 20:29, 8 October 2023450 × 315 (108 KB)Physikinger (talk | contribs)Legende Reihenfolge, Konfidenz -> Fehlerschätzung
09:18, 24 January 2022Thumbnail for version as of 09:18, 24 January 2022450 × 315 (111 KB)Physikinger (talk | contribs)Typo
16:07, 22 January 2022Thumbnail for version as of 16:07, 22 January 2022450 × 315 (104 KB)Physikinger (talk | contribs)Korrigiertes a-priori Modell
23:23, 21 January 2022Thumbnail for version as of 23:23, 21 January 2022450 × 315 (91 KB)Physikinger (talk | contribs)Besseres a-priori Modell und Konfidenzinterval
23:30, 5 May 2021Thumbnail for version as of 23:30, 5 May 2021450 × 315 (76 KB)Physikinger (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata