Frequency Response Analysis (.bode) Study Guide

I saw questions about how to use frequency response analysis (.bode). Actually, the help in Qspice is quite clear, but people may still find challenge as commands to control .bode behavior are separated in .bode and .option

Therefore, I prepared a guide for .bode for those who interested in .bode but have difficulty in setting up a simulation or getting a frequency response curve as you expect. But .bode is not an easy topic to explain, this is so far the best present I can come up with.

I am a user same as you, therefore, I cannot guarantee all information in my work is correct.

You can find the .bode guide in this Github link. In addition, it also include an Entry guide, Device guide and a Reference guide. I still work on updating all these guidelines. Feel free to let me know if typo or mistake in them.

Qspice/Guideline at main · KSKelvin-Github/Qspice

8 Likes

I look forward to reading this. Thanks Kelvin!

1 Like

Hi Kelvin,

I have a suspicion that the .bode does not actually run the transient analysis and apply the perturbation one frequency at a time. I guess some fancy algorithm like multitone is used instead Multi-Tone AC Analysis Theory

Reasons:
I noticed some weird result and clear cut differences between using .bode and .meas fra + .step.
perhaps you can find my mistake for how I implement .bode in this file.
FRA_SMPS_STUDY.zip.txt (2.5 KB)

Thanks
Arief,

I can guarantee .bode run a .tran to collect time domain data for frequency response analysis.

For Qspice demo circuit FRA_SMPS, I setup a .step for frequency from 1KHz to 80kHz, this allow to plot the .meas, to generate a bode plot.

Next step I change simulation directive to .bode, and results between FRA and .bode compared in below.

I start simulation from 1kHz instead of 100Hz, as 1kHz already with 40dB gain. To start with lower frequency down to 100Hz, higher gain is expected and may easily saturate the controller. For this circuit, bode between 1kHz to 80kHz should be good enough to cover enough design information.

This is simulation files for reference
Qspice/Forum/15954 at main · KSKelvin-Github/Qspice

Hi KSKelvin,

I am not doubting if real .tran is used for .bode, however, I am thinking if the analysis is performed using multi-tone or not.

To my knowledge a sweep of the single frequency perturbation should be the more accurate approach, though a lot slower.

Please refer to this article
Frequency Response of Switching DC_DC Converters from a Single Simulation in the Time Domain.pdf (1.5 MB)

Arief,

oh, sorry that I misunderstood your first message. I didn’t investigate the maths behind .bode.

My major focus is just to document my study and share with community. The simulation time for a time domain bode offers by .bode is amazing. That why I think it worth the effort to learn and to use it.

I am also interest to the math behind. But as Qspice help doesn’t explain that, and if Mike not further explain that, I just leave it aside at the moment. How to use it to achieve my goal is my major focus in using Qspice. Thanks for sharing the article, will look into that.
On the other hand, I also see you are working on a project to develop an approach for frequency response analysis in Qspice. :+1:

1 Like

Kelvin, this is what I been looking for. Thank you for posting this. Robert

Hello,

I am trying for a simple common-emitter amplifier to get the overall frequency response of the circuit. I am new to spice and QSPICE, and I am likely messing up the directive to make it run properly.

Below is the circuit, I teach basic Analog and have never used a SPICE program, so I apologize if this is a stupid problem to solve. I want to learn this simulator to better show the theory in class.
Below is the circuit in QSPICE, do not laugh at my directives, I read KSKelvins how to guides, but I am still struggling.

I left off the ground on the V2 as if it is present it gives me an error(below).

This is what I get for the plot. with the ground on V2

This is a generic frequency response I would expect to see, for the overall response.
image

This subject is hard for the student to visualize and I was hoping that QSPICE could help show it. I know for some of you this is a simple solution.

I would appreciate any help on this.

Darrell

.bode is not the best tool to handle your request. In QSPICE, two directive for frequency response analysis, .ac and .bode, you can go to Qspice Help for more information, here is a quick summary

  • .ac : small-signal ac analysis linearize the circuit at dc operation point, this is equivalent to what the standard textbook do for a BJT circuit
  • .bode : use a perturbating source to inject ac signal and run time domain simulation, use FFT to get frequency response from time domain data. This technique is normally for switching circuit

You didn’t attach your schematic, therefore, I am not quite sure if your have .model to support Q1 as 2N3904, just beware that 2N3904 is not in standard Qspice library, you can add a .model for that, but in following demonstration, I changed to MMBT3904, you can right click on Q1, to select a model from there.

As you mentioned for teaching purpose, and you are new in SPICE, let me give you a brief example of what you can do with Qspice.

This single schematic can run a .op, .tran, .ac and .bode analysis. What you need to do is that, you only let one directive active before run simulation. If you switch directive, close the waveform viewer first. To switch directive, mouse hover the directive, press “;” to toggle comment or not. I add a Vdummy 0V source in series Vpert, the reason is that, .bode must have the source disconnect from GND. In series a 0V source can do the trick.

BJT-Circuit.qsch (9.8 KB)

