Electronic – LTSpice simulate log amplifier

ltspiceoperational-amplifier

Consider we have a nonlinear opamp circuit like this.

log amp

According to theory this op amp should take log of input.

I wonder whether it is possible to get a response like this :

logamp2

I tried to plot vOut versus vIn but I didn't get meaningful results.

logamp3

First try

I replaced diode with a 1N5817 schottky diode and changed resistor value to 200k. This time I got quite interesting result.

To plot transfer function on the horizontal axis I select V(n001). On the vertical axis I select v(vO) trace to plot.

logamp4

Second try

After reading @Mattman944 's answer I exported Circuit's Lab simulation results as CSV. Since my primary OS is Ubuntu and Excel or LibreOffice Calc skills are quite bad I exported data to MatPlotLib.

import matplotlib.pyplot as plt
import numpy as np
import csv

time=[]
vIn=[]
vOut=[]

with open('devre.csv', 'r') as csvfile:
    plots= csv.reader(csvfile, delimiter=',')
    for row in plots:
        time.append(float(row[0]))
        vIn.append(float(row[1]))
        vOut.append(float(row[2]))

plt.plot(vIn,vOut, marker='o')

plt.title('Log amplifier')

plt.xlabel('vIn')
plt.ylabel('vOut')


plt.show()

The result looks like this. May be there might be some way to plot data in logarithmic scale.

logamp5

To be more precise I got these example from the textbook which I study.

logamp7

In the example they ask \$v_O\$ in terms of \$v_I\$ and \$R\$ and they want us to quick sketch of answer. Also \$ \large i = I_S(e^{\frac{qv}{nkT}} – 1)\$, \$\large \frac{kT}{q} = 26mV\$ and \$ \large n\$ is between 1 and 2. These circuit parameters are given.

I solved the example on paper and sketched the output. Which looks like this.

logamp8

I wondered whether theory matches practice so I tried to simulate the circuit in LTSpice.

Best Answer

The circuit only works for positive inputs. Add an offset to your input to keep it above zero. Loops in XY plots can be formed by capacitance, but at 5kHz, it should be negligible, I can't explain the loops. Try slower input frequencies, if it was stray capacitance, the loops will change. Finally, the circuit inverts, so the output is negative.

Works in CircuitLab. If CircuitLab can plot XY directly, I don't know how, I have only been using it a few weeks. I exported to Excel and plotted it.

schematic

simulate this circuit – Schematic created using CircuitLab

enter image description here

Edit: Based on comments from Kevin White, I re-ran at 5 kHz and a loop appeared. This confirms that stray capacitance can affect the results. Simulate slow and it works good.

enter image description here