%------------------------------------------------------------

% Tony Hyun Kim

% 6.638 PS2 Problem 1b

%   Calibration of Matlab DFT with class convention for FT

%------------------------------------------------------------

clear all; close all;



% Parameters for DFT

L = 2^10;                    % Length of signal

tau = 50*linspace(-1,1,L);   % Time vector [tau]

T  = tau(2)-tau(1);          % Sample time [tau]

Fs = 1/T;                    % Sampling frequency [1/tau]



% Parameters for initial soliton

N = 1;

a = 1/sqrt(2);

u = N*sech(a*tau);



% Time domain signal

subplot(121);

plot(tau,u);

xlabel('\tau');

ylabel('u(z=0,\tau)');

title('Pulse in time domain');



% Frequency domain

subplot(122);

U = T*fft(u);

Us = fftshift(U);

f = Fs/2*linspace(-1,1,L);

plot(f,abs(Us),'.-'); hold on;

xlim([-1 1]);

xlabel('Frequency 1/[\tau]');

title('Frequency component of pulse');



% Check against analytic formula

w = 2*pi*f;

Ua = 1/a*pi*sech(pi/(2*a)*w);

plot(f,Ua,'ro');

legend('Numerical','Analytic');



% Check ifft

subplot(121); hold on;

u2 = 1/T*ifft(U);

plot(tau,u2,'ro');

legend('Original','Numerical IFFT');