<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2026-11-23T23:55:56+00:00</updated><id>/feed.xml</id><title type="html">Antcating’s Chaos Lab</title><subtitle>My personal blog about science, programming, hacking old technology and other random stuff.</subtitle><entry><title type="html">Getting old Java phones online again (Windows Edition)</title><link href="/2026/11/23/getting-old-java-phones-online-again-windows.html" rel="alternate" type="text/html" title="Getting old Java phones online again (Windows Edition)" /><published>2026-11-23T21:00:00+00:00</published><updated>2026-11-23T21:00:00+00:00</updated><id>/2026/11/23/getting-old-java-phones-online-again-windows</id><content type="html" xml:base="/2026/11/23/getting-old-java-phones-online-again-windows.html"><![CDATA[<figure class="post-figure post-figure--hero">
  <img src="/assets/images/s500i/hero.jpg" alt="Sony Ericsson S500i showing FrogFind" />
  <figcaption>Sony Ericsson S500i accessing FrogFind.</figcaption>
</figure>

<h2 id="background">Background</h2>

<p>After writing <a href="/2026/11/23/getting-old-java-phones-online-again.html">Getting old Java phones online again</a>, I found out that Windows 11 can also act as a Bluetooth Network Access Point (NAP). And, surprisingly, setting it up is even simpler than on Linux!</p>

<p>For technical details about Bluetooth PAN/NAP, configuring the phone, and browsing the Web, please refer to the original post.</p>

<h2 id="getting-online-via-bluetooth">Getting online via Bluetooth</h2>

<h3 id="setting-up-bluetooth-nap-on-windows-11">Setting up Bluetooth NAP on Windows 11</h3>

<p>It turns out that Windows 11 still supports sharing an Internet connection over Bluetooth, and everything can be configured through the Settings app.</p>

<ul>
  <li>
    <p>Open <code class="language-plaintext highlighter-rouge">Settings / Network &amp; internet / Mobile hotspot</code>.</p>
  </li>
  <li>
    <p>Under Share my internet connection from, select the connection you want to share.</p>
  </li>
  <li>
    <p>Set Share over to Bluetooth.</p>
  </li>
  <li>
    <p>Turn on Mobile hotspot.</p>
  </li>
  <li>
    <p>Pair the phone with the computer through <code class="language-plaintext highlighter-rouge">Settings / Bluetooth &amp; devices</code>.</p>
  </li>
</ul>

<p>And that’s pretty much it! Windows now provides the Bluetooth Network Access service, allowing compatible phones to access the Internet through your computer.</p>

<h3 id="connecting-the-s500i">Connecting the S500i</h3>

<p>The phone-side configuration is the same as with Linux.</p>

<ul>
  <li>
    <p>On the S500i, go to <code class="language-plaintext highlighter-rouge">Connectivity / Bluetooth / My devices</code> and select your Windows computer.</p>
  </li>
  <li>
    <p>Browse its available services and look for Network access.</p>
  </li>
  <li>Configure the phone’s Internet profile to use the Bluetooth connection, as described in the original guide.
    <blockquote>
      <p>Note: Start the Sharing before connecting/pairing, otherwise the phone will not be able to use the connection.</p>
    </blockquote>
  </li>
  <li>Open the phone’s browser and try loading <a href="http://frogfind.com">frogfind.com</a>.</li>
</ul>

<p>That’s it! The S500i is online again, this time through Windows.</p>

<p>Again, for discussion on technical details, web browsing and other fun stuff refer to <a href="/2026/11/23/getting-old-java-phones-online-again.html">Getting old Java phones online again</a>.</p>

<p>Have fun and happy hacking!</p>]]></content><author><name></name></author><category term="tech" /><category term="j2me" /><category term="phone" /><category term="bluetooth" /><summary type="html"><![CDATA[Sony Ericsson S500i accessing FrogFind.]]></summary></entry><entry><title type="html">Getting old Java phones online again</title><link href="/2026/11/23/getting-old-java-phones-online-again.html" rel="alternate" type="text/html" title="Getting old Java phones online again" /><published>2026-11-23T12:00:00+00:00</published><updated>2026-11-23T12:00:00+00:00</updated><id>/2026/11/23/getting-old-java-phones-online-again</id><content type="html" xml:base="/2026/11/23/getting-old-java-phones-online-again.html"><![CDATA[<figure class="post-figure post-figure--hero">
  <img src="/assets/images/s500i/hero.jpg" alt="Sony Ericsson S500i showing FrogFind" />
  <figcaption>Sony Ericsson S500i accessing FrogFind.</figcaption>
</figure>

<h2 id="background">Background</h2>

<p>Recently, I bought a used Sony Ericsson S500i – one of the most beautiful phones IMO.
I vividly remember getting online on this phone while away from home and downloading games from the Sony Ericsson shop (and the exorbitant mobile data charges that came with it!).</p>

<p>But when I tried using it again in 2026, I couldn’t connect to the mobile network. Even though I had a SIM card compatible with the phone, 2G had been shut down for some time, leaving no way to access the Internet over a mobile connection.</p>

<p>USB wasn’t an option either. On many phones of this era, USB tethering was designed to share the phone’s Internet connection with a computer, not the other way around<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>. But there is a way…</p>

<h2 id="getting-online-via-bluetooth">Getting online via Bluetooth</h2>

<p>Bluetooth supports various profiles, which define how devices use Bluetooth for specific purposes. One of these is Personal Area Networking (PAN), which allows devices to communicate over Bluetooth as if they were connected to an Ethernet network.</p>

<p>PAN carries Ethernet frames over Bluetooth, including IP traffic. This allows a device acting as a PAN User (PANU) to access the Internet through another device acting as a Network Access Point (NAP). The NAP forwards the traffic to the Internet, much like a Wi-Fi hotspot, but over Bluetooth instead<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup>.</p>

<p>Although Bluetooth PAN is much less common nowadays, many devices still support the profile. One common use case was sharing a phone’s mobile Internet connection with a laptop. But why not reverse the direction? We can use a network-connected computer as a NAP and access the Internet from an old Java phone, provided the phone supports PANU<sup id="fnref:3"><a href="#fn:3" class="footnote" rel="footnote" role="doc-noteref">3</a></sup>.</p>

<h3 id="setting-up-bluetooth-nap-on-raspberry-pi-5">Setting up Bluetooth NAP on Raspberry Pi 5</h3>

<p>From what I’ve seen on forums, many older Sony Ericsson, Nokia, and other phones seem to <strong>support PANU even if it is not mentioned in the documentation</strong>. I couldn’t find any confirmation for the S500i, so I decided to give it a try by setting up a Bluetooth NAP and seeing whether the phone could connect.</p>

<p>I used Linux for this, but I’m sure you Windows and Mac wizards can figure out how to make it work on your systems too.</p>

<blockquote>
  <p>Note: After finishing this blog, I found out that there is a way to do the same thing on Windows, see: <a href="/2026/11/23/getting-old-java-phones-online-again-windows.html">Getting old Java phones online again (Windows Edition)</a>.</p>
</blockquote>

<p>I found an old guide showing how to get a Sony Ericsson K800i online over Bluetooth using Debian Etch<sup id="fnref:3:1"><a href="#fn:3" class="footnote" rel="footnote" role="doc-noteref">3</a></sup>. While the basic idea still works, the guide relies on tools and configurations that are long obsolete. I worked out a different approach using modern BlueZ and NetworkManager, without the old scripts and manual network configuration.</p>

<p>I bought a Raspberry Pi 5 a few years ago to run small services at home, and it turned out to be a great fit for this project. Raspberry Pi boards have had built-in Bluetooth since the Raspberry Pi 3 Model B, so there’s no need for any additional Bluetooth hardware<sup id="fnref:4"><a href="#fn:4" class="footnote" rel="footnote" role="doc-noteref">4</a></sup>.</p>

<p>Modern devices mostly don’t advertise the Bluetooth NAP service by default, so the following steps show how to enable it explicitly.</p>

<blockquote>
  <p>Note: This guide is written for Raspberry Pi OS based on Debian 13 (Trixie), but I also tested the setup on my ThinkPad E14 running Arch Linux, and it worked there too. It should work on any other Linux distribution with BlueZ and NetworkManager, although package installation and service management may differ.</p>
</blockquote>

<ol>
  <li>Install Bluez and NetworkManager (usually, installed by default).
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>apt update
 <span class="nb">sudo </span>apt <span class="nb">install</span> <span class="nt">-y</span> bluez network-manager
</code></pre></div>    </div>
  </li>
  <li>Enable Bluetooth.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>systemctl <span class="nb">enable</span> <span class="nt">--now</span> bluetooth
</code></pre></div>    </div>
  </li>
  <li>Create a Bluetooth NAP profile and share the Internet connection.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>nmcli connection add <span class="se">\</span>
     <span class="nb">type </span>bluetooth <span class="se">\</span>
     con-name <span class="s2">"Bluetooth-NAP"</span> <span class="se">\</span>
     ifname btnap0 <span class="se">\</span>
     bluetooth.type nap <span class="se">\</span>
     ipv4.method shared <span class="se">\</span>
     ipv6.method disabled
</code></pre></div>    </div>
    <p>This configuration enables IPv4 sharing through NetworkManager. The Raspberry Pi acts as a gateway for devices connected over Bluetooth, assigning IP addresses and forwarding their traffic to the Internet. It works with either an Ethernet or Wi-Fi connection.</p>
  </li>
  <li>Activate the created profile.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>nmcli connection up <span class="s2">"Bluetooth-NAP"</span>
</code></pre></div>    </div>
  </li>
  <li>(Optionally) Enable automatic activation on boot.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>nmcli connection modify <span class="s2">"Bluetooth-NAP"</span> connection.autoconnect <span class="nb">yes</span>
</code></pre></div>    </div>
  </li>
  <li>
    <p>Verify that the NAP service is available.</p>

    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bluetoothctl show
</code></pre></div>    </div>

    <p>Look for:</p>

    <div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>UUID: NAP (00001116-0000-1000-8000-00805f9b34fb)
</code></pre></div>    </div>

    <p>This indicates that BlueZ has registered the NAP service.</p>
  </li>
</ol>

<h3 id="connecting-the-s500i">Connecting the S500i</h3>

<ol>
  <li>
    <p>Enable Bluetooth on the phone and make it discoverable.</p>
  </li>
  <li>
    <p>Pair the Raspberry Pi with the phone using bluetoothctl.</p>
    <ul>
      <li>Start the Bluetooth control utility:
        <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  bluetoothctl
</code></pre></div>        </div>
      </li>
      <li>
        <p>Configure the Raspberry Pi to accept pairing requests:</p>

        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  power on
  agent off
  agent KeyboardDisplay
  default-agent
  pairable on
  discoverable on
</code></pre></div>        </div>

        <blockquote>
          <p>Note: Run each command separately in the interactive bluetoothctl prompt</p>
        </blockquote>
      </li>
      <li>Start scanning for nearby Bluetooth devices:
        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  scan on
</code></pre></div>        </div>
      </li>
      <li>
        <p>Look for your phone in the output.</p>

        <p>It should appear under the name configured on the phone. For example:</p>
        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  [NEW] Device 00:23:F1:XX:XX:XX S500i
</code></pre></div>        </div>
      </li>
      <li>Disable the scanning:
        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  scan off
</code></pre></div>        </div>
      </li>
      <li>
        <p>Pair the Raspberry Pi with the phone.</p>

        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  pair 00:23:F1:XX:XX:XX
</code></pre></div>        </div>

        <p>Replace the example address with your phone’s actual Bluetooth address.
  Enter the same PIN on both devices. If everything goes well, bluetoothctl will report that pairing was successful.</p>
      </li>
      <li>
        <p>Mark the phone as trusted on the Raspberry Pi:</p>

        <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  trust 00:23:F1:XX:XX:XX
</code></pre></div>        </div>

        <p>This allows the Raspberry Pi to authorize future supported connections from the phone without repeatedly asking for approval.</p>
      </li>
    </ul>
  </li>
</ol>

<h3 id="accessing-the-internet-from-a-java-phone">Accessing the Internet from a Java phone</h3>

<p>This part is phone-specific because it requires changing the phone’s Internet settings. The menu names and available options may differ between models.</p>

<ol>
  <li>
    <p>Check that the phone can discover the NAP service.</p>

    <p>On the S500i, select Raspberry Pi under <code class="language-plaintext highlighter-rouge">Connectivity / Bluetooth / My devices</code> and browse its services.</p>

    <p>Look for <code class="language-plaintext highlighter-rouge">Network access</code>.</p>

    <p>If it appears, the phone can discover the Raspberry Pi’s NAP service.</p>
  </li>
  <li>
    <p>Configure the phone’s Internet connection.</p>

    <p>Go to <code class="language-plaintext highlighter-rouge">Connectivity / Internet settings / Internet profiles</code>.</p>

    <p>Create an Internet profile using the Bluetooth connection if one is available.</p>
    <blockquote>
      <p>Some phones automatically create a Bluetooth data account when a PAN connection is established. The exact behavior varies between models and firmware versions.</p>
    </blockquote>
  </li>
  <li>
    <p>Test the connection.</p>

    <p>Open the phone’s browser and try loading a simple website, like <a href="https://frogfind.com">frogfind.com</a>.</p>

    <p>While the phone is attempting to connect, run the following command on the Raspberry Pi:</p>

    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> bridge <span class="nb">link </span>show master btnap0
</code></pre></div>    </div>

    <p>If you see an interface named bnep0 with state forwarding, the phone has successfully established a Bluetooth PAN connection to the Raspberry Pi.</p>
  </li>
</ol>

<figure class="post-figure post-figure--pair">
  <a href="/assets/images/s500i/nap-services.jpg">
    <img src="/assets/images/s500i/detail-nap-services.jpg" alt="S500i displaying the Raspberry Pi's Network access Bluetooth service" loading="lazy" />
  </a>
  <a href="/assets/images/s500i/data-account.jpg">
    <img src="/assets/images/s500i/detail-data-account.jpg" alt="S500i data accounts menu with a Bluetooth account for Raspberry Pi" loading="lazy" />
  </a>
  <figcaption>The Raspberry Pi's Network access service and the corresponding Bluetooth data account.</figcaption>
</figure>

<p><em>Hooray! We are on the net!</em></p>

<h3 id="browsing-the-web-on-the-java-phone">Browsing the web on the Java phone</h3>

<p>You can now go and browse the Web. Well, at least a very small part of it.</p>

<p>Most of the default links in the Sony Ericsson browser no longer work, but, for example, good old <a href="https://frogfind.com">frogfind.com</a> works just fine.</p>

<p>If you want a more modern, feature-rich alternative to the default browser, there is another option. By some miracle, Opera still provides <a href="https://www.opera.com/download/mobile-versions">download links</a> (<a href="https://web.archive.org/web/20261116100558/https://www.opera.com/download/mobile-versions">archive</a>) for Opera Mini 4.5 for Java phones on its official website, which is just incredible. Even better, many of its default links still work and serve today’s news!</p>

<p>Unlike the Sony Ericsson’s built-in browser, Opera Mini 4.5 can also access modern HTTPS websites through Opera’s proxy servers, which handle encryption and process webpages before sending them to the phone<sup id="fnref:5"><a href="#fn:5" class="footnote" rel="footnote" role="doc-noteref">5</a></sup>. This makes a surprisingly large portion of the modern web accessible, although many websites remain out of reach due to modern web standards, the phone’s limited hardware, and, well, the web being the web.</p>

<figure class="post-figure post-figure--pair">
  <a href="/assets/images/s500i/xkcd-duty-calls.jpg">
    <img src="/assets/images/s500i/detail-xkcd-duty-calls.jpg" alt="Sony Ericsson S500i displaying xkcd #386 in Opera Mini" loading="lazy" />
  </a>
  <a href="/assets/images/s500i/https-test.jpg">
    <img src="/assets/images/s500i/detail-https-test.jpg" alt="S500i showing the HTTPS-only HTTP Minimal website" loading="lazy" />
  </a>
  <figcaption>Reading <a href="https://xkcd.com/386/">xkcd #386, “Duty Calls”</a> and accessing an HTTPS-only website using Opera Mini 4.5.</figcaption>
</figure>

<p>Even with Opera Mini (while it still works), browsing the modern web on a phone this old is still pretty hit-or-miss. Fortunately, there are a couple of projects that make life easier for old browsers:</p>

<ul>
  <li>
    <p><a href="https://frogfind.com/about">FrogFind</a> – simplifies modern webpages into basic HTML that vintage computers can handle. It turns out to be pretty handy for an underpowered phone from almost 20 years ago, too.</p>
  </li>
  <li>
    <p><a href="https://protoweb.org/about/">ProtoWeb proxy</a> – takes a different approach, bringing back websites from the mid-to-late 1990s through a proxy. Those pages aren’t always convenient to navigate on the S500i’s tiny screen, but then again, browsing the web on phones back then wasn’t exactly convenient either. So it’s a pretty authentic experience!</p>
  </li>
</ul>

<h3 id="and-then-theres-wap">And then there’s WAP!</h3>

<p>There’s another little corner of the web that’s still alive: a small community of enthusiasts keeping old WAP websites running, serving WML pages designed for early mobile browsers. These sites can still be browsed on compatible phones, without relying on an emulator! And maybe it’s time to bring a few more WML sites online…</p>

<h2 id="closing-words">Closing Words</h2>

<p>I watched Action Retro’s video<sup id="fnref:6"><a href="#fn:6" class="footnote" rel="footnote" role="doc-noteref">6</a></sup> about bringing FrogFind to WAP, where he converts the FrogFind homepage into WML for older mobile browsers. Building a small HTML-to-WML converter could be a really cool project. And with Internet access already working over Bluetooth, developing and testing it on physical hardware should be much easier, without having to build an entire 2G network like dosdude1 did<sup id="fnref:7"><a href="#fn:7" class="footnote" rel="footnote" role="doc-noteref">7</a></sup>. Of course, this approach won’t work for every old phone, but for those that support Bluetooth networking, it doesn’t require any additional radio hardware.</p>

<p>I’d also love to see a community-maintained list of phones that support Bluetooth PANU, since many manufacturers never bothered to document it (including Sony Ericsson with the S500i). It would make it much easier for anyone to figure out whether their phone can get online this way or whether they’ll need to get a bit more creative ;-)</p>

<p>P.S. Have fun and happy hacking!</p>

<h2 id="changelog">Changelog</h2>

<p>2026/11/24: Added mention of Windows method</p>

<h2 id="sources">Sources</h2>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p><a href="https://www-support-downloads.sonymobile.com/s500/userguide_EN_S500.pdf">Sony Ericsson S500i documentation</a> (<a href="https://web.archive.org/web/20251023010349/https://www-support-downloads.sonymobile.com/s500/userguide_EN_S500.pdf">archive</a>). <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p><a href="https://wiki.gentoo.org/wiki/Bluetooth_Network_Aggregation_Point">Gentoo Wiki -  Bluetooth Network Aggregation Point</a> (<a href="https://web.archive.org/web/20260725024820/https://wiki.gentoo.org/wiki/Bluetooth_Network_Aggregation_Point">archive</a>). <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:3">
      <p><a href="https://www.howtoforge.com/bluetooth_pand_debian_etch/">Bluetooth PAND (Personal Area Network) Howto For Debian Etch</a> (<a href="https://web.archive.org/web/20260718000238/https://www.howtoforge.com/bluetooth_pand_debian_etch">archive</a>). <a href="#fnref:3" class="reversefootnote" role="doc-backlink">&#8617;</a> <a href="#fnref:3:1" class="reversefootnote" role="doc-backlink">&#8617;<sup>2</sup></a></p>
    </li>
    <li id="fn:4">
      <p><a href="https://www.raspberrypi.com/news/raspberry-pi-product-series-explained/">Raspberry Pi product series explained</a> (<a href="https://web.archive.org/web/20261030065658/https://www.raspberrypi.com/news/raspberry-pi-product-series-explained/">archive</a>) <a href="#fnref:4" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:5">
      <p><a href="https://blogs.opera.com/mobile/2016/03/opera-mini-takes-care-security/">Opera Mini Takes Care of Your Security — Opera Blog</a> (<a href="https://web.archive.org/web/20260719040428/https://blogs.opera.com/mobile/2016/03/opera-mini-takes-care-security/">archive</a>). <a href="#fnref:5" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:6">
      <p><a href="https://www.youtube.com/watch?v=D62ZsVZCjAA">Is WAP dead?</a> <a href="#fnref:6" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:7">
      <p><a href="https://www.youtube.com/watch?v=CMWvA4Ty1Wk">Building a CUSTOM 2G GSM Cellular Base Station</a> <a href="#fnref:7" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name></name></author><category term="tech" /><category term="j2me" /><category term="phone" /><category term="bluetooth" /><summary type="html"><![CDATA[Sony Ericsson S500i accessing FrogFind.]]></summary></entry><entry><title type="html">DAS Amplitude response as a function of frequency and velocity calculator</title><link href="/2026/10/08/das-response.html" rel="alternate" type="text/html" title="DAS Amplitude response as a function of frequency and velocity calculator" /><published>2026-10-08T09:00:00+00:00</published><updated>2026-10-08T09:00:00+00:00</updated><id>/2026/10/08/das-response</id><content type="html" xml:base="/2026/10/08/das-response.html"><![CDATA[<p>Following (<a href="https://doi.org/10.1029/2021JB023587">Näsholm et al., 2022</a>), the DAS amplitude response for planar wave propagating along the length of the fiber is given by Eq. 9:</p>

\[R(f) = 10 \log_{10} \left|
\frac{1}{m}
\frac{
  \sin\left(\frac{\pi m \Delta x f}{v}\right)
}{
  \sin\left(\frac{\pi \Delta x f}{v}\right)
}
\right|\]

<p>where $m$ is defined as $G / \Delta x$.</p>

<p>This is a simple calculator to get the response based on that formula:</p>

<div id="frequency-response-widget" style="width:100%; max-width:850px; margin:20px auto;">

  <div id="frequencyPlot" style="width:100%; height:420px;"></div>

  <style>
    #frequency-response-widget .control {
      margin-bottom: 15px;
    }

    #frequency-response-widget .control label {
      display: block;
      margin-bottom: 6px;
      font-weight: 500;
    }

    #frequency-response-widget .control-row {
      display: flex;
      align-items: center;
      gap: 15px;
    }

    #frequency-response-widget input[type="range"] {
      flex: 1;
      min-width: 0;
      cursor: pointer;
    }

    #frequency-response-widget input[type="number"] {
      width: 90px;
      padding: 6px;
      border: 1px solid #aaa;
      border-radius: 5px;
      box-sizing: border-box;
    }
  </style>

  <div style="padding:10px 20px;">

    <!-- Velocity -->
    <div class="control">
      <label for="velocityInput">Velocity (m/s)</label>
      <div class="control-row">
        <input type="range" id="velocitySlider" min="100" max="10000" step="10" value="900" />
        <input type="number" id="velocityInput" min="100" max="10000" step="10" value="900" />
      </div>
    </div>

    <!-- Gauge multiplier -->
    <div class="control">
      <label for="gaugeInput">Gauge multiplier</label>
      <div class="control-row">
        <input type="range" id="gaugeSlider" min="1" max="10" step="1" value="2" />
        <input type="number" id="gaugeInput" min="1" max="10" step="1" value="2" />
      </div>
    </div>

    <!-- Sampling distance -->
    <div class="control">
      <label for="samplingInput">Sampling distance (m)</label>
      <div class="control-row">
        <input type="range" id="samplingSlider" min="0.1" max="1000" step="0.01" value="5" />
        <input type="number" id="samplingInput" min="0.1" max="1000" step="0.01" value="5" />
      </div>
    </div>

    <!-- Maximum frequency -->
    <div class="control">
      <label for="maxFreqInput">Maximum frequency (Hz)</label>
      <div class="control-row">
        <input type="range" id="maxFreqSlider" min="50" max="10000" step="10" value="250" />
        <input type="number" id="maxFreqInput" min="50" max="10000" step="10" value="250" />
      </div>
    </div>
  </div>
