1

Hello and happy new year,

I am trying to create a continuous plot made of two different functions. Altough I am able to calculate and plot both of them correctly, I am not able to make the second function start on the end of the first one:

enter image description here

Both functions are calculated starting at a time of 0, but the red line should start at the end of the blue line, so it needs to be shifted to 0.2ns. I have tried using shift={(0.2,0)} on the second plot, but the data appears far away.

Thanks in advance :)

PS: I know that the red line appears on 0 because its domain is defined from 0 to 3.

My tex file is as follows:

\documentclass[class=IEEEtran]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

%- Declare parameters
\usetikzlibrary{math} % For computations. Variables must be declared in a tikzmath environment but can be used outside (almost anywhere)
\tikzmath{
    \Qfactor = 500; % Quality factor 
    \f0 =230; % Freq in GHz 
    \TimeConst = \Qfactor/(pi*\f0);
    \finalCharge = exp(-2*0.2/\TimeConst)-1; % Initial value for ringing tail
} 
\begin{tikzpicture} 
    \begin{axis}[
        axis lines = left,
        xmin=0, xmax=3,
        ymin=-30, ymax=5,
        ytick = {-30,-25,-20,-15,-10,-5,0,5},
        ylabel = { Normalized power (dB)},
        xlabel = {Time (ns)},
        width=3.15in,
        height=2.15in,
    ]
    \addplot+[no marks, domain=0:0.2,samples = 10] plot (\x, {10*log10(abs(exp(-2*\x/\TimeConst)-1))});
    % PLOT TO SHIFT:
    \addplot+[no marks, domain=0:3,samples = 50] plot (\x, {10*log10(abs(\finalCharge*exp(-2*\x/\TimeConst)))});   
    \end{axis}
\end{tikzpicture}
\end{document}
1

You can achieve this by simple math:

\documentclass[class=IEEEtran]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

%- Declare parameters
\usetikzlibrary{math} % For computations. Variables must be declared in a tikzmath environment but can be used outside (almost anywhere)
\tikzmath{
    \Qfactor = 500; % Quality factor 
    \f0 =230; % Freq in GHz 
    \TimeConst = \Qfactor/(pi*\f0);
    \finalCharge = exp(-2*0.2/\TimeConst)-1; % Initial value for ringing tail
} 
\begin{tikzpicture} 
    \begin{axis}[
        axis lines = left,
        xmin=0, xmax=3,
        ymin=-30, ymax=5,
        ytick = {-30,-25,-20,-15,-10,-5,0,5},
        ylabel = { Normalized power (dB)},
        xlabel = {Time (ns)},
        width=3.15in,
        height=2.15in,
    ]
    \addplot+[no marks, domain=0:0.2,samples = 10] plot (\x, {10*log10(abs(exp(-2*\x/\TimeConst)-1))});
    % PLOT TO SHIFT:
    \addplot+[no marks, domain=0.2:3,samples = 50] plot
        (\x, {
            10 * log10 (abs( \finalCharge * exp(-2 * (x - 0.2) / \TimeConst) ))
            }
        );   
    \end{axis}
\end{tikzpicture}
\end{document}

I don't really now know what the difference between \x and a regular x is, but you can also use (\x - 0.2) instead of (x - 0.2) if you want.

That's my output: enter image description here

1
  • I didn't even think about doing this... shame on me. Thanks for the remark about \x!
    – Jes
    Jan 5 '21 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.