Skip to content

Commit 3b6de2f

Browse files
committed
reworked feature selection for discrete systems
1 parent e2e24a5 commit 3b6de2f

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ build.log
1313
doc/_build
1414
doc/generated
1515

16-
examples/.ipynb_checkpoints/bode-plot-checkpoint.ipynb
16+
examples/.ipynb_checkpoints/
1717
.settings/org.eclipse.core.resources.prefs
1818
.pydevproject
19-
.project
19+
.project
20+
Untitled*.ipynb

control/freqplot.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,26 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
442442
try:
443443
# Add new features to the list
444444
if sys.isctime():
445-
features_ = np.abs(sys.pole())
446-
features_ = np.concatenate((features_, np.abs(sys.zero())))
445+
features_ = np.concatenate((np.abs(sys.pole()),
446+
np.abs(sys.zero())))
447447
# Get rid of poles and zeros at the origin
448448
features_ = features_[features_ != 0.0];
449449
features = np.concatenate((features, features_))
450450
elif sys.isdtime(strict=True):
451451
fn = np.pi * 1. / sys.dt
452-
#TODO: What distance to the Nyquist frequency is appropriate?
453-
freq_interesting.append(fn*0.9)
454-
p = sys.pole()
455-
p = p[p != -1.]
456-
features = np.concatenate((features, np.abs(np.log(p) / sys.dt)))
457-
z = sys.zero()
458-
z = z[(z.imag != 0.0)] # Get rid of poles and zeros at the origin and real <= 0 & imag==0
459-
features = np.concatenate((features, np.abs(np.log(z) / sys.dt)))
452+
# TODO: What distance to the Nyquist frequency is appropriate?
453+
freq_interesting.append(fn * 0.9)
454+
455+
features_ = np.concatenate((sys.pole(),
456+
sys.zero()))
457+
# Get rid of poles and zeros
458+
# * at the origin and real <= 0 & imag==0: log!
459+
# * at 1.: would result in omega=0. (logaritmic plot!)
460+
features_ = features_[(features_.imag != 0.0) | (features_.real > 0.)]
461+
features_ = features_[np.bitwise_not((features_.imag == 0.0) & (np.abs(features_.real - 1.0) < 1.e-10))]
462+
# TODO: improve
463+
features__ = np.abs(np.log(features_) / (1.j * sys.dt))
464+
features = np.concatenate((features, features__))
460465
else:
461466
# TODO
462467
raise NotImplementedError('type of system in not implemented now')
@@ -466,7 +471,7 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
466471

467472
# Make sure there is at least one point in the range
468473
if (features.shape[0] == 0):
469-
features = [1];
474+
features = np.array([1]);
470475

471476
if Hz:
472477
features /= 2.*np.pi

