<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Simulation on Clayton Easley</title><link>https://claytoneasley.org/tags/simulation/</link><description>Recent content in Simulation on Clayton Easley</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 06 Jan 2026 14:29:39 -0500</lastBuildDate><atom:link href="https://claytoneasley.org/tags/simulation/index.xml" rel="self" type="application/rss+xml"/><item><title>Send Sound Through Your Circuit Designs</title><link>https://claytoneasley.org/notes/sound-through-lt-spice/</link><pubDate>Tue, 06 Jan 2026 14:29:39 -0500</pubDate><guid>https://claytoneasley.org/notes/sound-through-lt-spice/</guid><description>Notes on how to send .wav files through simulated analog circuits in LTspice</description><content:encoded><![CDATA[<p>Wheather you&rsquo;re a student, professional, or hobbyist, you will eventually come across <a href="https://en.wikipedia.org/wiki/SPICE">SPICE Software</a> when desigining electronics projects. SPICE software, such as <a href="https://www.analog.com/en/resources/design-tools-and-calculators/ltspice-simulator.html">LTspice</a>, can be used to simulate your analog and digital designs without having to bust out a breadboard or soldering iron.</p>
<p>One of LTspice&rsquo;s features I have found incredibly useful is it&rsquo;s ability to process <code>.wav</code> files as a voltage input and the write the voltage output of the circuit to a new audo file.</p>
<h2 id="audio-settings">Audio Settings</h2>
<p>When working with audio in LTspice, it is important to ensure the correct audio format and encoding are used. The <code>.wav</code> file is just a container for uncompressed pulse-code modulation (PCM) data.
To process audio files in the <code>.wav</code> file format it is important to make sure the file is encoded corectly. The .wav file is a just a <a href="https://en.wikipedia.org/wiki/Container_format">container</a> for raw uncompressed <a href="https://en.wikipedia.org/wiki/Pulse-code_modulation">pulse-code modulation (PCM)</a> data.</p>
<p>So when importing your audio files into LTspice make sure you take note of the <span style="color:red"><strong>audio encoding</strong></span>, <span style="color:red"><strong>bit rate</strong></span>, <span style="color:red"><strong>sample rate</strong></span>, <span style="color:red"><strong>audio duration</strong></span> and make sure the audio channel is <span style="color:red"><strong>monophonic</strong></span></p>
<p>Most audio recording software has the option to export wavefiles in 8-bit to 32-bit  PCM format. In most cases, 16-bit should suffice.</p>

<details>
	<summary>See Audacity Export Example</summary>
	<hr>
<p>Download <a href="https://www.audacityteam.org/">Audacity</a> or <a href="https://github.com/audacity/audacity">Audacity github</a></p>
<p>Open a new Audacity project and navigate to <code>Tracks &gt; Add New &gt; Mono Track</code>. Click on the newly added track and then navigate to <code>Generate &gt; Pluck</code> to make a guitar plucking sound.</p>
<p>Take note that Audacity uses the <a href="https://studiocode.dev/resources/midi-middle-c/">MIDI pitch number</a> which is diffrent than the key number when generating the pluck sound.</p>
<figure>
    <img loading="lazy" src="/notes/audicty_wav_encoding_settings.webp"/> 
</figure>
</details>

<h2 id="ltspice-settings-and-circuit">LTspice Settings and Circuit</h2>
<p>Once you have your audio file you want to use, I would recommend moveing it into the root directory where your LTspice project is located. Otherwise, you will have to provide the <strong>full path</strong> to your audio file.</p>
<pre tabindex="0"><code>.
├── pluck.wav
└── project.asc
</code></pre><h3 id="add-audio-input">Add Audio Input</h3>
<p>Right click the value of your voltage source and put the folowing in the empty text box.</p>
<pre tabindex="0"><code>wavefile=path/to/your_audio.wav
</code></pre><p>This voltage source will now serve as your audio input in your circuit.</p>
<h3 id="simulation-settings">Simulation settings</h3>
<p>The next step is going to be to set up a <a href="https://ltwiki.org/LTspiceHelpXVII/LTspiceHelp/html/DotTran.htm">transient analysis</a> equal to the duration of your audio sample.</p>
<p>This can be done by adding the flowing directive by pressing <code>.</code> on your keyboard. You can also use the GUI by naviagiting to <code>Simulate &gt; Configure Analysis</code> and edit your settings in the <code>Transient</code> tab.</p>
<p>In my case my directive looks like the flowing but you may need to change the duration of analysis.</p>
<pre tabindex="0"><code>.tran 0 1s 0s 0.1s
</code></pre><h3 id="audio-output">Audio Output</h3>
<p>The next step is going to be to add the output newtork lable by pressing <code>n</code> on your keyboard. Keep note of the name of this node as it acts as a varable for the output data. In the example image this is <strong>V_Out</strong>.</p>

<details>
	<summary>See Example Low Pass Filter Schmatic</summary>
	<hr>
<figure>
    <img loading="lazy" src="/notes/lowpass_schematic.webp"/> 
</figure>
<p><a href="https://www.electronics-tutorials.ws/filter/filter_2.html">click here if you want to know more about RC filters</a></p>
<p>Here is a simple low pass filter example with a cut off frequency of  $ \approx 10061 $ Hz which is the closest I could get using standard components.</p>
<p><strong>Remember</strong></p>
<p>$$ f_c = {1 \over 2\pi RC} $$</p>
</details>

<br>
<p>Once you have your circuits input, output, and simulation settings configured we need to use the <a href="https://ltwiki.org/LTspiceHelp/LTspiceHelp/_WAVE_Write_selected_nodes_to_a_wav_file_.htm">.wave directive</a> to output your audio file the circuit.</p>
<pre tabindex="0"><code>.wave &lt;output.wav&gt; &lt;bit rate&gt; &lt;sample rate&gt; V(&lt;output node&gt;)
</code></pre><p>Given my audio settings.</p>
<pre tabindex="0"><code>.wave pluck_out.wav 16 44100 V(V_Out)
</code></pre><h2 id="example-audio">Example Audio</h2>
<p>Listen carefully, the original audio should sound sharper than the outputted file. Looking at LTspice output image (right) you can see the <a href="https://en.wikipedia.org/wiki/Attenuation">attenuation</a> from the right of the red line onward compared to the original audio (left).</p>
<table>
	<thead>
			<tr>
					<th>Original</th>
					<th>LTspice output</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><audio controls src="/notes/pluck.wav"></audio></td>
					<td><audio controls src="/notes/pluck_out.wav"></audio></td>
			</tr>
			<tr>
					<td><figure>
    <img loading="lazy" src="/notes/peak_fft.webp"/> 
</figure>
</td>
					<td><figure>
    <img loading="lazy" src="/notes/peak_out_fft.webp"/> 
</figure>
</td>
			</tr>
	</tbody>
</table>
]]></content:encoded></item></channel></rss>