kurse:efcomputergrafik:kw45

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
kurse:efcomputergrafik:kw45 [2019/11/05 12:01]
Marcel Metzler
kurse:efcomputergrafik:kw45 [2019/11/05 13:25]
Marcel Metzler
Line 27: Line 27:
  
  Ermittle für den Datesatz "Daten_ksg.txt" ein optimales $k_{max}$. Optimal ist in diesem Fall individuel und nicht mathematisch exakt und daher nicht eindeutig.  Ermittle für den Datesatz "Daten_ksg.txt" ein optimales $k_{max}$. Optimal ist in diesem Fall individuel und nicht mathematisch exakt und daher nicht eindeutig.
 +
 +<hidden>
 +<code python Fourier_Rek.py>
 +from gpanel import *
 +import math
 +import cmath
 +import csv
 +
 +#-----------------------------------------
 +# Einlesen der Daten
 +#-----------------------------------------
 +Koordinaten=[]
 +print('Daten lesen Start')
 +with open('Daten_ksbg.txt') as csvfile:
 +    reader=csv.DictReader(csvfile)
 +    for row in reader:
 +        Koordinaten.append([float(row['x']),float(row['y'])])
 +print('Daten lesen Ende')
 +#-----------------------------------------
 +# Bild zeichnen
 +#-----------------------------------------
 +makeGPanel(0,100,0,100)
 +move(Koordinaten[0][0], Koordinaten[0][1])
 +for ko in Koordinaten:
 +    draw(ko[0],ko[1])
 +delay(1000)
 +clear()
 +#-----------------------------------------
 +# Berechnen der Fourierkoeffizienten
 +# Teil 1: Init.
 +#-----------------------------------------
 +anzP=len(Koordinaten)
 +dt=1/(anzP-1)
 +kMax=int(math.floor(anzP/32)) # Datenkomprimierung
 +print(str(anzP)+' Datenpunkte')
 +print(str(2*kMax+1)+" Fourierkoeffizienten")
 +c=[]
 +for k in range(2*kMax+1):
 +    c.append(complex(0,0))
 +f=open('Fourier_Test_ksbg.txt','w')
 +#-----------------------------------------
 +# Berechnen der Fourierkoeffizienten
 +# Teil 2: c_k von -kmax <= k <= kmax 
 +#-----------------------------------------
 +for k in range(-kMax,kMax+1):
 +    for i in range(anzP):
 +        kshift=k+kMax
 +        c[kshift]=c[kshift]+complex(Koordinaten[i][0],Koordinaten[i][1])*cmath.exp(-2*math.pi*k*i*dt*1j)*dt
 +    c[kshift]=complex(round(c[kshift].real,2),round(c[kshift].imag,2))
 +    f.write(str(c[kshift]) + '\n')
 +f.close()    
 +print('Fourierkoeffizienten berechnet')
 +#-----------------------------------------
 +# Rekonstruktion des Bildes
 +#-----------------------------------------
 +setColor('red')
 +t=[]
 +t.append(0)
 +for i in range(anzP-1):
 +    t.append(t[i]+dt)
 +#---------------------------------------
 +# Startpunkt berechnen und Corsor
 +# dort abstellen
 +#---------------------------------------
 +f=0
 +for k in range(-kMax,kMax+1):
 +    kshift=k+kMax
 +    f=f+c[kshift]*cmath.exp(2*math.pi*k*t[0]*1j)
 +move(f.real,f.imag)
 +f=0
 +#---------------------------------------
 +# Rest zeichnen
 +#---------------------------------------
 +for i in range(anzP):
 +    for k in range(-kMax,kMax+1):
 +        kshift=k+kMax
 +        f=f+c[kshift]*cmath.exp(2*math.pi*k*t[i]*1j)
 +    draw(f.real,f.imag)
 +    delay(10)
 +    f=0   
 +print('Bild gezeichnet'
 +</code>
 +</hidden>
  • kurse/efcomputergrafik/kw45.txt
  • Last modified: 2019/11/06 07:55
  • by Ivo Blöchliger