% % This script file verifies the "ideal reconstruction" formula of equation % (4.28), using 6 samples (0..5) of a 1 Hz sine wave sampled at T=0.2 sec. % % Variables r will be the original sine wave, rk will be the samples, % and rr will be the reconstructed signal. Variables r and rr should be % plotted vs time t, while sampled signal rk should be plotted vs tk. % First create the sample to be used in reconstruction k = [0:5]'; % Vector of sample indices from 0 to 5 T = 0.2; % Sample period (corresponds to 5 Hz) tk = k*T; % Vector of sample times rk = sin(2*pi*k*T); % Calculate the samples of sine function % Next calculate the reconstruction using a finer time step t = [0:0.01:1]'; % Hi-res time vector for generating reconstruction r = sin(2*pi*t); % Calculate continuous sine wave to compare N = length(t); % Number of samples in hi-res time vector rr = zeros(N,1); % Create zero vector to hold reconstructed rr(t) for k = 0:5 % Loop over sample points rr = rr + rk(k+1)*sinc(pi*(t-k*T)/T); end; hp = plot(t,r,'k-',tk,rk,'k*',t,rr,'r-'); grid; ha = gca; set(ha,'fontsize',18); set(hp,'linewidth',2); xlabel('Time (sec)'); legend('Original Function','Samples','Reconstruction');