Simulating with real audio is awesome and easy!

LTSpice is a fantastic simulation tool that can greatly help in your circuit design. For example, you easily get a bode-plot from a Cauer-filter:

Circuit diagram of two-stage elliptical SSB filter. A cut-off frequency of circa 3.1 KHz and over 80 dB attenuation at 7.5kHz.
Figure -1 – Circuit diagram of two-stage elliptical SSB filter. A cut-off frequency of circa 3.1 KHz and over 80 dB attenuation at 7.5kHz.
Bodeplot of two-stage elliptical SSB filter. Red trace is input, green trace is after first stage, violet trace is final output.
Figure-2 – Bodeplot of two-stage elliptical SSB filter. Red trace is input, green trace is after first stage, violet trace is final output.

To determine how suited an audio filter is for a Morse code, get the impulse response after a tone burst. You can then see how much ringing there is in the filter.

Two-stage CW filter according to the multiple feedback topology. Center frequency is set at 1kHz.
Figure-3 – Two-stage CW filter according to the multiple feedback topology. Center frequency is set at 1kHz.
Input (red) and output (green) traces of a 10 millisecond tone burst of the CW filter. The filter time (63%) is circa 7 ms.
Figure-4 – Input (red) and output (green) traces of a 10 millisecond tone burst of the CW filter. The filter time (63%) is circa 7 ms.

However, one of the really cool, but nevertheless lesser known, features of LTSpice is the ability to use real audio as a source for your circuit simulations. You can thus capture some amateur radio broadcast using your favorite receiver. Be it a crystal receiver or a web SDR receiver and save it as an audio file (wav). This file can now be used as the input for the circuit you are currently simulating. You can thus verify how good your audio filter is before soldering a single component!

Let’s see how the simulation works…

We need to change three small things. First we need to tell the voltage source in our simulation to use a WAV file. Then we need to tell LTSpice to record the output to another WAV file. Finally, we need to change the simulation time to match the length of the input WAV file (more or less).

1. For excitation of the filter an ordinary voltage source can be used. To assign the voltage signals from the WAV file, hold down the CTRL key and right click on the voltage source. This will reveal the Component Attribute Editor, as shown in the figure below.

Component Attribute Editor with the input set to the SSB recording.
Figure-5 – Component Attribute Editor with the input set to the SSB recording.

Change the value line of the Voltage source to wavefile="C:\NameOfYourWaveFile.wav". The full syntax of wavefile command is wavefile="FileName.wav" [chan=<chan#>]. The “FileName.wav” parameter is mandatory. However, you can omit the quotes if there are no spaces in the file or directory name. The channel parameter is optional. Channel can have a value between 0 … 65.535. Channel 0 is used by default if this parameter is omitted. In a stereo file, channel 0 is assigned to the left channel and channel 1 is assigned to the right channel. LTSpice will figure out the sample rate and the number of bits from the file by itself from the file header.

2. Next we need to capture the output and send it to a file. This is done using the LTSpice .wave command.

“Syntax:  .wave <filename.wav> <Nbits>  <SampleRate> V(out) [V(out2) …]

example: .wave C:\output.wav 16 44.1K V(left) V(right)

<filename.wav> is either a complete absolute path for the .wav file you wish to create or a relative path computed from the directory containing the simulation schematic or netlist.  Double quotes may be used to specify a path containing spaces.  <Nbits> is the number of sampling bits.  The valid range is from 1 to 32 bits.
<SampleRate> is the number of samples to write per simulated second.  The valid range is 1 to 4294967295 samples be second. The remainder of the syntax lists the nodes that you wish to save. Each node will be an independent channel in the .wav file.  The number of channels may be as few as one or as many as 65535.  It is possible to write a device current, e.g., Ib(Q1) as well as node voltage.  The .wav analog to digital converter has a full scale range of -1 to +1 Volt or Amp.

Note that it is possible to write .wav files that cannot be played on your PC sound system because of the number of channels, sample rate or number of bits due to limitations of your PC’s codec.  But these .wav files may still be used in LTspice as input for another simulation. See the sections LTspice=>Circuit Elements=>V. Voltage Source and I. Current source for information on playing a .wav file into an LTspice simulation. If you want to play the .wav file on your PC sound card, keep in mind that the more popularly supported .wav file formats have 1 or 2 channels; 8 or 16 bits/channel; and a sample rate of 11025, 22050, or 44100 Hz.” (Source: LTSpice Wiki)

3. In the transient simulation example in the beginning, the simulation time was set to 20 milliseconds. Now we set the simulation time to be equal (more or less) to the length of WAV file. If we set the time span too short, the WAV file is truncated eq. only a small art of the file is used. If we set it longer than the actual length of the file, our simulation will end with silence….
This is done with the command .tran <time> . This whole scheme will only work in transient simulation mode, of course.

Using the fantastic Twente University WebSDR (http://websdr.ewi.utwente.nl:8901/), I’ve recorded two audio samples. The first sample is a 6-7 seconds long recording of a SSB conversation with the bandwidth set to 6.6 (!) kHz. the sample was recorded at 7073 kHz at 1233h CET March 8th 2023. The 2nd sample is a recording of a CW exchange. Again with the bandwidth set to 6.6 kHz and recorded at 7019 kHz at 1227h CET of the same day and has roughly the same length. You can find both recordings at the end of this post.

Two stage elliptical SSB filter with real audio

We are using the passive Cauer Low Pass Filter again that we’ve used at the beginning of this post. We used the Twente WebSDR SSB wav file recording as input.
Using Ctrl-Righ click we open the Component Attribute Editor of V1 and we use the wavefile command to tell LTSpice to use LSB wave file as input.

Circuit of the elliptical filter configured to use real audio in the simulation.
Figure-6 – Circuit of the elliptical filter configured to use real audio in the simulation.

We capture the output of the filter at two places. The output recorded after the first filter (out1) is stored as ssb1.wav . This is done using the .wave c:SSB1.wav 16 44.1K V(out1) command. The output after the 2nd filter ( labelled out2) is recorded as ssb2.wav using the .wave c:SSB2.wav 16 44.1K V(out2) command.
Since the audio captured with WebSDR was a little over 6 seconds, we set the simulation time to 7 seconds with the command .tran 7 .
That’s really all there is to it! Now you can run the simulation and listen to the results. You can listen to the outputs of this filters with ssb1.wav and with ssb2.wav

Multiple feedback CW filter with real audio

The CW filter is the same filter as used in the beginning. This time we use, part of, a CW conversation as input. The file can be found HERE.

CW filter now configured to use real audio in the simulation.
Figure-7 – CW filter now configured to use real audio in the simulation.

It works exactly the same as with the SSB filter. We open the Component Attribute Editor with Ctrl-Right Click and use the wavefile command to use the CW wav file as the input. The output of both filter sections (out1 & out2) are captured with the .wave commands. Finally, the simulation time is set to match the length of the input recording with the .tran 7s command.
The output is recorded after the first filter (out1) and after the 2nd filter and stored as cw1.wav. respectively as cw2.wav.

Downloads

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>