fourier_demo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cs515 Demo: Smoothness of f ~ decay of f^
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Useful data for first two examples:
n = [-128:127]; % range of fourier coefficients
t = n / 128 * pi; % define functions on [-pi,pi)
ttt = [t-2*pi,t,t+2*pi]; % time axis for periodic extension
N = length(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ex 1: A piecewise constant function related to H(t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (t<0) - (t>=0); % evaluate f(t)
% F = (2*pi)*fftshift(fft(f))/N; % FFT evaluation: F(n) = f^(n)
F = (2i*pi) * sin(n*pi/2) .* sinc(n/2); % Use analytic form of f^(n)
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter for next example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ex 2: A piecewise linear function related to B2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (t/pi+1).*(t<0) + (1-t/pi).*(t>=0); % evaluate f(t)
% F = (2*pi)*fftshift(fft(f))/N; % FFT evaluation: F(n) = f^(n)
F = pi*sinc(n/2).^2; % Use analytic form of f^(n)
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter for next example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example 3: Reconstruction of a 'smooth' function %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n = [-128:127]; % range of Fourier coefficients
t = n/128*pi;
N = length(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A piecewise cubic related to B4 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (2*t/pi+2).^3/6 .* (t>=-pi & t<-pi/2) ... % ... continued
-(3*(2*t/pi+2).^3 - 12*(2*t/pi+2).^2+12*(2*t/pi+2)-4)/6 .* (t>=-pi/2 & t<0) ...
+(3*(2*t/pi+2).^3 -24*(2*t/pi+2).^2 + 60*(2*t/pi+2)-44)/6 .*(t>=0 & t=pi/2 & t0&t<1);
g(index) = exp(1./(t(index)-1)-1./t(index));
s = max(g); g = g / s;
G = fftshift(fft(g))/N;
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
??? Error using ==> get
Invalid handle object.
Error in ==> btndown at 21
axesHandle = findobj(get(figHandle, 'children'), 'flat', ...
Error in ==> fourier_demo at 352
btndown(5,'TestGroup', 'Next>>');
fourier_demo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cs515 Demo: Smoothness of f ~ decay of f^
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Useful data for first two examples:
n = [-128:127]; % range of fourier coefficients
t = n / 128 * pi; % define functions on [-pi,pi)
ttt = [t-2*pi,t,t+2*pi]; % time axis for periodic extension
N = length(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ex 1: A piecewise constant function related to H(t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (t<0) - (t>=0); % evaluate f(t)
% F = (2*pi)*fftshift(fft(f))/N; % FFT evaluation: F(n) = f^(n)
F = (2i*pi) * sin(n*pi/2) .* sinc(n/2); % Use analytic form of f^(n)
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter for next example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ex 2: A piecewise linear function related to B2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (t/pi+1).*(t<0) + (1-t/pi).*(t>=0); % evaluate f(t)
% F = (2*pi)*fftshift(fft(f))/N; % FFT evaluation: F(n) = f^(n)
F = pi*sinc(n/2).^2; % Use analytic form of f^(n)
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter for next example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example 3: Reconstruction of a 'smooth' function %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n = [-128:127]; % range of Fourier coefficients
t = n/128*pi;
N = length(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A piecewise cubic related to B4 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = (2*t/pi+2).^3/6 .* (t>=-pi & t<-pi/2) ... % ... continued
-(3*(2*t/pi+2).^3 - 12*(2*t/pi+2).^2+12*(2*t/pi+2)-4)/6 .* (t>=-pi/2 & t<0) ...
+(3*(2*t/pi+2).^3 -24*(2*t/pi+2).^2 + 60*(2*t/pi+2)-44)/6 .*(t>=0 & t=pi/2 & t0&t<1);
g(index) = exp(1./(t(index)-1)-1./t(index));
s = max(g); g = g / s;
G = fftshift(fft(g))/N;
echo off;
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue
Hit Enter to continue