Guest User

Untitled

a guest
Jan 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. f=1;
  2. T=1/f;
  3. mysignal = @(t) sin(2*pi*f*t);
  4.  
  5. f_s=5*f; % sampling rate
  6. T_s=1/f_s; % sampling period
  7. t=0:T_s:T; % times at which mysignal is sampled
  8. t1=0:.05*T_s:1.5*T; % times to plot mysignal "continuosly"
  9.  
  10. % plot mysgnal as a "continuos" signal
  11. hold off;
  12. plot(t1,mysignal(t1),'r')
  13. hold on;
  14.  
  15. function y = Whittaker_Shannon_interpolation(samples,T_s,t)
  16. % samples are the samples of the original signal;
  17. % T_s is sampling period;
  18. % t are the times at which interpolate the original signal;
  19. % y are the interpolated values (reconstructed) of the original signal at times t.
  20. y = zeros(1,length(t));
  21. normalized_sinc = @(x) sin(pi*x)./(pi*x);
  22. for k = 1:1:length(samples)
  23. % https://en.wikipedia.org/wiki/Whittaker%E2%80%93Shannon_interpolation_formula
  24. % the above formula uses so called "normalized sinc", i.e. sin(pi*x)/(pi*x)
  25. y+=samples(k)*normalized_sinc((t-k*T_s)/T_s);
  26. endfor
  27. endfunction
  28.  
  29. samples=mysignal(t);
  30. stem(t,samples,'b')
  31. hold on;
  32.  
  33. y=Whittaker_Shannon_interpolation(samples,T_s,t1);
  34. plot(t1,y,'k-o')
  35.  
  36. legend('original signal','samples','reconstructed')
Add Comment
Please, Sign In to add comment