You are on page 1of 3

# -*- coding: utf-8 -*"""

Created on Tue Sep 16 20:13:07 2014


@author: Anish
"""
import os
os.system('cls')
import numpy as np
import matplotlib.pyplot as plt
#a = 2
#plt.figure(1)
N = 500
nvec11 = np.linspace(1,N,num=N)
nvec2 = nvec11/100
v_t = cos(pi*nvec2)
plt.figure(1)
plt.plot(nvec2,v_t,'b--',label="Input")
x_t = v_t
for t in range(1,N):
if (v_t[t]) >= 0.5:
x_t[t] = 0.5
if v_t[t] < -.5:
x_t[t] = -0.5
plt.plot(nvec2,x_t,'r',label="Output", linewidth=2.0)
plt.xlabel('time')
plt.ylabel('voltage')
plt.xlim(0.02,5)
legend(bbox_to_anchor=(.7, .9), loc=1, borderaxespad=0.)
#plt.legend('input','output')
v_1t = 2.0*cos(pi*nvec2)
v_2t = 2.0*cos(2*pi*nvec2)
v_t_c = .33*v_1t + 0.66*v_2t
plt.figure(2)
plt.plot(nvec2,v_t_c,'b--',label="Input")
x_1t = v_1t
for t in range(1,N):
if (v_1t[t]) > 0.5:
x_1t[t] = 0.5
if v_1t[t] < -.5:
x_1t[t] = -0.5
x_2t = v_2t
for t in range(1,N):
if (v_2t[t]) > 0.5:
x_2t[t] = 0.5
if v_2t[t] < -.5:
x_2t[t] = -0.5
x_t_2 = .33*x_1t + .66*x_2t

x_t_1 = v_t_c
for t in range(1,N):
if (v_t_c[t]) > 0.5:
x_t_1[t] = 0.5
if v_t_c[t] < -.5:
x_t_1[t] = -0.5
plt.plot(nvec2,x_t_1,'r',label="Output 1", linewidth=2.0)
plt.plot(nvec2,x_t_2,'g',label="Output 2", linewidth=2.0)
plt.xlabel('time')
plt.ylabel('voltage')
plt.xlim(0.02,5)
legend(bbox_to_anchor=(.7, .9), loc=1, borderaxespad=0.)

Fig 1. The input and output of a zener diode

Fig 2. The plots illustrating that the zener diode is a non-linear system.

You might also like