Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. close all; clear; clc;
  2.  
  3. Fs = 50;
  4. t = 0:(1/Fs):10;
  5.  
  6. harm1 = sin(2*pi*2.*t);
  7. harm2 = 0.5*sin(2*pi*5.*t);
  8. gauss = 0.5*0.5*exp((-(t-0.5).^2)/(2*0.5*0.5));
  9.  
  10. x = harm1 + harm2 + gauss;
  11.  
  12. x_szum = x + 0.2*randn(size(t));
  13.  
  14. oc =@(x,y) sqrt(((x-y)*(x-y)'));
  15.  
  16. k = 1;
  17.  
  18. for n=3:2:71
  19. %srednia
  20. x_avg = conv(x_szum, ones(1, n)/n, 'same');
  21. wa(k) = oc(x, x_avg);
  22.  
  23. %gauss
  24. n2 = floor(n/2);
  25. odch = n/6;
  26. temp1 = exp((-(-n2:n2).^2)/(2*odch*odch));
  27. temp1 = temp1/sum(temp1);
  28. x_gauss = conv(x_szum, temp1, 'same');
  29. wa_gauss(k) = oc(x, x_gauss);
  30.  
  31. temp2 = medfilt1(x, n);
  32. wa_mediana(k)= oc(x, temp2);
  33.  
  34. temp3 = wiener2(x_szum, [1 n]);
  35. wa_wiener(k) = oc(x, temp3);
  36.  
  37. k = k+1;
  38. end
  39.  
  40. tt = 3:2:71;
  41. %plot(tt, wa, 'r', tt, wa_gauss, 'g', tt, wa_mediana, 'b', ...
  42. % tt, wa_wiener, 'y');
  43.  
  44.  
  45. gauss = exp((-(-0.03:(1/Fs):0.03).^2)/(2*(3/6).^2));
  46. gauss = gauss/sum(gauss);
  47. x_new = conv(x_szum, gauss, 'same');
  48.  
  49.  
  50. %x_new = conv(x_new, ones(1,3)/3, 'same');
  51.  
  52.  
  53.  
  54. subplot(211), plot(tt, wa, 'r', tt, wa_gauss, 'g',...
  55. tt, wa_mediana,...
  56. 'b', ...
  57. tt, wa_wiener, 'y');
  58. subplot(212), plot(t, x, 'r', t, x_new, 'g');
  59.  
  60. oc(x, x_new)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement