Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.65 KB | None | 0 0
  1.  
  2. % simulate1fnoise(number of samples,
  3. %                 signal amplitude ,
  4. %                 signal frequency ,
  5. %                 number of redundant sensors to simulate (each has independent noise),
  6. %                 starting probability of each update)
  7. % Outputs:
  8. %
  9. % pure_signal = physical signal we want to measure
  10. % ideal_measurement = the best we could expect, after denoising (additive
  11. %                                                       noise limited)
  12. % additive_noise    = the additive noise
  13. % acquisition_signal = Simulated measurement. What we would actually
  14. % obtain.
  15. % update_noise       = the step-like noise which we want to remove, due to
  16. %                      the updates
  17. % refUpdates         = time instants at which the reference is updated, and we
  18. %                      have step-function noise
  19.  
  20. % The information we have available in the real case is refUpdates and
  21. % acquisition_signal.
  22.  
  23.  
  24. nsamp = 1000; t = 1:nsamp; nSensors = 10;
  25. [pure_signal,ideal_measurement,additive_noise,acquisition_signal,update_noise,refUpdates] = simulate1fnoise(nsamp,4,0.01,nSensors,0.8);
  26.  
  27.  
  28. figure, subplot(1,2,1), plot(t,ideal_measurement(1,:),t,pure_signal(1,:),'r'),
  29.         title('Ideal case for measurement (no updates)'), legend({'Ideal Measurement', 'Pure Signal'})
  30.         xlabel('time')
  31.         subplot(1,2,2), plot(t,acquisition_signal(1,:),t,update_noise(1,:),'r'),
  32.         title('Actual measurement'), legend({'Acquisition', 'Step noise'})
  33.         xlabel('time')
  34.  
  35.  
  36. function [pure_signal,ideal_measurement,additive_noise,acquisition_signal,update_noise,refUpdates] = simulate1fnoise(nsamp,amp,freq,nWindows,probabilityUpdate)
  37.  
  38.  
  39. t = 1:nsamp;
  40. pure_signal = amp*sin(2*pi*freq*t).*[zeros(1,floor(nsamp/4)) hamming(floor(nsamp/2))' zeros(1,nsamp-(floor(nsamp/2) + floor(nsamp/4)))] ;
  41.  
  42. additive_noise = randn(nWindows,nsamp);
  43. ideal_measurement = pure_signal + additive_noise; % What one would ideally measure
  44. update_noise = zeros(nWindows,nsamp);   % Noise resulting from updates (the part that we want to discover/remove from our signal)
  45. acquisition_signal = zeros(nWindows,nsamp);    % Actual physical measurement
  46.  
  47. refUpdates = zeros(nWindows,nsamp);
  48.  
  49. for wnd = 1:nWindows
  50.     updateError = 0;
  51.     countNoUpdates = -1;
  52.     for idx = 1:nsamp
  53.         countNoUpdates = countNoUpdates+1;
  54.         acquisition_signal(wnd,idx) = ideal_measurement(wnd,idx) + updateError;
  55.         update_noise(wnd,idx) = updateError;
  56.         if rand > probabilityUpdate-(countNoUpdates*0.025)
  57.             refUpdates(wnd,idx) = 1;
  58.             updateError = updateError+additive_noise(wnd,idx);
  59.             countNoUpdates = 0;
  60.         end
  61.     end
  62. end
  63.  
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement