# LTSpice simulate log amplifier

Consider we have a nonlinear opamp circuit like this.

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

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

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

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.

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:
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.

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

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.

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

• See what happens if you pick a leakier diode (like a schottky) and increase the size of the resistor. Your plot actually does look like it could be taking the log of the input, but it saturates quickly because the saturation current of the diode is quite small compared to your voltage across 15K (and so the op amp rails). – Los Frijoles Jun 27 at 21:20
• Try selecting a particular diode model for D1, such as a 1N4148. The default model might not behave like a real diode. – Elliot Alderson Jun 27 at 21:22
• Your Second Try matches my results, at least for > 0.1 Vin, below that and it is too hard to read the linear graph. So, if you didn't change anything else, maybe the primary issue was in plotting. – Mattman944 Jun 28 at 13:54
• I got these results directly from Mattman944's simulation results. (First one) Since I do not have proficiency in using LTSpice yet this might be true. Also LTSpice might be using a different equation for diode current. – Erdem Jun 28 at 16:31