</div>

<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>

<script>
(function () {
  const widget = document.getElementById(
    'frequency-response-widget'
  );

  const graph = widget.querySelector('#frequencyPlot');

  const controls = {
    velocity: {
      slider: widget.querySelector('#velocitySlider'),
      input: widget.querySelector('#velocityInput')
    },
    gauge: {
      slider: widget.querySelector('#gaugeSlider'),
      input: widget.querySelector('#gaugeInput')
    },
    sampling: {
      slider: widget.querySelector('#samplingSlider'),
      input: widget.querySelector('#samplingInput')
    },
    maxFreq: {
      slider: widget.querySelector('#maxFreqSlider'),
      input: widget.querySelector('#maxFreqInput')
    }
  };

  const numPoints = 5000;

  // Keep sliders and numeric inputs synchronized
  function syncControls(control) {
    const slider = control.slider;
    const input = control.input;

    // Slider changes update number field immediately
    slider.addEventListener('input', function () {
      input.value = slider.value;
      updateGraph();
    });

    // Accept valid typed values immediately.
    input.addEventListener('input', function () {
      if (input.value.trim() === '') return;

      const value = Number(input.value);
      const min = Number(input.min);
      const max = Number(input.max);

      if (!Number.isFinite(value) ||
          value < min || value > max) return;

      // Gauge multiplier must be an integer
      if (control === controls.gauge &&
          !Number.isInteger(value)) return;

      slider.value = value;
      updateGraph();
    });

    // Normalize invalid or out-of-range entries on change
    input.addEventListener('change', function () {
      let value = Number(input.value);

      if (!Number.isFinite(value) ||
          input.value.trim() === '') {
        value = Number(slider.value);
      }

      value = Math.max(
        Number(input.min),
        Math.min(Number(input.max), value)
      );

      // Match the slider's defined increments
      const step = Number(slider.step);
      const min = Number(slider.min);

      value = min + Math.round((value - min) / step) * step;
      value = Number(value.toFixed(6));

      slider.value = value;
      input.value = slider.value;
      updateGraph();
    });
  }

  Object.values(controls).forEach(syncControls);

  // Frequency response calculation
  function calculateResponse(v, sampling, multiplier, freqs) {
    return freqs.map(f => {
      const theta = Math.PI * f * sampling / v;
      const denominator = Math.sin(theta);

      let magnitude;

      if (Math.abs(denominator) < 1e-10) {
        magnitude = 1;
      } else {
        magnitude = Math.abs(
          Math.sin(multiplier * theta) /
          (multiplier * denominator)
        );
      }

      return 10 * Math.log10(
        Math.max(magnitude, 1e-12)
      );
    });
  }

  // Update graph
  function updateGraph() {
    const v = Number(controls.velocity.slider.value);
    const sampling = Number(controls.sampling.slider.value);
    const multiplier = Number(controls.gauge.slider.value);
    const maxFreq = Number(controls.maxFreq.slider.value);

    const gauge = sampling * multiplier;

    const minFreq = 0.01;

    const freqs = Array.from(
      { length: numPoints },
      (_, i) =>
        minFreq + i * (maxFreq - minFreq) / (numPoints - 1)
    );

    const response = calculateResponse(
      v, sampling, multiplier, freqs
    );

    Plotly.react(graph, [{
      x: freqs,
      y: response,
      type: 'scatter',
      mode: 'lines',
      line: {
        color: '#2563eb',
        width: 2
      },
      hovertemplate:
        'Frequency: %{x:.2f} Hz<br>' +
        'Response: %{y:.2f} dB<extra></extra>'
    }], {
      title: {
        text:
          'Frequency Response<br>' +
          `<sup>Velocity = ${v} m/s, ` +
          `Gauge = ${gauge.toFixed(2)} m, ` +
          `Sampling = ${sampling.toFixed(2)} m</sup>`
      },

      xaxis: {
        title: 'Frequency (Hz)',
        range: [0, maxFreq],
        showgrid: true,
        zeroline: false
      },

      yaxis: {
        title: 'Response Magnitude (dB)',
        range: [-40, 1],
        showgrid: true,
        zeroline: false
      },

      margin: {
        l: 65,
        r: 20,
        t: 85,
        b: 60
      },

      paper_bgcolor: 'rgba(0,0,0,0)',
      plot_bgcolor: 'rgba(0,0,0,0)',

      uirevision: `frequency-${maxFreq}`,
      showlegend: false
    }, {
      responsive: true,
      displaylogo: false,
      scrollZoom: true
    });
  }

  updateGraph();
})();
</script>]]></content><author><name></name></author><category term="DAS" /><category term="science" /><category term="seismology" /><summary type="html"><![CDATA[Following (Näsholm et al., 2022), the DAS amplitude response for planar wave propagating along the length of the fiber is given by Eq. 9:]]></summary></entry></feed>