Advertisement
Guest User

Untitled

a guest
May 4th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. Fd = 1000; %sampling rate in Hz
  2. points = 512;
  3. noise_mean = 0;
  4. dispersion = 30;
  5. noise_standard_dev = sqrt(dispersion);
  6.  
  7. %5. task
  8. n = randn(1,512);
  9.  
  10. %6. task
  11. A1=5;
  12. A2=5;
  13. A3=1;
  14. A4=1;
  15. W1=2*pi*100;
  16. W2=2*pi*120;
  17. W3=2*pi*200;
  18. W4=2*pi*250;
  19. F1=0;
  20. F2=pi/2;
  21. F3=pi;
  22. F4=1.5*pi;
  23. % t=(0:499)*1/Fd;
  24. t=0:1/Fd:511/Fd;
  25. s1 = A1*sin(W1*t+F1);
  26. s2 = A2*sin(W2*t+F2);
  27. s3 = A3*sin(W3*t+F3);
  28. s4 = A4*sin(W4*t+F4);
  29. s=s1+s2+s3+s4;
  30.  
  31. %7. task
  32. y = s + n;
  33. L=length(y);
  34.  
  35. %8. task
  36. figure(1)
  37. subplot(3,4,5)
  38. plot(n)
  39. title('Noise n');
  40. subplot(3,4,1)
  41. plot(s)
  42. title('Signal s');
  43. subplot(3,4,9)
  44. plot(y)
  45. title('Signal y (Sum of two signals)');
  46.  
  47. %9. task
  48. freq = Fd*((-floor(L/2)+1):floor(L/2))/L;
  49.  
  50. ffts = fft(s)/L;
  51. absffts = abs(ffts);
  52. fftshiftabsffts = fftshift(absffts);
  53.  
  54. fftn = fft(n)/L;
  55. absfftn = abs(fftn);
  56. fftshiftabsfftn = fftshift(absfftn);
  57.  
  58. fftn = fft(y)/L;
  59. absffty = abs(fftn);
  60. fftshiftabsffty = fftshift(absffty);
  61.  
  62.  
  63. subplot(3,4,2)
  64. plot(freq,fftshiftabsffts)
  65. title('Amplitude spectrum of signal s');
  66. subplot(3,4,6)
  67. plot(freq,fftshiftabsfftn)
  68. title('Amplitude spectrum of noise n');
  69. subplot(3,4,10)
  70. plot(freq,fftshiftabsffty)
  71. title('Amplitude spectrum of signal y');
  72.  
  73. %10. task
  74. [Pxx ws]=periodogram(s,[],'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  75. periodrams = fftshift(Pxx);
  76. [Pxx wn]=periodogram(n,[],'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  77. periodramn = fftshift(Pxx);
  78. [Pxx wy]=periodogram(y,[],'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  79. periodramy = fftshift(Pxx);
  80.  
  81. subplot(3,4,3)
  82. plot(freq,periodrams)
  83. title('Periodogram (rectangular) of signal s')
  84. subplot(3,4,7)
  85. plot(freq,periodramn)
  86. title('Periodogram(rectangular) of noise n')
  87. subplot(3,4,11)
  88. plot(freq,periodramy)
  89. title('Periodogram(rectangular) of signal y')
  90.  
  91. %11. task
  92. [Pxx wsh]=periodogram(s,hamming(L),'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  93. periodramhs = fftshift(Pxx);
  94. [Pxx wnh]=periodogram(n,hamming(L),'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  95. periodramhn = fftshift(Pxx);
  96. [Pxx wyh]=periodogram(y,hamming(L),'twosided',512,Fd); % the window corners are straight and cause parasitic leakage
  97. periodramhy = fftshift(Pxx);
  98.  
  99. subplot(3,4,4)
  100. plot(freq,periodramhs)
  101. title('Periodogram (hamming) of signal s')
  102. subplot(3,4,8)
  103. plot(freq,periodramhn)
  104. title('Periodogram (hamming) of noise n')
  105. subplot(3,4,12)
  106. plot(freq,periodramhy)
  107. title('Periodogram (hamming) of signal y')
  108.  
  109. %12. task
  110. %a.variant
  111.  
  112. % you estimate the values thanks to collums. calculate variance of each
  113. % collumn number.
  114.  
  115. for i = 1:1000
  116. n = randn(1,512);
  117. s=s1+s2+s3+s4;
  118. y=s+n;
  119.  
  120. ffts = fft(s);
  121. absffts = abs(ffts);
  122. fftshiftabsffts = fftshift(absffts);
  123.  
  124. fftn = fft(n);
  125. absfftn = abs(fftn);
  126. fftshiftabsfftn = fftshift(absfftn);
  127.  
  128. fftn = fft(y);
  129. absffty = abs(fftn);
  130. fftshiftabsffty = fftshift(absffty);
  131.  
  132. periodrams=periodogram(s,[],'twosided',points,Fd); % the window corners are straight and cause parasitic leakage
  133. periodramn=periodogram(n,[],'twosided',points,Fd);
  134. periodramy=periodogram(y,[],'twosided',points,Fd);
  135.  
  136. periodramhs=periodogram(s,hamming(L)); %for hamming the resolution is worse because the window is oval but it has less parasitic afflictions
  137. periodramhn=periodogram(n,hamming(L));
  138. periodramhy=periodogram(y,hamming(L));
  139.  
  140. %c.variant
  141. for k = 1:257
  142. MeshSignalfftshiftabsffty(i,k)=fftshiftabsffty(k);
  143. end
  144. for l = 1:257
  145. MeshSignalperiodram(i,l)=periodramy(l);
  146. end
  147. for m = 1:257
  148. MeshSignalperiodramh(i,m)=periodramhy(m);
  149. end
  150. end
  151. % figure(2)
  152. % subplot(1,2,1)
  153. % mesh(MeshSignalfftshiftabsffty)
  154. % subplot(1,2,2)
  155. % mesh(diag(cov(MeshSignalfftshiftabsffty)))
  156. % figure(3)
  157. % subplot(1,2,1)
  158. % mesh(MeshSignalperiodram)
  159. % subplot(1,2,2)
  160. % mesh(diag(cov(MeshSignalperiodram)))
  161. % figure(4)
  162. % subplot(1,2,1)
  163. % mesh(MeshSignalperiodramh)
  164. % subplot(1,2,2)
  165. % mesh(diag(cov(MeshSignalperiodramh)))
  166. %d.variant
  167. % check with zero noise. then the diag(cov) should be zeros .
  168. % periodgram shoul give highest variance method. Welch and bartlett
  169. % deceases the variance
  170.  
  171.  
  172.  
  173. %b.variant
  174. for i = 1:1000
  175. n = noise_mean + noise_standard_dev*randn(1,512);
  176. s=s1+s2+s3+s4;
  177. y=s+n;
  178.  
  179. ffts = fft(s);
  180. absffts = abs(ffts);
  181. fftshiftabsffts = fftshift(absffts);
  182.  
  183. fftn = fft(n);
  184. absfftn = abs(fftn);
  185. fftshiftabsfftn = fftshift(absfftn);
  186.  
  187. fftn = fft(y);
  188. absffty = abs(fftn);
  189. fftshiftabsffty = fftshift(absffty);
  190.  
  191. periodrams=periodogram(s); % the window corners are straight and cause parasitic leakage
  192. periodramn=periodogram(n);
  193. periodramy=periodogram(y);
  194.  
  195. periodramhs=periodogram(s,hamming(Ls)); %for hamming the resolution is worse because the window is oval but it has less parasitic afflictions
  196. periodramhn=periodogram(n,hamming(Ln));
  197. periodramhy=periodogram(y,hamming(Ly));
  198.  
  199. %c.variant
  200. for k = 1:257
  201. MeshSignalfftshiftabsffty(i,k)=fftshiftabsffty(k);
  202. end
  203. for l = 1:257
  204. MeshSignalperiodram(i,l)=periodramy(l);
  205. end
  206. for m = 1:257
  207. MeshSignalperiodramh(i,m)=periodramhy(m);
  208. end
  209. end
  210. figure(11)
  211. mesh(MeshSignalfftshiftabsffty)
  212. figure(12)
  213. mesh(MeshSignalperiodram)
  214. figure(13)
  215. mesh(MeshSignalperiodramh)
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. % %14. task
  244. % wel1=pwelch(s,250,250,length(s));
  245. % wel2=pwelch(y,250,250,length(y));
  246. %
  247. % figure(5)
  248. % subplot(2,1,1);plot(wel1)
  249. % title('Signal s');
  250. % subplot(2,1,2);plot(wel2)
  251. % title('Signal y');
  252. %
  253. % %15. task
  254. %
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement