You are on page 1of 3

# Written in python(x,y) : Main code

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


Created on Sun Sep 21 15:42:30 2014
@author: Anish
"""
import os
os.system('cls')
import numpy as np
import matplotlib.pyplot as plt
import BasicSignals01
N = 100
t = np.linspace(-5, 5, num=N)
ymat = np.zeros([4,N])
ymat[0,:] = BasicSignals01.fn_ramp(t,3,3)
ymat[1,:] = BasicSignals01.fn_ramp(t,-6,1)
ymat[2,:] = BasicSignals01.fn_ramp(t,3,0)
ymat[3,:] = -3*BasicSignals01.fn_ustep(t,-3)
#y4 = -3*Y4
y = [sum(x) for x in zip(*ymat)]
figure(1)
i=1
while i <= 4:
subplot(4,1,i)
plot(t,ymat[i-1,:])
i=i+1
figure(2)
plt.plot(t,y,'r')
plt.xlabel('time')
plt.ylabel('Total Signal')
#------------------------------------------------------------------------------------------------------------------# Functions coded in a separate module BasicSignals01.py
# -*- coding: utf-8 -*"""
Created on Sun Sep 21 15:44:07 2014
@author: Anish
"""

import numpy as np
def fn_ramp(t,m,ad):
N = len(t)
y = np.zeros(N)
for i in range(1,N):
if t[i] >= -ad:
y[i] = m*(t[i]+ad)
return y
def fn_ustep(t,ad):
N = len(t)
y = np.zeros(N)
for i in range(1,N):
if t[i] >= -ad:
y[i] = 1
return y
#------------------------------------------------------------------------------------------------------------------Results

Figure 1: Signal Components: y_1(t) to y_4(t)

Figure 2: Total signal y(t)

You might also like