DC Operation Point
As I changed Q1, I have to re-adjust bias condition. .op with .step can give V(c) vs R4 relationship, which help to quickly identify what R4 should be. Midpoint is at R4=3.7kohms, and in standard E12, R4 is selected as 3.9kohms in following analysis

Transient Simulation
In Vpert, sin 0 10m 1k is used, A sine wave 1kHz, 10mV is injected from V(in), and transient can help to ensure what is proper input signal range for .bode.

AC Analysis
OK, this is to answer your question. Here, Vpert with AC 1, which means we have a magnitude 1V, phase 0 degree AC source at Vpert. As circuit is linearized in .ac analysis, this “1V” magnitude will never saturate the circuit (if you put a 1V in sine function in .tran, you will see amplifier is saturated). The ac directive in here is to sweep freq from 10Hz to 1GHz, 100 points per decade. And this is the result you are looking for.

Frequency Response Analysis
Finally is .bode analysis. Actually, in your case, you don’t have to use .bode, but as demonstration, I still give you this example of how to use .bode to generate frequency response. However, to use .bode, you must be familiar with all setting in .bode

  • in this simulation, need to force constant perturbating amplitude, use .option bodeampfreq=0. you have to prevent saturating output as it will no longer be small-signal frequency response
  • .bode run very slow if Fstart to Fstop apart more than 3 decade. therefore, to sweep freq from 10Hz to 1GHz, I use .step to separate into 4 .bode sweeps and recombine the result

3 Likes

WOW, Thank you for taking the time to show/explain this.

Darrell

Qspice - Bode Frequency Response Analysis (.bode).pdf is updated in my Github : KSKelvin-Github/Qspice/Guideline.

On 26-Oct, Qspice updated help of .bode, and currently .bode can keep its time domain waveform with “DEBUG” and excitation source with Square wave instead of Sine wave with “SQUARE” as positive number.

Here is a demo schematic for following example in demonstrate DEBUG and SQUARE
bode-example-controlblockset.qsch (5.5 KB)

Demonstrate the use of debug, with sine wave perturbing source

Demonstrate the use of debug, with square wave perturbing source

3 Likes

Hello KSKelvin,

I am trying to use .meas FRA command but getting error. Below is the link to my post for same query.

Could you please help me in solving this issue?

Regards,
Shantanu

Hi KsKelvin,
I have read your guide for the use of the bode command.
It is useful, my question is is het possible to have two bode measurements in the same schematic? I seems handy for optimizing the compensator. If you have the transfer function of the plant and the of the total loop. Now it takes me two different simulations to change the input and output of the bode measurement command.

Best regards Joop

@Pe1ebc My understanding is that .bode can only return one transfer function. The traditional way to obtain a Bode plot using the .meas NAME fra FREQ INPUT OUTPUT syntax allows multiple transfer functions to be analyzed. For .bode to have multiple transfer functions, it would be necessary for Mike to add an additional feature.

There are at least two FRA projects in this forum. @physicboy and I both have our versions of FRA. I just uploaded a variant with 2 transfer functions at the following link.
QSPICE Forum Schematic Capture “A Frequency Response Analyzer (FRA) in QSPICE” - QSPICE - Qorvo Tech Forum

I recall that @physicboy also has a version with multiple channels… (@physicboy, did you upload that on your GitHub?)

@KSKelvin, I dont finish that one…

Because it gets confusing for me to define the transfer function.
In two channel design as we did, the TF is defined as IN2/IN1

But, for multi channel (lets say 4ch)… is it gonna be?

  1. IN2/IN1 and IN4/IN3
  2. IN4/IN1, IN3/IN1, IN2/IN1

*after writing above, i kinda think if option 1 is more straight forward…haha

Hi KSkelvin,

Thanks for the answer. I’m familiar with the .meas NAME fra FREQ INPUT OUTPUT from LTspice. Not sure if it can be used with one disturbance source from the bode command. especially when you add the block option. I will try.

@ physicboy,
I have seen your work, which I think is great. I even downloaded your example which also worked.
For me expermenting /chancing something in your code is quite challenging as i have no experience with writing code. Let’'s just say that I have a fear for the blinking cursor.
Maybe time to overcome that.
Best regards

1 Like

.bode does not work with .meas FRA. I am just trying to point out that the way to have multiple transfer functions in Qspice can only be achieved with the .meas FRA method.

@Pe1ebc

I misunderstood your question.

You can use my FRA implementation with .step, it will automatically plot all the bode plot coming from your sim.

To automate your analysis you can use B source and .step to switch the signal measured by the FRA

For example,
step 1 you measure your overall loop response
step 2 you measure your control loop only

@Pe1ebc As reminded by @physicboy, a switch can be used to obtain 2 transfer functions with .step approach. However, it is essentially the same as simulating the same schematic twice, offering no time-saving benefits but rather allowing everything to be simulated in a single setup.

The symbols in this schematic can be found in my Github Symbol library
Qspice/Symbols-KSKelvin/.command/.bode · KSKelvin-Github/Qspice

example.Bode-InOut-Switch.qsch (17.9 KB)