상세 컨텐츠

본문 제목

푸리에 변환 파이썬코드 - 디리클레, 체사로, 아벨 합

수학

by 릿카。 2023. 4. 9. 18:18

본문

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])

디리클레 커널 - 그냥 부분합
페저 커널 - 체사로 부분합

 

푸아송 커널 - 아벨 합, a=0.9 (r의 역할)
푸아송 커널 - 아벨 합, a=0.95
푸아송 커널 - 아벨 합, a=0.99

 

관련글 더보기

댓글 영역