Advertisement
Alisator

Uloha1_ANS_FEL

Sep 24th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.39 KB | None | 0 0
  1. echo off
  2. clc
  3. clear all
  4. close all
  5. %generate sin_ with Gaussian noise
  6. SNRdb = 3;
  7. SNR = 0;
  8. FS = 8000;
  9. F = 1;
  10. To = 0.25;
  11. t = 0:1/FS:To-1/FS;
  12. meanHelp = [];
  13. powerHelp = [];
  14. figure();
  15. %----
  16. sin_ = sin(2*pi*F*t); %clear sinus
  17. gauss_ = randn(size(sin_));
  18. Psin = mean(sin_.^2, 2);
  19. Pnoise = mean(gauss_.^2, 2);
  20. %normalization
  21. SNR = 10^(-SNRdb/10);
  22. gauss_ = gauss_ * sqrt(Psin) / sqrt(Pnoise)/SNR;
  23. sin_gaus = sin_ + gauss_; %mixed sin with noise
  24.  
  25. countBlocks = 10;
  26. lengthBlock = floor(length(sin_gaus)/countBlocks);
  27.  
  28. for i = 1:countBlocks
  29.   j = (i-1)*lengthBlock + 1;
  30.   k = j + lengthBlock - 1;
  31.   vectHelp = sin_gaus(j:k);
  32.   mean_ = mean(vectHelp);
  33.   power = mean(vectHelp.^2);    
  34.   meanHelp = [meanHelp, mean_];
  35.   powerHelp = [powerHelp, power];
  36. end
  37. meanHelp = ones(lengthBlock,1)  * meanHelp;
  38. meanHelp = meanHelp(:)';
  39. powerHelp = ones(lengthBlock,1)  * powerHelp;
  40. powerHelp = powerHelp(:)';
  41. %plot
  42. subplot(2,1,1);
  43. plot(t, sin_gaus, t, meanHelp, t, powerHelp);
  44. xlabel('t[s]');
  45. ylabel('|A|');
  46. legend('sinus with noise', 'mean', 'power')
  47. title('sinus 1Hz with Gaussian noise, SNR 3dB');
  48.  
  49. %generate oscillation sinus
  50. Flow = 10;
  51. FS = 8000;
  52. Fhigh = 400;
  53. To = 0.02;
  54. t = 0:1/FS:To-1/FS;
  55. %--------
  56. k = (Fhigh-Flow)/To;
  57. F = k*t+Flow; %vector of frequencies
  58. sin_ = sin(2*pi*F.*t);
  59. %plot
  60. subplot(2,1,2);
  61. plot(t,sin_);
  62. xlabel('t[s]');
  63. ylabel('|A|');
  64. title('oscillation sinus');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement