Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. clear all;
  2. N = 32;
  3. L= 32;
  4.  
  5.  
  6. %macierz F transformaty
  7. for(n=0:N-1)
  8. for(m=0:N-1)
  9. F(n+1,m+1) = (1/sqrt(N))*cos((2*pi/N)*n*m)-i*(1/sqrt(N))*sin((2*pi/N)*n*m);
  10. end
  11. end
  12.  
  13. disp("czy F jest ortogonalna?")
  14. FF =F*F';
  15. real(FF(1:5,1:5)) %tak jest
  16.  
  17.  
  18. %__________________________dla sygnalu sin____________________
  19. if(0)
  20. %sygnal wyslany sinusy
  21. L = 32;
  22. x3 = zeros(32,1);
  23. for(n=0:31)
  24. x3(n+1)= sin(2*pi*2*n/L)+sin(2*pi*6*n/L);
  25. end
  26.  
  27. %plot(x3,'r');
  28. %pause;
  29.  
  30. X = F*x3;
  31. X_obrazek = 20*log(abs(X));
  32. plot(X_obrazek);
  33. title("widmo gestosci mocy");
  34. pause;
  35.  
  36. x3_1 = inv(F)*X; %x~
  37. x3_1_2 = inv(F.')*X; %x~~
  38.  
  39. %czy wyniki sa takie same co do bledow numerycznych
  40. errorx3_1_to_x = max(abs(x3-x3_1))
  41. errorx3_1_2_to_x = max(abs(x3-x3_1_2))
  42.  
  43. if(x3_1 == x3_1_2)
  44. disp("macierze sa takie same");
  45. else
  46. disp("macierze sa inne")
  47. end
  48. figure; subplot(311);plot(1:L,x3,'-r');title("nadany");subplot(312);plot(1:L,x3_1,'-b');title("odebrany synteza 1");
  49. subplot(313);plot(1:L,x3_1_2,'-b');title('odebrany synteza 2');
  50.  
  51. end
  52.  
  53. %_____________________sygnal exp______________________
  54. if(0)
  55. L = 32;
  56. x3 = zeros(32,1);
  57. for(n=0:31)
  58. x3(n+1)= exp(-i*2*pi*2*n/L)+exp(-i*2*pi*6*n/L);
  59. end
  60.  
  61. %plot(x3,'r');
  62. %pause;
  63.  
  64. X = F*x3;
  65. X_obrazek = 20*log(abs(X));
  66. plot(X_obrazek);
  67. title("widmo gestosci mocy");
  68. pause;
  69.  
  70. x3_1 = inv(F)*X; %x~
  71. x3_1_2 = inv(F.')*X; %x~~
  72.  
  73. %czy wyniki sa takie same co do bledow numerycznych
  74. errorx3_1_to_x = max(abs(x3-x3_1))
  75. errorx3_1_2_to_x = max(abs(x3-x3_1_2))
  76.  
  77. if(x3_1 == x3_1_2)
  78. disp("macierze sa takie same");
  79. else
  80. disp("macierze sa inne")
  81. end
  82. figure; subplot(311);plot(1:L,x3,'-r');title("nadany");subplot(312);plot(1:L,x3_1,'-b');title("odebrany synteza 1");
  83. subplot(313);plot(1:L,x3_1_2,'-b');title('odebrany synteza 2');
  84.  
  85.  
  86. end
  87. %______________________dla y3__________________________
  88. if(0)
  89. load("h.mat");
  90. L = 32;
  91. x3 = zeros(32,1);
  92. for(n=0:31)
  93. x3(n+1)= sin(2*pi*2*n/L)+sin(2*pi*6*n/L);
  94. end
  95. h = h'; %nie umiem tego conv
  96. X3 = toeplitz(x3, zeros(1,32));
  97. y = X3*h;
  98.  
  99. X = F*y;
  100. X_obrazek = 20*log(abs(X));
  101. plot(X_obrazek);
  102. title("widmo gestosci mocy");
  103. pause;
  104.  
  105. y3_1 = inv(F)*X; %x~
  106. y3_1_2 = inv(F.')*X; %x~~
  107.  
  108. %czy wyniki sa takie same co do bledow numerycznych
  109. errory3_1_to_y = max(abs(y-y3_1))
  110. errory3_1_2_to_y = max(abs(y-y3_1_2))
  111.  
  112. if(y3_1 == y3_1_2)
  113. disp("macierze sa takie same");
  114. else
  115. disp("macierze sa inne")
  116. end
  117. figure; subplot(311);plot(1:L,y,'-r');title("nadany");subplot(312);plot(1:L,y3_1,'-b');title("odebrany synteza 1");
  118. subplot(313);plot(1:L,y3_1_2,'-b');title('odebrany synteza 2');
  119.  
  120. end
  121.  
  122.  
  123. %_____________________dla random_______________________
  124. if(1)
  125. rs = randn(32,1);
  126. %plot(rs);
  127.  
  128. RS=F*rs; %to jest to co jest podobne w F do sygnalu rs
  129. rs1=inv(F)*RS;
  130. rs2=inv(F.')*RS;
  131. X_obrazek = 20*log(abs(RS));
  132. plot(X_obrazek);
  133. title("widmo gestosci mocy");
  134. pause;
  135. %czy wyniki sa takie same co do bledow numerycznych
  136. error_rs1_to_rs = max(abs(rs-rs1))
  137. errorr_rs2_to_re = max(abs(rs-rs2))
  138.  
  139. if(rs1 == rs2)
  140. disp("macierze sa takie same");
  141. else
  142. disp("macierze sa inne")
  143. end
  144. figure; subplot(311);plot(1:L,rs,'-r');title("nadany");subplot(312);plot(1:L,rs1,'-b');title("odebrany synteza 1");
  145. subplot(313);plot(1:L,rs2,'-b');title('odebrany synteza 2');
  146.  
  147.  
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement