import numpy as np
import matplotlib.pyplot as plt
# Define the step function
def step_function(x):
return 1 if x >= 0 else 0
# Fourier coefficients for the step function
def fourier_coefficients(n):
if n == 0:
return 0.5
else:
return (1 / (np.pi * n)) * (1 - (-1)**n)
# Truncated Fourier series
def truncated_fourier_series(x, N):
return 0.5 + sum([fourier_coefficients(n) * np.sin(n * x) for n in range(1, N + 1)])
# Modified Dirichlet kernel (Cesàro sum)
def dirichlet_modified(x, N):
return truncated_fourier_series(x, N)
# Fejer's kernel (Cesàro sum)
def fejers_kernel(x, N):
return (1 / (N + 1)) * sum([truncated_fourier_series(x, n) for n in range(N + 1)])
# Poisson kernel
def poisson_kernel(x, N, a):
return fourier_coefficients(0) + sum([fourier_coefficients(n) * np.sin(n * x) * (a**n) for n in range(1, N + 1)])
# Plotting function
def plot_convergence(n_values, kernel_name, kernel, **kwargs):
plt.figure(figsize=(10, 5))
x = np.linspace(-1 * np.pi, 1 * np.pi, 1000)
for n in n_values:
plt.plot(x, [kernel(xi, n, **kwargs) for xi in x], label=f'N = {n}')
plt.plot(x, [step_function(xi) for xi in x], '--', label='Step function', color='black')
plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.title(f'Fourier series convergence with {kernel_name} (Step function)')
plt.show()
n_values = [1, 5, 20, 50]
aa = [0.9, 0.95, 0.99]
plot_convergence(n_values, "Modified Dirichlet Kernel", dirichlet_modified)
plot_convergence(n_values, "Fejer's Kernel", fejers_kernel)
plot_convergence(n_values, "Poisson Kernel with a = "+str(aa[0]), poisson_kernel, a=aa[0])
plot_convergence(n_values, "Poisson Kernel with a = "+str(aa[1]), poisson_kernel, a=aa[1])
plot_convergence(n_values, "Poisson Kernel with a = "+str(aa[2]), poisson_kernel, a=aa[2])
푸리에 해석 평균제곱수렴 파이썬 코드 (0) | 2023.04.09 |
---|---|
푸리에 해석 : 리만-르베그 보조정리 파이썬코드 (0) | 2023.04.09 |
푸리에 해석 (2-5) : 체사로, 아벨 합 - 푸리에 급수의 응용 (0) | 2023.04.08 |
푸리에 해석 (2-4) : 좋은 커널 (0) | 2023.04.08 |
푸리에 해석 (2-3) : 컨볼루션 (0) | 2023.04.08 |
댓글 영역