examples/bode-plot.ipynb

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:2416b0175371454a997b2a6cd448368a26e5913058bba72d188ec84dd29a7784"
4+
"signature": "sha256:bb8169741807e084dda69a0ed35f00bb23568ea1695b9268b1208f4b57b73508"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -1137,7 +1137,7 @@
11371137
"metadata": {},
11381138
"output_type": "display_data",
11391139
"text": [
1140-
"<IPython.core.display.Javascript at 0x11db1d50>"
1140+
"<IPython.core.display.Javascript at 0x13181e70>"
11411141
]
11421142
},
11431143
{
@@ -1147,7 +1147,7 @@
11471147
"metadata": {},
11481148
"output_type": "display_data",
11491149
"text": [
1150-
"<IPython.core.display.HTML at 0x11dd74d0>"
1150+
"<IPython.core.display.HTML at 0x131ae630>"
11511151
]
11521152
}
11531153
],
@@ -1934,7 +1934,7 @@
19341934
"metadata": {},
19351935
"output_type": "display_data",
19361936
"text": [
1937-
"<IPython.core.display.Javascript at 0x11db1e10>"
1937+
"<IPython.core.display.Javascript at 0x13090ab0>"
19381938
]
19391939
},
19401940
{
@@ -1944,7 +1944,7 @@
19441944
"metadata": {},
19451945
"output_type": "display_data",
19461946
"text": [
1947-
"<IPython.core.display.HTML at 0x11f3db10>"
1947+
"<IPython.core.display.HTML at 0x132e2c70>"
19481948
]
19491949
}
19501950
],
@@ -2735,7 +2735,7 @@
27352735
"metadata": {},
27362736
"output_type": "display_data",
27372737
"text": [
2738-
"<IPython.core.display.Javascript at 0x11db1ed0>"
2738+
"<IPython.core.display.Javascript at 0x131ae050>"
27392739
]
27402740
},
27412741
{
@@ -2745,7 +2745,7 @@
27452745
"metadata": {},
27462746
"output_type": "display_data",
27472747
"text": [
2748-
"<IPython.core.display.HTML at 0x120449d0>"
2748+
"<IPython.core.display.HTML at 0x133e9b10>"
27492749
]
27502750
}
27512751
],
@@ -3532,7 +3532,7 @@
35323532
"metadata": {},
35333533
"output_type": "display_data",
35343534
"text": [
3535-
"<IPython.core.display.Javascript at 0x11db1c30>"
3535+
"<IPython.core.display.Javascript at 0x131ae730>"
35363536
]
35373537
},
35383538
{
@@ -3542,7 +3542,7 @@
35423542
"metadata": {},
35433543
"output_type": "display_data",
35443544
"text": [
3545-
"<IPython.core.display.HTML at 0x1214ced0>"
3545+
"<IPython.core.display.HTML at 0x13561fb0>"
35463546
]
35473547
}
35483548
],
@@ -4308,7 +4308,7 @@
43084308
"metadata": {},
43094309
"output_type": "display_data",
43104310
"text": [
4311-
"<IPython.core.display.Javascript at 0x11cdae30>"
4311+
"<IPython.core.display.Javascript at 0x131ae070>"
43124312
]
43134313
},
43144314
{
@@ -4318,7 +4318,7 @@
43184318
"metadata": {},
43194319
"output_type": "display_data",
43204320
"text": [
4321-
"<IPython.core.display.HTML at 0x1227ee30>"
4321+
"<IPython.core.display.HTML at 0x13679f70>"
43224322
]
43234323
}
43244324
],
@@ -5073,7 +5073,7 @@
50735073
"metadata": {},
50745074
"output_type": "display_data",
50755075
"text": [
5076-
"<IPython.core.display.Javascript at 0x11cdad70>"
5076+
"<IPython.core.display.Javascript at 0x13090e10>"
50775077
]
50785078
},
50795079
{
@@ -5083,7 +5083,7 @@
50835083
"metadata": {},
50845084
"output_type": "display_data",
50855085
"text": [
5086-
"<IPython.core.display.HTML at 0x12368d10>"
5086+
"<IPython.core.display.HTML at 0x1373be50>"
50875087
]
50885088
}
50895089
],
@@ -5840,7 +5840,7 @@
58405840
"metadata": {},
58415841
"output_type": "display_data",
58425842
"text": [
5843-
"<IPython.core.display.Javascript at 0x12044730>"
5843+
"<IPython.core.display.Javascript at 0x13561cf0>"
58445844
]
58455845
},
58465846
{
@@ -5850,7 +5850,7 @@
58505850
"metadata": {},
58515851
"output_type": "display_data",
58525852
"text": [
5853-
"<IPython.core.display.HTML at 0x124cc4d0>"
5853+
"<IPython.core.display.HTML at 0x138d0610>"
58545854
]
58555855
}
58565856
],
@@ -6616,7 +6616,7 @@
66166616
"metadata": {},
66176617
"output_type": "display_data",
66186618
"text": [
6619-
"<IPython.core.display.Javascript at 0x122e8490>"
6619+
"<IPython.core.display.Javascript at 0x131ae110>"
66206620
]
66216621
},
66226622
{
@@ -6626,7 +6626,7 @@
66266626
"metadata": {},
66276627
"output_type": "display_data",
66286628
"text": [
6629-
"<IPython.core.display.HTML at 0x121a0f70>"
6629+
"<IPython.core.display.HTML at 0x135c3c70>"
66306630
]
66316631
}
66326632
],
@@ -7381,7 +7381,7 @@
73817381
"metadata": {},
73827382
"output_type": "display_data",
73837383
"text": [
7384-
"<IPython.core.display.Javascript at 0x11cdacd0>"
7384+
"<IPython.core.display.Javascript at 0x13679b90>"
73857385
]
73867386
},
73877387
{
@@ -7391,7 +7391,7 @@
73917391
"metadata": {},
73927392
"output_type": "display_data",
73937393
"text": [
7394-
"<IPython.core.display.HTML at 0x14787b90>"
7394+
"<IPython.core.display.HTML at 0x147c0cd0>"
73957395
]
73967396
}
73977397
],
@@ -8149,7 +8149,7 @@
81498149
"metadata": {},
81508150
"output_type": "display_data",
81518151
"text": [
8152-
"<IPython.core.display.Javascript at 0x1246cf90>"
8152+
"<IPython.core.display.Javascript at 0x13870e30>"
81538153
]
81548154
},
81558155
{
@@ -8159,7 +8159,7 @@
81598159
"metadata": {},
81608160
"output_type": "display_data",
81618161
"text": [
8162-
"<IPython.core.display.HTML at 0x148e9df0>"
8162+
"<IPython.core.display.HTML at 0x148c4f30>"
81638163
]
81648164
}
81658165
],
@@ -8907,7 +8907,7 @@
89078907
"metadata": {},
89088908
"output_type": "display_data",
89098909
"text": [
8910-
"<IPython.core.display.Javascript at 0x1246c0b0>"
8910+
"<IPython.core.display.Javascript at 0x138709d0>"
89118911
]
89128912
},
89138913
{
@@ -8917,12 +8917,21 @@
89178917
"metadata": {},
89188918
"output_type": "display_data",
89198919
"text": [
8920-
"<IPython.core.display.HTML at 0x14b2e3f0>"
8920+
"<IPython.core.display.HTML at 0x14b49510>"
89218921
]
89228922
}
89238923
],
89248924
"prompt_number": 32
89258925
},
8926+
{
8927+
"cell_type": "code",
8928+
"collapsed": false,
8929+
"input": [],
8930+
"language": "python",
8931+
"metadata": {},
8932+
"outputs": [],
8933+
"prompt_number": 32
8934+
},
89268935
{
89278936
"cell_type": "code",
89288937
"collapsed": false,

0 commit comments

Comments
 (0)