Emania

signal

Dec 6th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.91 KB | None | 0 0
  1. A1 = 0.8;
  2. f1 = 100;
  3. A2 = 0.5;
  4. f2 = 427;
  5. T = 0.5;
  6. fs = 8000;
  7. t = 1/f : 1 / f : T;
  8. var = 1.5;
  9.  
  10. sig1 = A1 * sin(2 * pi * f1 * t);
  11. sig2 = A2 * sin(2 * pi * f2 * t);
  12.  
  13. orig = sig1 + sig2;
  14. ORIG = fft(orig);
  15.  
  16.  
  17. noise = sqrt(var).*randn(1, fix(fs*T));
  18. sig = orig + noise;
  19.  
  20. SIG = fft(sig);
  21. N = mean(abs(SIG(1000:3000)));
  22. CLEARED = fft(sig);
  23. CLEARED_phase = CLEARED ./ abs(CLEARED);
  24. CLEARED_abs = abs(CLEARED) - 3 * N;
  25. CLEARED_abs = max(CLEARED_abs, 0);
  26. CLEARED = CLEARED_abs .* CLEARED_phase;
  27.  
  28. cleared_reconstructed = ifft(CLEARED);
  29. orig_reconstructed = ifft(ORIG);
  30.  
  31.  
  32. figure(1)
  33. subplot(321)
  34. plot(t, sig)
  35. title('signal with noise')
  36. subplot(322)
  37. plot(abs(SIG))
  38.  
  39. subplot(323)
  40. plot(cleared_reconstructed)
  41. title('reconstructed signal')
  42. axis([0 4000 -2 2])
  43. subplot(324)
  44. plot(abs(CLEARED))
  45.  
  46.  
  47. subplot(325)
  48. plot(orig_reconstructed)
  49. title('original signal')
  50. axis([0 4000 -2 2])
  51. subplot(326)
  52. plot(abs(ORIG))
Advertisement
Add Comment
Please, Sign In to add comment