diff options
author | Nicolas Tobler <nicolas.tobler@ost.ch> | 2022-08-23 22:33:40 +0200 |
---|---|---|
committer | Nicolas Tobler <nicolas.tobler@ost.ch> | 2022-08-23 22:33:40 +0200 |
commit | 6ac6dd132a11abd9ec4955cd2e35e22408c982e6 (patch) | |
tree | 902445b16ec2f2b9df3b3659b6139926469c267f /buch/papers/fm/Python animation/Bessel-FM.py | |
parent | Added Berechnung der rationalen Funktion (diff) | |
parent | Merge pull request #63 from NaoPross/master (diff) | |
download | SeminarSpezielleFunktionen-6ac6dd132a11abd9ec4955cd2e35e22408c982e6.tar.gz SeminarSpezielleFunktionen-6ac6dd132a11abd9ec4955cd2e35e22408c982e6.zip |
Merge branch 'master' of https://github.com/AndreasFMueller/SeminarSpezielleFunktionen
Diffstat (limited to '')
-rw-r--r-- | buch/papers/fm/Python animation/Bessel-FM.py | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/buch/papers/fm/Python animation/Bessel-FM.py b/buch/papers/fm/Python animation/Bessel-FM.py index cf30e16..cb35ebd 100644 --- a/buch/papers/fm/Python animation/Bessel-FM.py +++ b/buch/papers/fm/Python animation/Bessel-FM.py @@ -4,39 +4,45 @@ from scipy.fft import fft, ifft, fftfreq import scipy.special as sc import scipy.fftpack import matplotlib.pyplot as plt -from matplotlib.widgets import Slider - -# Number of samplepoints -N = 600 -# sample spacing -T = 1.0 / 800.0 -x = np.linspace(0.01, N*T, N) -beta = 1.0 -y_old = np.sin(100.0 * 2.0*np.pi*x+beta*np.sin(50.0 * 2.0*np.pi*x)) -y = 0*x; -xf = fftfreq(N, 1 / 400) -for k in range (-5, 5): - y = sc.jv(k,beta)*np.sin((100.0+k*50) * 2.0*np.pi*x) - yf = fft(y) - plt.plot(xf, np.abs(yf)) - -axbeta =plt.axes([0.25, 0.1, 0.65, 0.03]) -beta_slider = Slider( -ax=axbeta, -label="Beta", -valmin=0.1, -valmax=3, -valinit=beta, -) - -def update(val): - line.set_ydata(fm(beta_slider.val)) - fig.canvas.draw_idle() +import matplotlib as mpl +# Use the pgf backend (must be set before pyplot imported) +mpl.use('pgf') +from matplotlib.widgets import Slider +def fm(beta): + # Number of samplepoints + N = 600 + # sample spacing + T = 1.0 / 1000.0 + fc = 100.0 + fm = 30.0 + x = np.linspace(0.01, N*T, N) + #beta = 1.0 + y_old = np.sin(fc * 2.0*np.pi*x+beta*np.sin(fm * 2.0*np.pi*x)) + y = 0*x; + xf = fftfreq(N, 1 / N) + for k in range (-4, 4): + y = sc.jv(k,beta)*np.sin((fc+k*fm) * 2.0*np.pi*x) + yf = fft(y)/(fc*np.pi) + plt.plot(xf, np.abs(yf)) + plt.xlim(-150, 150) + #plt.savefig('bessel.pgf', format='pgf') + plt.show() -beta_slider.on_changed(update) -plt.show() +fm(1) -yf_old = fft(y_old) -plt.plot(xf, np.abs(yf_old)) -plt.show()
\ No newline at end of file +# Bessel-Funktion +for n in range (-2,4): + x = np.linspace(-11,11,1000) + y = sc.jv(n,x) + plt.plot(x, y, '-',label='n='+str(n)) +#plt.plot([1,1],[sc.jv(0,1),sc.jv(-1,1)],) +plt.xlim(-10,10) +plt.grid(True) +plt.ylabel('Bessel $J_n(\\beta)$') +plt.xlabel(' $ \\beta $ ') +plt.plot(x, y) +plt.legend() +#plt.show() +plt.savefig('bessel.pgf', format='pgf') +print(sc.jv(0,1))
\ No newline at end of file |