Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.04 KB | None | 0 0
  1. clear all;
  2. clf;
  3.  
  4. fs = 3;
  5. Ts = 1/fs;
  6. num_sec = 6;
  7. ws = 2*pi*fs;
  8. wc = ws/2;
  9. t = linspace(-floor(num_sec/2), floor(num_sec/2), num_sec*100+1);
  10.  
  11. x = exp(-2*t.^2).*cos((2*pi).*t);
  12. h = Ts*wc/pi*sinc(wc.*t/pi);
  13. xp = zeros(1, num_sec*fs);
  14. tp = zeros(1, num_sec*fs);
  15.  
  16. index = 1;
  17. dec = 0;
  18. for iter = 1:length(t)
  19.     if(t(iter) < 0)
  20.         dec = t(iter) - ceil(t(iter));
  21.     else
  22.         dec = t(iter) - floor(t(iter));
  23.     end
  24.     for k = -floor(num_sec/2):floor(num_sec/2)
  25.         if(round(dec, 2) == round(k*Ts, 2))
  26.             for n = 1:fs
  27.                 xp(index) = x(iter);
  28.                 tp(index) = t(iter);
  29.                 index = index + 1;
  30.             end
  31.         end
  32.     end
  33. end
  34.  
  35. xr = zeros(1, length(xp));
  36.  
  37. for iter = 1:length(tp)
  38.     for n2 = -10000:10000
  39.         xr(iter) = xr(iter) + xp(iter)*Ts*wc/pi*...
  40.             sinc(wc*(t(iter)-n2*Ts)/pi);
  41.     end
  42. end
  43.  
  44. figure(1);
  45. plot(t, x, 'b'); hold on
  46. plot(tp, xr, 'r')
  47. plot(tp, xp, 'or');
  48.  
  49. xlabel('time (s)');
  50. axis([-floor(num_sec/2) floor(num_sec/2) -1.2 1.2]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement