Advertisement
RybaSG

sin

Oct 16th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. clear;
  2. clc;
  3. Fs = 50000;         %sampling freq
  4. f1 = 1000;          %signal freq
  5.  
  6. N = Fs / f1;        % samples
  7. n = 0:N-1;          % sample number
  8.  
  9. x = sin( 2*pi*(f1/Fs)*n );
  10.  
  11. %subplot(2,1,1); plot( n/Fs, x, '-*');  % n/Fs - signal freq
  12. %subplot(2,1,2); plot( n, x, '-*');
  13.  
  14. for i = n+1
  15.    
  16.     if ( n(i) < 30 )
  17.         x = sin( 2*pi*(f1/Fs)*n );
  18.     end
  19.    
  20.     if ( n(i) > 30 )
  21.         x(i) = 1;
  22.     end
  23.    
  24.     if ( n(i) > 40 )
  25.         x(i) = 0;
  26.     end
  27.    
  28. end
  29.  
  30. plot(n,x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement