Created
          September 26, 2017 13:49 
        
      - 
      
 - 
        
Save linnil1/acd23b613135e3a840b7eca1a1c08f94 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import numpy as np | |
| import matplotlib.pyplot as plt | |
| f = 150 # frequency | |
| period_point = 10 # how many point each sampling interval | |
| period = 50 | |
| sf = 200 * period // f # sampling times | |
| t = np.linspace(0, period * 1 / f, period_point * sf) | |
| fun = 4 * np.sin(100 * np.pi * t) + 4 * np.sin(300 * np.pi * t) | |
| bit = 12 # bits for coding | |
| Q = 8 * 2 / ( 2 ** bit - 1) # quantization interval | |
| ADCout = [] | |
| for i in range(sf): | |
| code = np.floor((fun[i * period_point]) / Q) * Q | |
| ADCout.extend([code] * period_point) | |
| plt.rc('text', usetex=True) | |
| plt.subplot(211) | |
| plt.title(r"4\sin(100\pi t) + 4\sin(300\pi t)") | |
| plt.plot(t, fun) | |
| plt.subplot(212) | |
| plt.title("ADC output with sampling rate 200Hz") | |
| plt.plot(t, ADCout) | |
| # plt.legend() | |
| plt.show() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment