# Beginner's LTSpice Question: Why does my sine wave look so bad and how can I fix it?

I'm planning on building a Spice circuit with variable-gap capacitors. The capacitance in general will be something like C = eps*A/(g0+g'), where g' is the oscillation that occurs on top of the nominal gap position, g0. My first thought was to make a behavioral voltage source that would ultimately be the g' variable.

Prior to making the real circuit, I wanted to mess around with this concept in a beginner's fashion. Below is the general idea, where I have some frequency input and an amplitude called "disp," representing the gap change.

Here is where the problem comes in. When the disp variable is 1e-4, everything seems fine (sine wave with the correct amplitude). But when I go to 1e-5, I get the following picture. I imagine this is some sort of resolution issue? But I wanted to ask and see if there is a solution or if my initial plan is not the smartest way of going about things. I also tried using a normal voltage source with the parameters inputted as the frequency/amplitude of a sine wave. Thanks in advance.

That voltage is rather low.

Simulate->Control Panel and set Absolute Voltage tolerance to something smaller like 1E-7 or 1E-8.

• Wow, that is exactly what I needed. My voltage tolerance was at 1e-5, which is why it got goofy. Thank you Commented Jul 28, 2020 at 21:07

You could use @Spehro Pefhany's answer, but there is another way to do it: since you only need a fixed amplitude sine, don't use a behavioural source, instead, use a simple voltage source with SINE(0 {disp} {f}). This is because behavioural sources are a bit more tricky and need tinkering. If the displayed waveform is still not satisfactory, then disable the waveform compression. By default, all the points are compressed leading to artifacts. You can disable this by adding .opt plotwinsize=0 to the schematic. This setting should be used whenever you need details. The prce to pay is larger .raw files (no compression). Personally, I'd recommend these, first, and only if you have problems try altering the settings in the Control Panel > SPICE tab.

• I did the sine(0 {disp} {f}) as well before posting this and still got the same exact results (plotted on top of each other). The reason I want to use a behavioral source is so I can use the output in a separate formula...would that work with a simple voltage source? Also, I'm trying to use this for a variable-capacitor, which seems to be its own can of worms based on other threads I'm reading. If you have any advice for setting up a behavioral/variable/time-dependent capacitor, that would be appreciated as well. Thank you Commented Jul 28, 2020 at 22:10
• As far as behavioural elements go, maybe these three answers can help. Even if it's about inductors, too, it shows how the whole expression needs to be integrated, not just the variable. For your case, $\int_g{\frac{A\epsilon}{g_0\pm g}}=\pm A\epsilon\log(g_0\pm g)$. Or use the non-integrated formula in a bi source with Cpar=1, resulting in the current as the original expression and the voltage as the integral. Commented Jul 29, 2020 at 5:48
• So I'm still struggling a bit with this concept of integration. In the manual, it says that 'x' is the current but in a lot of those posts, 'x' is the derivative of current. Either way, if the charge is the voltage multiplied by the capacitance, I'm not sure why I need to integrate. Any feedback is helpful, thank you. Commented Jul 30, 2020 at 16:23
• Oops, correct me if I'm wrong please, but I think that 'x' is just for the inductor while in the capacitor definition, 'x' is the voltage drop across the capacitor? Commented Jul 30, 2020 at 17:21
• It sounds like another question, otherwise these comments will prolonge unnecessarily long, and answers that will be here will not be discovered by others, in the future, with similar problems. Commented Jul 30, 2020 at 18:25