Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.06 KB | None | 0 0
  1. clear, clc
  2.  
  3. fun = inline('sin(2*pi*x*3)+sin(2*pi*x*5)');
  4.  
  5. fs = 40;
  6. x = 0 : 1/fs : 10;
  7. y = fun(x);
  8.  
  9. fsn = 50;
  10. xi = 2 : 1/fsn : 8;
  11. yr = fun(xi);
  12.  
  13. c = 6;
  14.  
  15. % starting times and values
  16. times = x(1:c);
  17. values = y(1:c);
  18.  
  19. % Evaluate barycentric weights
  20. w = zeros(1, c);
  21. for j = 1:c
  22.     prod = 1;
  23.     for k = 1:c
  24.         if ( k ~= j )
  25.             prod = prod * ( times(j) - times(k) );
  26.         end
  27.     end
  28.     w(j) = 1/prod;
  29. end
  30.  
  31. % Evaluate points
  32. index = 0;
  33. yi = zeros(1, length(xi));
  34. for i = 1:length(xi)
  35.    
  36.     t = xi(i);
  37.    
  38.     while t > times(c/2)
  39.         index = index+1;
  40.         times = (1+index:c+index)/fs - 1/fs;
  41.         values = y(1+index:c+index);
  42.     end
  43.  
  44.     if find( abs(xi(i)-times) < 1e-15 )
  45.         yi(i) = values(  abs(xi(i)-times) < 1e-15  );
  46.         continue;
  47.     end
  48.    
  49.     num = 0;
  50.     dem = 0;
  51.     for j = 1:c
  52.         temp = ( w(j) / (xi(i)-times(j)) );
  53.         num = num + temp * values(j);
  54.         dem = dem + temp;
  55.     end
  56.     yi(i) = num/dem;
  57.    
  58. end
  59.  
  60. %plot(xi, yr, 'b', xi, yi, 'r')
  61.  
  62. snr(yr,yi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement