Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Mar 25th, 2023, 7:03am
 Pages: 1
 How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag (Read 1532 times)
 bernd2700 Community Member Offline Posts: 34 How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Jan 15th, 2021, 2:10am   Dear guys,Ken Kundert said to post here.I tried to compare the simple switched-capacitor integrator below between Cadence and Matlab (at the end acting as a simple loop-filter for a delta-sigma) and I am stuck now on the point of how to compare the 2 results CORRECTLY because of the additional sample & hold maybe (?) needed and instantiated in the Cadence schematics.I have read Ken Kundert’s papers:*) “Simulating Switched-Capacitor Filters with SpectreRF”, and*) “Device Noise Simulation of Delta-Sigma Modulators”.I’m an electronics engineer, but not a mathematician, and so, from the practical point of view I have not found a good answer for me from the internet, therefore I would be very happy, if you could give me a practical advice.Block schematics and timing diagram:Transfer function for this circuit (confirmed by e.g. [Richard Schreier, “yellow” Delta-Sigma book, p.337]):vo/vi =(-Cs)/(Cf)∙z^(-0.5)/(1-z^(-1) )I also calculated the theoretical magnitude and phase at fs/2 (with ideal opamp and with Cs = Cf = 1). It yields “+j/2” which is 0.5 magnitude (-6 dB) and +90° phase.Cadence circuit:As Ken Kundert writes in his papers, I am interested upfront in the discrete-time (DT) behavior, thus I have attached his S&H circuit next to the output “Vo”. It is sampling just a few moments before the rising edge of phase p1, so should be equivalent the read-out at rising edge of p1 at time point “n*T” indicated in the block diagram (node “Vo_ext”) and match with the theoretical result.Cadence results:Matlab result:I created a Bode diagram of the above theoretical, also discrete-time transfer function (thick green line).Comparison and questions:1. Q1: Why does Cadence show 159 mHz as 0 dB magnitude line (as it would be a continuous-time (CT) integrator comparable to a Matlab “1/s” transfer function), although it is discrete-time (DT) behavior after the S&H?Ken Kundert writes in his papers that Spectre basically reports the continuous-time behavior, and if I am interested in the discrete-time behavior then I need to attach a S&H, which I did, but for the magnitude result (as in contrast to the phase result) there is NO difference. The PAC result of BOTH nodes, “Vo” and “Vo_ext” show the 159 mHz. Matlab, instead, shows 167 mHz as 0 dB line.2. Q2: Why the Cadence PAC goes on with the -20dB/dec straight line as again it would be a continuous-time integrator (and reaches -10 dB at fs/2), although it’s the PAC result AFTER the S&H (I have 2 sidebands shown above fs/2 that one can see well the continuing straight line). Matlab’s result, however, flattens out to -6dB at fs/2, also my theoretical calculation yields -6dB.3. When I extend the Matlab plot to beyond fs/2, one could see (not shown here) the symmetrical behavior around fs/2, as it should be for a DT system.Q3: Why does the node after the S&H (“Vo_ext”) in Cadence PAC not show the symmetry around fs/2, although it should be a DT behavior, as Ken writes in his papers?4. For the phase, I would have found a solution for an conclusive explanation in my head, but it is not consistent with the procedure / method of the amplitude:I could argue the following way: When I want to know the response of the integrator alone, I omit the S&H at the end in the Cadence circuit, and I get 90° of phase shift (from +180° to +90°) and make the trick with the Matlab that I can plot z^-0.5. Then, for the phase at least, Matlab fits to Cadence, at least to fs/2. When I want to know the “real” DT behavior (so e.g. every 1/fs = every integer second here (and not half a sec.)), I take node “Vo_ext” in Cadence AFTER the S&H and of course then in Matlab for every Ts=1/fs, it also has to be z^-1, and both results fit.Q4: Is here my thinking somehow correct?5. We see: If I apply the same procedure for the magnitude as for the phase, both Cadence results, before and as well after the S&H are still showing 159 mHz as 0 dB line and -10 dB at fs/2 and neither case does fit to Matlab / theory (167 mHz and -6 dB).Q5: Why does the phase match with this thinking (at least to fs/2), but the magnitude doesn’t?6. I somehow have in mind, that of course I will see the unwanted (“sin(x)/x” coloring) but maybe also wanted (DT, as Ken writes) behavior of the S&H. As by theory, a sim. has shown -3.9 dB of magnitude drop and the phase is at -180 degrees if the S&H is simulated alone. If I simulate 2 of them in series, I obtain the very same data. Thus I conclude, this S&H is NOT an LTI system. Therefore, it’s not allowed to simply divide by its transfer function (so to deduct the sample and hold from the overall circuit, so to exclude the behavior of the additional magnitude and phase influence of the S&H (but which I possibly even want, because, as Ken writes, I am interested in the discrete-time behavior). So maybe I need the discrete-time behavior without the influence of the S&H??? You see, it’s not clear to me.Q6: So, my main question: How to CORRECTLY compare, evaluate, interpret and argue the results obtained in order that the answers are consistent and I have a correct procedure / methodology which is valid for also all the circuits to be analyzed in the future? Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #1 - Jan 18th, 2021, 12:00am   Block schematics and timing diagram: Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #2 - Jan 18th, 2021, 12:01am   Cadence circuit: Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #3 - Jan 18th, 2021, 12:02am   Cadence result: Magnitude Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #4 - Jan 18th, 2021, 12:02am   Cadence result: Phase Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #5 - Jan 18th, 2021, 12:03am   Transfer function equation Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #6 - Jan 18th, 2021, 12:03am   Matlab result and code Back to top IP Logged
 Ken Kundert Global Moderator Offline Posts: 2358 Silicon Valley Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #7 - Jan 18th, 2021, 4:07pm   First, for a sample & hold, you should only be plotting the 0 sideband. SpectreRF by default computes many sidebands, and Wavescan by default shows you all of them.  This is a mistake by Wavescan.  Seeing all sidebands at once can be helpful in certain situations with PXF, but I have never found a use for it in PAC, and it always results in confusing results.  So my first suggestion: for sample-and-holds, only plot one sideband. Generally that will be the 0 sideband, but it could be another sideband if you are engaged down-conversion through sub-sampling the input signal.Second, SpectreRF computes it's transfer functions by looking at the continuous time waveforms, not the discrete time waveforms.  You can pass the output of a system through a sample & hold, which makes the results more akin to a discrete time response, but it will have a sin(x)/x distortion. I suspect that the differences you are seeing between SpectreRF and your abstract model are largely due to that distortion.  I could be wrong as I am having trouble understanding exactly what is being presented.To be more specific, if you plot the transfer function at the output of your integrator, artefacts anywhere in the signal are going to affect the result.  For example, if your opamp exhibits slew rate limiting, then distortion from that will show up in the results. In a real sampled system, the output of the integrator would be sampled as well, and so as long as you sampled after the op amp has settled, then the effect of slew rate limiting should be very small or negligible in the sampled result, even though it might be significant in the direct output of the integrator. Following the integrator by a sampler causes any artefact in the output of the integrator to be ignored if it is not present at the actual time of sampling. This is what I mean that the output of the sampler is akin to a discrete time signal, but it is not a discrete time signal. SpectreRF is computing the response for all points of continuous time. Thus, the spectrum of the signal at the output of the sampler is discrete time spectrum of the signal at is input convolved with the spectrum of its output pulse shape. If the output pulse shape is rectangular, then the spectrum at the output of the sample as computed by SpectreRF is not the discrete-time spectrum, but the discrete-time spectrum colored by the the sin(x)/x spectrum of the output pulse.I think you can use the sampled PAC or PXF feature of SpectreRF to get something that should exhibit less sin(x)/x distortion.  That would eliminate the need for the extra sample & hold.  Don't ask me how to use them, as they were added after I left and have never tried them.  Alternately, use the sample & holds, but simply shrink the hold time. Doing so make the SH behave more like a sampler; it broadens the sin(x)/x.A few more points. In general it is best not to say things like the Cadence results or the Matlab results as both Cadence and Matlab are general tool suites, and by using those names you are not really giving much information about how the results were computed.  Also, it is best not to ask a half dozen questions up front as it becomes difficult for people to respond and difficult to follow the conversation.-Ken Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #8 - Jan 20th, 2021, 5:29am   Dear Ken,Thank you 1.000.000 times for your answer, it seems to be the solution!-------------------------------------------So the key point summarized for all:============================The key point (for this case at least, the rest I have to check, then) is obviously to apply in Cadence the “PAC SAMPLED” ANALYSIS and moreover, CORRECTLY apply it (i.e. select a concrete time, and not “time averaged”, see below)! The S&H in the output can stay and so in this example “Vo_ext” can be taken for the result. With these actions, Cadence then matches Matlab perfectly, see the screenshot!-------------------------------------------(Sorry to mention the names of the involved programs again, and of course it’s not “politically correct”, but I think with this it’s most clear to everybody what I mean), or call it “Praxis (real Cadence circuit) means Theory (Matlab transfer function)” (On the other side, “PAC sampled” IS a Cadence product and another simulator might not offer this possibility, so I think I have to write "Cadence result" because its bounded to this program.))Before you have posted in the forum, you have written me a personal mail, where you also suggested to try the “PAC sampled” analysis (Periodic AC for the others), which I also followed, but I unfortunately abandoned this path in the first instance, because I got wrong results. I obviously just took the wrong result selection! => In my case, there was a choice of 2 sub-options: That is to say, if one choses the PAC result “time averaged” then one gets wrong results (or at least me in this case), so guys, also maybe you need to take option B: The concrete time “e.g. 799ms”, then you’ll get the correct results which PERFECTLY match to Matlab (or to “theory” if you want)! I have to find out what is behind this selection in more detail, but this I can do on my own, I think.To the other points you made:Ad “Shrink S&H hold time”:I already before tried to shrink in your S&H the “aperture” and as well the “tc” both by a factor of 100 (so aperture now = 1/10000 (instead of before 1/100), and tc = 1/100k now (instead of before 1/1k), and I also tried to shrink “tc” only by the same amount without touching “aperture”. Both did not change anything. Therefore I conclude, my choice was good.=> Is this what you meant by “simply shrink the hold time”? Or did you mean to modify something else? I'm not quite sure, please tell me.Ad “Sidebands”:As you exactly say, for a discrete-time system only plotting the 0 sideband (until fs/2) basically is interesting. Just for the reason that one could see the continuing magnitude line with -20 dB/dec for the Cadence result, I have plotted 2 more sidebands.Anyway, thank you VERY much, you did a great help,bernd2700 Back to top IP Logged
 Ken Kundert Global Moderator Offline Posts: 2358 Silicon Valley Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #9 - Jan 20th, 2021, 10:51am   Quote:Ad “Shrink S&H hold time”:I already before tried to shrink in your S&H the “aperture” and as well the “tc” both by a factor of 100 (so aperture now = 1/10000 (instead of before 1/100), and tc = 1/100k now (instead of before 1/1k), and I also tried to shrink “tc” only by the same amount without touching “aperture”. Both did not change anything. Therefore I conclude, my choice was good.=> Is this what you meant by “simply shrink the hold time”? Or did you mean to modify something else? I'm not quite sure, please tell me. Sorry, no. I meant that you should shrink the width of the hold pulse, or how long the output of the sampler holds the sampled value.  The issue is that the continuous time output spectrum is the discrete time spectrum of the sampled input convolved with the hold pulse. You want the hold pulse to be more of an impulse than a pulse.  You would implement this with a sampler that returns to zero a short time after outputting the sampled value. So you would not use a track-and-hold, but a return-to-zero sampler.Anyway, none of that is necessary if you use the Sampled PAC. It is basically doing it for you.-Ken Back to top IP Logged
 bernd2700 Community Member Offline Posts: 34 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #10 - Jan 22nd, 2021, 4:12am   Dear Ken,Thank you so much for this valuable information!Return to zero sampler:The sentence you write in your paper “Simulating Switched-Capacitor Filters with SpectreRF” on p. 24 “reduce this coloring by shrinking the output pulse width, but do not increase pulse height to compensate unless you use relref = alllocal.” didn’t jump into my face when skimming through the whole article, but now I see and understand the importance of it.==> Q1: Do you have a concrete “return to zero sampler” available somewhere, so a ready-to-use block, as it is the case with your S&H? Or maybe know somewhere a basis what I could modify then? If I understood correctly, this basically means, take your S&H but the “hold” portion of it modify in a way in order that this “hold” gets as short as possible and is zero in all the other times, is this right?In this case it’s also clear to me that “none that is necessary if I use the Sampled PAC”, and I am basically done with this, therefore I have mentioned the word “solution” in my previous post. However, at the moment I am not sure if for the future, e.g. within a complete LOOP, if I maybe would need such a “return to zero sampler”. Until now, I didn’t, since e.g. I exported the time-domain (transient) result of a complete 1st order delta-sigma after instantiating your S&H at the quantizer output and it perfectly fits to Matlab model result (both DFT’s I did with Matlab), so maybe I never would need the “return to zero sampler” but if you have something lying around, I would be happy to have it, if in case I once will need it.Supporting explaining pictures of theory:About the theory, which interests me as much: Do you have any “good” reference for your sentence “the CT output spectrum is the DT spectrum…”? I fully believe you, but I mean a reference with maybe some (maybe even animated) pictures in order that your statement is a bit easier to follow? Just in case you know some source, please let me know, this would be great!IS THIS NOW THE CORRECT PROCEDURE / METHODOLOGY to apply “everywhere”? :As I said: I need your S&H when I am comparing in 2 DFTs a whole delta-sigma from taking the transient output results. So I take the Matlab result and the Cadence transient result, this after your S&H, then everything fits perfectly. If I would not install your S&H, results would NOT fit. If I want now a small signal analysis, I LET THE CIRCUIT AS IT IS, I.E. WITH YOUR S&H INCLUDED, and make a Bode diagram with the “PAC sampled” again with the concrete time stated (e.g. 799ms, NOT take: "time averaged" result) after the S&H, and again everything fits perfectly.So, it seems for me now to finally have found the correct procedure when comparing a switched-cap Cadence circuit to a discrete-time (in “z”) theory (Matlab) model: Take a DUT (Device Under Test, e.g. a switched-cap integrator), instantiate at the interesting output node your S&H, and - depending what I am interested in - either take the transient output AFTER the S&H & do the DFTs, or take the “PAC sampled” also AFTER the S&H and compare the results in small signal.==> Q2: My utmost important question, I hope you will answer with “yes”, since now with this procedure everything fits fine, Matlab to Cadence, transient, as well as AC analysis. So do you agree that this general procedure to be applicable to ANY switched-cap circuit, when one wants to compare to a DT model? Or do I overlook (miss) an important detail anywhere and it just worked out in this example “by chance”?What is still unclear to me:I raised the above question, because what still is not clear to me: You write in your above mentioned paper on p. 15: “Be aware that the idealized sample and hold effectively adds a half clock cycle of delay to the transfer function that should be manually removed.”Obviously I lack here somehow important knowledge of theory behind:==> Q3: If this adds half a delay, I would expect to be the complete phase shifted, whatever it was before, by a CONSTANT factor of -180° at all frequencies. This is a contradiction in my head to: If I plot the transfer function of the S&H, the phase starts at 0° and linearly TURNS down to (moreover to) -90° at fs/2. So? ==> Q4: Why I am not seeing any difference then in the Bode diagram from the “PAC sampled” output results between the nets “Vo” and “Vo_ext” ( = before and after the S&H) when using the “PAC sampled” analysis?? I only see big differences when using the “normal PAC” without the “sampled” between those 2 nets, and also here not a CONSTANT phase shift by -180°, and moreover, results anyway do not fit to Matlab. But for the “PAC sampled” I did not remove anything manually although taking the node “Vo_ext” after the S&H and it still is the very same result as the node “Vo”, see the screenshot (blue and green lines) from my previous post (and fits to Matlab).Thank you very much in advance for clarifying the things a bit,bernd2700 Back to top IP Logged
 Juliaw ebbiavx New Member Offline Posts: 1 Re: How to compare Matlab/Theory <=> Cadence: Switched-cap. integrator: Mag Reply #11 - Oct 26th, 2021, 6:42am   How hard it is to understand all this, haha Back to top IP Logged
 Pages: 1