Guest User

Untitled

a guest
Oct 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. %Generation of colored noise in Matlab
  2. a=0.9; %low pass filter parameter
  3. L=50 ; % Number of samples used in auto-covariance calculation
  4. clc;
  5. Fs=1000; %sampling rate
  6. Fc=10; % carrier frequency for the dummy signal
  7. t=0:1/Fs:2; %time base
  8. variance = 1; %variance of white noise
  9. %generate a dummy signal
  10. signal=5*sin(2*pi*Fc*t);
  11. % Generate Gaussian White Noise with zero mean and unit variance
  12. whiteNoise=sqrt(variance)*randn(1,length(signal));
  13. %Calculate auto Covariance of the generated white noise L is the number of samples used in autocovariance calculation
  14. [whiteNoiseCov,lags] = xcov(whiteNoise,L);
  15. %Frequency domain representation of noise
  16. NFFT = 2^nextpow2(length(noise));
  17. whiteNoiseSpectrum = fft(noise,NFFT)/length(noise);
  18. f = Fs/2*linspace(0,1,NFFT/2+1);
  19. %Colored Noise Generation
  20. x=whiteNoise;
  21. %First Order Low pass filter y(n)=a*y(n-1)+(1-a)*x(n)
  22. %Filter Transfer function Y(Z) = X(Z)*(1-a)/(1-aZ^-1)
  23. [y zf]=filter(1-a,[1 -a],x);
  24. coloredNoise = y;
  25. [coloredNoiseCov,lags] = xcov(coloredNoise,L);
  26. NFFT = 2^nextpow2(length(coloredNoise));
  27. coloredNoiseSpectrum = fft(coloredNoise,NFFT)/length(coloredNoise);
  28. f = Fs/2*linspace(0,1,NFFT/2+1);
  29. %plotting commands
  30. figure(1);
  31. subplot(3,1,1);
  32. plot(t,whiteNoise);
  33. title('Additive White Gaussian Noise');
  34. xlabel('Time (s)');
  35. ylabel('Amplitude');
  36. subplot(3,1,2);
  37. stem(lags,whiteNoiseCov/max(whiteNoiseCov));
  38. title('Normalized AutoCovariance of AWGN noise');
  39. xlabel('Lag [samples]');
  40. subplot(3,1,3);
  41. stem(f,2*abs(whiteNoiseSpectrum(1:NFFT/2+1)))
  42. title('Frequency Domain representation of AWGN');
  43. xlabel('Frequency (Hz)')
  44. ylabel('|Y(f)|')
  45. figure(2);
  46. subplot(3,1,1);
  47. plot(t,coloredNoise);
  48. title('Colored Noise');
  49. xlabel('Time (s)');
  50. ylabel('Amplitude');
  51. subplot(3,1,2);
  52. stem(lags,coloredNoiseCov/max(coloredNoiseCov));
  53. title('Normalized AutoCovariance of Colored Noise');
  54. xlabel('Lag [samples]');
  55. subplot(3,1,3);
  56. stem(f,2*abs(coloredNoiseSpectrum(1:NFFT/2+1)))
  57. title('Frequency Domain representation of Colored Noise');
  58. xlabel('Frequency (Hz)')
  59. ylabel('|Y(f)|')
  60.  
  61. mean_color = mean(coloredNoise)
  62.  
  63. mean_whitenoise = mean(x)
Add Comment
Please, Sign In to add comment