矩形波に対してチェザロ総和法(N=100)を適用

clear; close all; clc; T=2*pi; f0=1/T; dt=0.01; t=-T/2:dt:T/2; y=f(t); plot(t,y,'r','DisplayName','original'); hold on; a0=0; a=@(n) 0; b=@(n) 2*(1-(-1)^n)/(pi*n); nmaxs=[100]; %Fourier series for idx=1:length(nmaxs) nmax = nmaxs(idx); yt=fourier_series(t,f0,a0,a,b,nmax); plot(t,yt,'DisplayName',sprintf('N=%d',nmax)); end %Cèsaro summation of Fourier series to suppress Gibbs' phenomena for idx=1:length(nmaxs) nmax = nmaxs(idx); ytc=0; for n=1:nmax ytc=ytc+fourier_series(t,f0,a0,a,b,n); end ytc=ytc/nmax; plot(t,ytc,'DisplayName',sprintf('N=%d(Cesàro summation)',nmax)); end legend(); big; function res=f(t) res = []; for idx=1:length(t) ti=t(idx); if ti<0 res(idx)=-1; else res(idx)=1; end end end function ft=fourier_series(t,f0,a0,a,b,nmax) ft = a0/2; for n=1:nmax an = a(n); bn = b(n); ft = ft + an*cos(2*pi*f0*n*t) + bn*sin(2*pi*f0*n*t); end end