<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://fbswiki.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Figure_6.13%3A_AFM_frequency_response</id>
	<title>Figure 6.13: AFM frequency response - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://fbswiki.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Figure_6.13%3A_AFM_frequency_response"/>
	<link rel="alternate" type="text/html" href="http://fbswiki.org/wiki/index.php?title=Figure_6.13:_AFM_frequency_response&amp;action=history"/>
	<updated>2026-04-24T21:52:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>http://fbswiki.org/wiki/index.php?title=Figure_6.13:_AFM_frequency_response&amp;diff=1365&amp;oldid=prev</id>
		<title>Murray at 06:09, 19 February 2025</title>
		<link rel="alternate" type="text/html" href="http://fbswiki.org/wiki/index.php?title=Figure_6.13:_AFM_frequency_response&amp;diff=1365&amp;oldid=prev"/>
		<updated>2025-02-19T06:09:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 06:09, 19 February 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l68&quot; &gt;Line 68:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 68:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;omega = np.logspace(4, 7, 10000)  # Frequency range from 10^4 to 10^7 rad/s&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;omega = np.logspace(4, 7, 10000)  # Frequency range from 10^4 to 10^7 rad/s&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;freqresp = ct.frequency_response(sys, omega)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;freqresp = ct.frequency_response(sys, omega)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;mag, phase = freqresp.magnitude&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[0, 0]&lt;/del&gt;, freqresp.phase&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[0, 0]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;mag, phase = freqresp.magnitude, freqresp.phase&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Create the Bode plot&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Create the Bode plot&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Murray</name></author>
	</entry>
	<entry>
		<id>http://fbswiki.org/wiki/index.php?title=Figure_6.13:_AFM_frequency_response&amp;diff=1359&amp;oldid=prev</id>
		<title>Murray: Created page with &quot;{{Figure |Chapter=Linear Systems |Figure number=6.13 |Sort key=613 |Figure title=AFM frequency response |GitHub URL=https://github.com/murrayrm/fbs2e-python/blob/main/example-...&quot;</title>
		<link rel="alternate" type="text/html" href="http://fbswiki.org/wiki/index.php?title=Figure_6.13:_AFM_frequency_response&amp;diff=1359&amp;oldid=prev"/>
		<updated>2024-11-28T19:21:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Figure |Chapter=Linear Systems |Figure number=6.13 |Sort key=613 |Figure title=AFM frequency response |GitHub URL=https://github.com/murrayrm/fbs2e-python/blob/main/example-...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Figure&lt;br /&gt;
|Chapter=Linear Systems&lt;br /&gt;
|Figure number=6.13&lt;br /&gt;
|Sort key=613&lt;br /&gt;
|Figure title=AFM frequency response&lt;br /&gt;
|GitHub URL=https://github.com/murrayrm/fbs2e-python/blob/main/example-6.9-afm_freqresp.py&lt;br /&gt;
}}&lt;br /&gt;
[[Image:figure-6.13-afm_freqresp.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 6.13:''' AFM frequency response. (a) A block diagram for the vertical dynamics of an atomic force microscope in contact mode [not shown]. The plot in (b) shows the gain and phase for the piezo stack. The response contains two frequency peaks at resonances of the system, along with an antiresonance at &amp;lt;math&amp;gt;\omega = 268&amp;lt;/math&amp;gt; krad/s. The combination of a resonant peak followed by an antiresonance is common for systems with multiple lightly damped modes. The dashed horizontal line represents the gain equal to the zero frequency gain divided by &amp;lt;math&amp;gt;\sqrt{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# example-6.9-afm_freqresp.py - &amp;lt;Short description&amp;gt;&lt;br /&gt;
# RMM, 28 Nov 2024&lt;br /&gt;
#&lt;br /&gt;
# Figure 6.13: AFM frequency response. (a) A block diagram for the vertical&lt;br /&gt;
# dynamics of an atomic force microscope in contact mode. The plot in (b)&lt;br /&gt;
# shows the gain and phase for the piezo stack. The response contains two&lt;br /&gt;
# frequency peaks at resonances of the system, along with an antiresonance&lt;br /&gt;
# at ω = 268 krad/s.  The combination of a resonant peak followed by an&lt;br /&gt;
# antiresonance is common for systems with multiple lightly damped&lt;br /&gt;
# modes. The dashed horizontal line represents the gain equal to the zero&lt;br /&gt;
# frequency gain divided by sqrt(2).&lt;br /&gt;
&lt;br /&gt;
import control as ct&lt;br /&gt;
import numpy as np&lt;br /&gt;
import matplotlib.pyplot as plt&lt;br /&gt;
from math import sqrt&lt;br /&gt;
ct.use_fbs_defaults()&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# System dynamics&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# System parameters&lt;br /&gt;
m1 = 0.15e-3&lt;br /&gt;
m2 = 1e-3&lt;br /&gt;
f1 = 40.9e3&lt;br /&gt;
f2 = 41.6e3&lt;br /&gt;
f3 = 120e3&lt;br /&gt;
&lt;br /&gt;
# Derived quantities&lt;br /&gt;
w1 = 2 * np.pi * f1&lt;br /&gt;
w2 = 2 * np.pi * f2&lt;br /&gt;
w3 = 2 * np.pi * f3&lt;br /&gt;
z1 = 0.1&lt;br /&gt;
z3 = 0.1&lt;br /&gt;
k2 = w2**2 * m2&lt;br /&gt;
c2 = m2 * z1 * w1&lt;br /&gt;
&lt;br /&gt;
# System matrices&lt;br /&gt;
A = np.array([[0, 1, 0, 0],&lt;br /&gt;
              [-k2 / (m1 + m2), -c2 / (m1 + m2), 1 / m2, 0],&lt;br /&gt;
              [0, 0, 0, 1],&lt;br /&gt;
              [0, 0, -w3**2, -2 * z3 * w3]])&lt;br /&gt;
B = np.array([[0], [0], [0], [w3**2]])&lt;br /&gt;
C = (m2 / (m1 + m2)) * np.array([m1 * k2 / (m1 + m2), m1 * c2 / (m1 + m2), 1, 0])&lt;br /&gt;
D = np.array([[0]])&lt;br /&gt;
&lt;br /&gt;
# Create the state-space system&lt;br /&gt;
sys = ct.ss(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# (b) Frequency response&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Generate the frequency response&lt;br /&gt;
omega = np.logspace(4, 7, 10000)  # Frequency range from 10^4 to 10^7 rad/s&lt;br /&gt;
freqresp = ct.frequency_response(sys, omega)&lt;br /&gt;
mag, phase = freqresp.magnitude[0, 0], freqresp.phase[0, 0]&lt;br /&gt;
&lt;br /&gt;
# Create the Bode plot&lt;br /&gt;
cplt = freqresp.plot()&lt;br /&gt;
mag_ax, phase_ax = cplt.axes[:, 0]&lt;br /&gt;
cplt.set_plot_title(&amp;quot;(b) Frequency response&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Locate peaks and valleys&lt;br /&gt;
# Find the first peak&lt;br /&gt;
max_mag = 0&lt;br /&gt;
omega1 = None&lt;br /&gt;
for i, m in enumerate(mag):&lt;br /&gt;
    if m &amp;gt; max_mag:&lt;br /&gt;
        max_mag = m&lt;br /&gt;
        omega1 = omega[i]&lt;br /&gt;
    elif m &amp;lt; max_mag:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
# Find the first valley&lt;br /&gt;
min_mag = max_mag&lt;br /&gt;
omega2 = None&lt;br /&gt;
for i, m in enumerate(mag):&lt;br /&gt;
    if m &amp;lt; min_mag:&lt;br /&gt;
        min_mag = m&lt;br /&gt;
        omega2 = omega[i]&lt;br /&gt;
    elif m &amp;gt; min_mag:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
# Find the second peak (must be higher than first)&lt;br /&gt;
omega3 = None&lt;br /&gt;
for i, m in enumerate(mag):&lt;br /&gt;
    if m &amp;gt; max_mag:&lt;br /&gt;
        max_mag = m&lt;br /&gt;
        omega3 = omega[i]&lt;br /&gt;
    elif m &amp;lt; max_mag and omega3 is not None:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
# Print peaks and valley frequencies&lt;br /&gt;
print(f&amp;quot;Peaks at {omega1:.2e}, {omega3:.2e}; valley at {omega2:.2e}&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Add lines to mark the frequencies&lt;br /&gt;
mag_ax.axhline(1 / sqrt(2), color='r', linestyle='--', linewidth=0.5)&lt;br /&gt;
&lt;br /&gt;
mag_ax.axvline(omega1, color='k', linestyle='--', linewidth=0.5)&lt;br /&gt;
mag_ax.text(omega1 * 1.1, 2, r&amp;quot;$M_{r1}$&amp;quot;)&lt;br /&gt;
mag_ax.text(omega1 * 1.1, 0.07, r&amp;quot;$\omega = \omega_{r1}$&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
mag_ax.axvline(omega3, color='k', linestyle='--', linewidth=0.5)&lt;br /&gt;
mag_ax.text(omega3 * 1.2, 3, r&amp;quot;$M_{r2}$&amp;quot;)&lt;br /&gt;
mag_ax.text(omega3 * 1.1, 0.07, r&amp;quot;$\omega = \omega_{r2}$&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
phase_ax.axvline(omega1, color='k', linestyle='--', linewidth=0.5)&lt;br /&gt;
phase_ax.axvline(omega3, color='k', linestyle='--', linewidth=0.5)&lt;br /&gt;
&lt;br /&gt;
# Save the figure&lt;br /&gt;
plt.savefig(&amp;quot;figure-6.9-afm_freqresp.png&amp;quot;, bbox_inches='tight')&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Murray</name></author>
	</entry>
</feed>