# 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))
vIn.append(float(row))
vOut.append(float(row))

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

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. simulate this circuit – Schematic created using CircuitLab 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. • At low input currents the dynamic resistance of the feedback element (the diode) can be extremely high and pF capacitances can result in large time constants. Log amplifiers always suffer from this. A photodetector amplifier I one designed could take tens of seconds to settle at -90dBm optical input power (equivalent to pA photocurrent). It was much faster at higher light levels. – Kevin White Jun 28 at 2:06
• @Kevin White - Thanks, I re-ran at 5 kHz and demonstrated that capacitance will affect the results. I edited the answer. – Mattman944 Jun 28 at 2:54