Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.02 KB | None | 0 0
  1. close all;
  2. clear all;
  3.  
  4. a=1;
  5. U=-pi:0.01:pi;
  6. N=length(U);
  7.  
  8. %-------------------1------------------
  9.  
  10. m=@(x) (a*x.^2).*(x>-1).*(x<1) + 1.*(x>=1).*(x<2).*(x<=-1).*(x>2) + 0.*(x>=2).*(x<=-2);
  11.  
  12. figure(1);
  13. subplot(3,1,1);
  14. plot(U, m(U));
  15. title('1. Wykres uzyskany z charakterystyki nieliniowej.');
  16.  
  17. %-------------------2------------------
  18.  
  19. sigma=0.035;
  20. z=sigma*randn(1, N);
  21.  
  22. y=m(U)+z;
  23. subplot(3,1,2);
  24. hold on;
  25. plot(U, m(U));
  26. plot(U, y, 'ro');
  27. hold off;
  28. title('2. Wykres z dodana chmura bledu.');
  29.  
  30. %-------------------3------------------
  31.  
  32. L=50;
  33. k=10;
  34. fi0=1/(2*pi);
  35.  
  36. for i=1:k
  37.    fi{i}=@(x) (1/pi)*cos(i*x);
  38. end
  39.  
  40. for i=1:k
  41.     alfa{i}=@(x) (1/N)*symsum(y(n)*fi{i}(m(n)),n,1,N);
  42. end
  43.  
  44. for i=1:k
  45.     beta{i}=@(x) (1/N)*symsum(fi{i}(m(n)),n,1,N);
  46. end
  47.  
  48.  
  49. f_n=@(x) symsum(beta.*fi(x),k,0,L);
  50.  
  51. g_n=@(x) symsum(alfa.*fi(x),k,0,L);
  52.  
  53. %if f_n == 0
  54. %    m_n = 0;
  55. %else
  56. %    m_n=@(x) g_n(x)/f_n(x);
  57. %end
  58.  
  59. m_n=@(x) g_n(x)/f_n(x);
  60.  
  61. subplot(3,1,3)
  62. plot(U, m_n(U));
  63. title('3. Wykres uzyskany z bazy kosinusowej.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement