0
$\begingroup$

I tried to implement Whittaker-Shannon-Kotel’nikov interpolation formula but I get unexpected results: the reconstructed signal lags with respect to the original.

enter image description here

I know that I can not expect a perfect reconstruction because I am sampling a finite time signal (just one cycle of a sine wave) and this finite time signal is not bandwidth limited and so the Whittaker-Shannon-Kotel’nikov theorem does not hold... but I do not know whether to expect a lag.

I suspect there is something wrong in my implementation (for example in a previous implementation I was erroneously using $\frac{\sin x}{x}$ instead of $\frac{\sin \pi x}{\pi x}$) but I can not find it.

f=1;
T=1/f;
mysignal = @(t) sin(2*pi*f*t);

f_s=5*f; % sampling rate
T_s=1/f_s; % sampling period
t=0:T_s:T; % times at which mysignal is sampled 
t1=0:.05*T_s:1.5*T; % times to plot mysignal "continuosly"

% plot mysgnal as a "continuos" signal
hold off;
plot(t1,mysignal(t1),'r')
hold on;

function y = Whittaker_Shannon_interpolation(samples,T_s,t)
% samples are the samples of the original signal;
% T_s is sampling period;
% t are the times at which interpolate the original signal;
% y are the interpolated values (reconstructed) of the original signal at times t.
  y = zeros(1,length(t));
  normalized_sinc = @(x) sin(pi*x)./(pi*x);
  for k = 1:1:length(samples)
    % https://en.wikipedia.org/wiki/Whittaker%E2%80%93Shannon_interpolation_formula
    % the above formula uses so called "normalized sinc", i.e. sin(pi*x)/(pi*x)
    y+=samples(k)*normalized_sinc((t-k*T_s)/T_s);
  endfor
endfunction

samples=mysignal(t);
stem(t,samples,'b')
hold on;

y=Whittaker_Shannon_interpolation(samples,T_s,t1);
plot(t1,y,'k-o')

legend('original signal','samples','reconstructed')
$\endgroup$
1
$\begingroup$

Replace the line

y+=samples(k)*normalized_sinc((t-k*T_s)/T_s);

by

y+=samples(k)*normalized_sinc((t-(k-1)*T_s)/T_s);

because the indices inside the sinc function must start from $0$, not from $1$. The first sinc must have its peak at $t=0$, not at $t=T_s$.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.