-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab11.py
More file actions
121 lines (100 loc) · 3.41 KB
/
Lab11.py
File metadata and controls
121 lines (100 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 19:15:38 2019
@author: holt3393
"""
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig
numZ = [2,-40]
denZ = [1,-10,16]
Z, P, K = sig.residuez(numZ,denZ)
print(Z,P,K)
#%% Zplane function
#
# Copyright (c) 2011 Christopher Felton
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# The following is derived from the slides presented by
# Alexander Kain for CS506/606 "Special Topics: Speech Signal Processing"
# CSLU / OHSU, Spring Term 2011.
#
#
#
# Modified by Drew Owens in Fall 2018 for use in the University of Idaho's
# Department of Electrical and Computer Engineering Signals and Systems I Lab
# (ECE 351)
#
# Modified by Morteza Soltani in Spring 2019 for use in the ECE 351 of the U of
# I.
#
# Modified by Phillip Hagen in Fall 2019 for use in the University of Idaho's
# Department of Electrical and Computer Engineering Signals and Systems I Lab
# (ECE 351)
def zplane(b,a,filename=None):
"""Plot the complex z-plane given a transfer function.
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches
# get a figure/plot
ax = plt.subplot(111)
# create the unit circle
uc = patches.Circle((0,0), radius=1, fill=False,
color='black', ls='dashed')
ax.add_patch(uc)
# The coefficients are less than 1, normalize the coeficients
if np.max(b) > 1:
kn = np.max(b)
b = np.array(b)/float(kn)
else:
kn = 1
if np.max(a) > 1:
kd = np.max(a)
a = np.array(a)/float(kd)
else:
kd = 1
# Get the poles and zeros
p = np.roots(a)
z = np.roots(b)
k = kn/float(kd)
# Plot the zeros and set marker properties
t1 = plt.plot(z.real, z.imag, 'o', ms=10,label='Zeros')
plt.setp( t1, markersize=10.0, markeredgewidth=1.0)
# Plot the poles and set marker properties
t2 = plt.plot(p.real, p.imag, 'x', ms=10,label='Poles')
plt.setp( t2, markersize=12.0, markeredgewidth=3.0)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.legend()
# set the ticks
# r = 1.5; plt.axis('scaled'); plt.axis([-r, r, -r, r])
# ticks = [-1, -.5, .5, 1]; plt.xticks(ticks); plt.yticks(ticks)
if filename is None:
plt.show()
else:
plt.savefig(filename)
return z, p, k
zplane(numZ,denZ)
w, h = sig.freqz(numZ, denZ, whole = True)
plt.figure(figsize=(10,7))
plt.plot(w/np.pi, 20*np.log10(np.abs(h)))
plt.grid()
plt.figure(figsize=(10,7))
plt.plot(w/np.pi, np.angle(h))
plt.grid()
plt.show()