Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GDET3-Demos
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IENT
GDET3-Demos
Commits
1bdfc789
Commit
1bdfc789
authored
4 years ago
by
Hafiz Emin Kosar
Browse files
Options
Downloads
Patches
Plain Diff
- laplace and z-transform demos: added drag functionality for poles/zeros
parent
818172a4
No related branches found
No related tags found
1 merge request
!6
New DFT demo and minor changes in Laplace/z-Transform demo
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/laplace/laplace_plot.py
+73
-15
73 additions, 15 deletions
src/laplace/laplace_plot.py
src/z_transform/z_transform.py
+75
-14
75 additions, 14 deletions
src/z_transform/z_transform.py
with
148 additions
and
29 deletions
src/laplace/laplace_plot.py
+
73
−
15
View file @
1bdfc789
...
...
@@ -25,7 +25,7 @@ class pzPoint():
def
clear
(
self
):
if
self
.
h_point
is
not
None
:
self
.
h_point
.
remove
();
self
.
h_point
=
None
if
self
.
h_point_conj
is
not
None
:
self
.
h_point_conj
.
remove
();
self
.
h_point_conj
=
None
if
self
.
h_order
is
not
None
:
self
.
h_order
.
remove
();
self
.
h_order
=
None
if
self
.
h_order
is
not
None
:
self
.
h_order
[
0
].
remove
();
self
.
h_order
[
1
]
.
remove
();
self
.
h_order
=
None
class
pzPlot
():
...
...
@@ -106,26 +106,84 @@ class pzPlot():
self
.
ax
.
set_title
(
'
Pol- /Nullstellen Diagramm
'
,
fontsize
=
'
12
'
)
self
.
ax
.
set_aspect
(
'
equal
'
,
adjustable
=
'
datalim
'
)
def
onclick
(
event
):
if
self
.
action
==
'
add
'
and
event
.
key
==
'
shift
'
:
self
.
action
=
'
del
'
# * move indicates whether a drag is happening
# * selected_coords indicates selected coords when button is pressed
# * ghost_hpoint, ghost_hpoint_conj are the half transparent poles/zeroes to indicate where the newly created will be
self
.
move
=
False
self
.
selected_coords
=
None
self
.
ghost_hpoint
=
None
self
.
ghost_hpoint_conj
=
None
def
on_btn_press
(
event
):
if
event
.
inaxes
!=
self
.
ax
:
return
if
self
.
filter
!=
'
man
'
:
return
p
=
event
.
xdata
+
1j
*
event
.
ydata
self
.
update_point
(
p
,
self
.
mode
)
def
onkeypress
(
event
):
self
.
action_locked
=
True
if
self
.
action
==
'
del
'
else
False
self
.
w_action_type
.
children
[
0
].
value
=
'
Löschen
'
# button press, reset move
self
.
move
=
False
def
onkeyrelease
(
event
):
if
not
self
.
action_locked
:
self
.
w_action_type
.
children
[
0
].
value
=
'
Hinzufügen
'
# find closest point and set selected if there are any valid points nearby
p
=
event
.
xdata
+
1j
*
event
.
ydata
self
.
selected_coords
=
p
def
on_btn_release
(
event
):
# press + no movement + release = click
if
not
self
.
move
:
on_click
(
event
)
# press + movement + release = drag
# if dragging process is finished
if
self
.
move
and
self
.
find_closest_point
(
self
.
selected_coords
,
self
.
mode
)[
0
]
is
not
None
:
# release move
self
.
move
=
False
# remove any ghosts from the figure and clear variables
if
self
.
ghost_hpoint
is
not
None
:
self
.
ghost_hpoint
.
remove
()
self
.
ghost_hpoint_conj
.
remove
()
self
.
ghost_hpoint
=
None
self
.
ghost_hpoint_conj
=
None
# delete at press selected point
tmp_action
=
self
.
action
self
.
action
=
'
del
'
self
.
update_point
(
self
.
selected_coords
,
self
.
mode
)
# add new point at drag point
self
.
action
=
'
add
'
on_click
(
event
)
self
.
action
=
tmp_action
def
on_motion
(
event
):
# if button is pressed
if
event
.
button
==
1
:
# lock move
self
.
move
=
True
# if a point was selected
if
self
.
find_closest_point
(
self
.
selected_coords
,
self
.
mode
)[
0
]
is
not
None
:
if
self
.
ghost_hpoint
is
None
:
# draw ghost point
if
self
.
mode
==
'
p
'
:
plotstyle
=
rwth_plots
.
style_poles
else
:
plotstyle
=
rwth_plots
.
style_zeros
self
.
ghost_hpoint
,
=
self
.
ax
.
plot
(
event
.
xdata
,
event
.
ydata
,
**
plotstyle
,
alpha
=
.
5
)
if
np
.
abs
(
event
.
ydata
)
>
0
:
# plot complex conjugated poles/zeroes
self
.
ghost_hpoint_conj
,
=
self
.
ax
.
plot
(
event
.
xdata
,
-
event
.
ydata
,
**
plotstyle
,
alpha
=
.
5
)
else
:
self
.
ghost_hpoint
.
set_data
(
event
.
xdata
,
event
.
ydata
)
self
.
ghost_hpoint_conj
.
set_data
(
event
.
xdata
,
-
event
.
ydata
)
def
on_click
(
event
):
# update point
p
=
event
.
xdata
+
1j
*
event
.
ydata
self
.
update_point
(
p
,
self
.
mode
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
on
click
)
self
.
fig
.
canvas
.
mpl_connect
(
'
key_press_event
'
,
onkeypress
)
self
.
fig
.
canvas
.
mpl_connect
(
'
key_release_event
'
,
onkeyrelease
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
on
_btn_press
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_release_event
'
,
on_btn_release
)
self
.
fig
.
canvas
.
mpl_connect
(
'
motion_notify_event
'
,
on_motion
)
self
.
handles
[
'
axh
'
]
=
plt
.
subplot
(
gs
[
0
,
1
])
self
.
handles
[
'
axh
'
].
set_title
(
'
Impulsantwort
'
,
fontsize
=
'
12
'
)
...
...
This diff is collapsed.
Click to expand it.
src/z_transform/z_transform.py
+
75
−
14
View file @
1bdfc789
...
...
@@ -25,7 +25,7 @@ class pzPoint():
def
clear
(
self
):
if
self
.
h_point
is
not
None
:
self
.
h_point
.
remove
();
self
.
h_point
=
None
if
self
.
h_point_conj
is
not
None
:
self
.
h_point_conj
.
remove
();
self
.
h_point_conj
=
None
if
self
.
h_order
is
not
None
:
self
.
h_order
.
remove
();
self
.
h_order
=
None
if
self
.
h_order
is
not
None
:
self
.
h_order
[
0
].
remove
();
self
.
h_order
[
1
]
.
remove
();
self
.
h_order
=
None
class
zPlot
():
...
...
@@ -103,26 +103,87 @@ class zPlot():
self
.
ax
.
set_title
(
'
Pol- /Nullstellen Diagramm
'
,
fontsize
=
'
12
'
)
self
.
ax
.
set_aspect
(
'
equal
'
)
def
onclick
(
event
):
if
self
.
action
==
'
add
'
and
event
.
key
==
'
shift
'
:
self
.
action
=
'
del
'
# * move indicates whether a drag is happening
# * selected_coords indicates selected coords when button is pressed
# * ghost_hpoint, ghost_hpoint_conj are the half transparent poles/zeroes to indicate where the newly created will be
self
.
move
=
False
self
.
selected_coords
=
None
self
.
ghost_hpoint
=
None
self
.
ghost_hpoint_conj
=
None
def
on_btn_press
(
event
):
if
event
.
inaxes
!=
self
.
ax
:
return
if
self
.
filter
!=
'
man
'
:
return
# button press, reset move
self
.
move
=
False
# find closest point and set selected if there are any valid points nearby
p
=
event
.
xdata
+
1j
*
event
.
ydata
self
.
update_point
(
p
,
self
.
mode
)
self
.
selected_coords
=
p
def
on_btn_release
(
event
):
# press + no movement + release = click
if
not
self
.
move
:
on_click
(
event
)
# press + movement + release = drag
# if dragging process is finished
if
self
.
move
and
self
.
find_closest_point
(
self
.
selected_coords
,
self
.
mode
)[
0
]
is
not
None
:
# release move
self
.
move
=
False
# remove any ghosts from the figure and clear variables
if
self
.
ghost_hpoint
is
not
None
:
self
.
ghost_hpoint
.
remove
()
self
.
ghost_hpoint_conj
.
remove
()
self
.
ghost_hpoint
=
None
self
.
ghost_hpoint_conj
=
None
# delete at press selected point
tmp_action
=
self
.
action
self
.
action
=
'
del
'
self
.
update_point
(
self
.
selected_coords
,
self
.
mode
)
# add new point at drag point
self
.
action
=
'
add
'
on_click
(
event
)
self
.
action
=
tmp_action
def
on_motion
(
event
):
# if button is pressed
if
event
.
button
==
1
:
# lock move
self
.
move
=
True
# if a point was selected
if
self
.
find_closest_point
(
self
.
selected_coords
,
self
.
mode
)[
0
]
is
not
None
:
if
self
.
ghost_hpoint
is
None
:
# draw ghost point
if
self
.
mode
==
'
p
'
:
plotstyle
=
rwth_plots
.
style_poles
else
:
plotstyle
=
rwth_plots
.
style_zeros
self
.
ghost_hpoint
,
=
self
.
ax
.
plot
(
event
.
xdata
,
event
.
ydata
,
**
plotstyle
,
alpha
=
.
5
)
if
np
.
abs
(
event
.
ydata
)
>
0
:
# plot complex conjugated poles/zeroes
self
.
ghost_hpoint_conj
,
=
self
.
ax
.
plot
(
event
.
xdata
,
-
event
.
ydata
,
**
plotstyle
,
alpha
=
.
5
)
else
:
self
.
ghost_hpoint
.
set_data
(
event
.
xdata
,
event
.
ydata
)
self
.
ghost_hpoint_conj
.
set_data
(
event
.
xdata
,
-
event
.
ydata
)
def
on
keypress
(
event
):
self
.
action_locked
=
self
.
action
==
'
del
'
self
.
w_action_type
.
children
[
0
].
value
=
'
Löschen
'
def
on
_click
(
event
):
if
self
.
filter
!=
'
man
'
:
return
if
event
.
inaxes
!=
self
.
ax
:
return
def
onkeyrelease
(
event
):
if
not
self
.
action_locked
:
self
.
w_action_type
.
children
[
0
].
value
=
'
Hinzufügen
'
# update point
p
=
event
.
xdata
+
1j
*
event
.
ydata
self
.
update_point
(
p
,
self
.
mode
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
on
click
)
self
.
fig
.
canvas
.
mpl_connect
(
'
key_press_event
'
,
onkeypress
)
self
.
fig
.
canvas
.
mpl_connect
(
'
key_release_event
'
,
onkeyrelease
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
on
_btn_press
)
self
.
fig
.
canvas
.
mpl_connect
(
'
button_release_event
'
,
on_btn_release
)
self
.
fig
.
canvas
.
mpl_connect
(
'
motion_notify_event
'
,
on_motion
)
self
.
handles
[
'
axh
'
]
=
plt
.
subplot
(
gs
[
0
,
1
])
self
.
handles
[
'
axh
'
].
set_xlim
(
-
15
,
15
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment