2

I want to draw this gaussian wave packet, with chirped frequency:

gaussian pulse

This plot was created with Desmos.com online tool.

The function that generated this waveform is

equation

My result with pgfplots is the following:

\documentclass[border=5pt]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}
\addplot [domain=0:4, samples=1000,line join=round,line cap=round]
{exp(-(x-2)^2)*cos(30*(deg(x)-2)-6.5*(deg(x)-2)^2)};
\end{axis}

\end{tikzpicture}
\end{document}

pgfplots result

So I understand that the math engine behind pgfplots has some difficulties at evaluating a squared term of x inside a cosine function (I tried plotting it without the -6.5*(deg(x)-2)^2 part, and the result is fine).

How can I overcome this?

4
  • 2
    I'm not sure but I think that you are using wrong the degoperator. Could be \addplot [domain=0:4, samples=1000,line join=round,line cap=round] {exp(-(x-2)^2)*cos(deg(30*(x-2)-6.5*(x-2)^2))}; what you need? May 6, 2021 at 20:01
  • @JuanCastaño Indeed! So it is correct to do cos(deg( f(x) ) ? @user241266 Maybe I will later change the quadratic term.
    – tush
    May 6, 2021 at 20:04
  • 1
    @tush Using (\x,{exp(-(\x-2)^2)*cos(deg(30*(\x)-2)-6.5*(\x-2)^2)}) will give the desired output
    – Excelsior
    May 6, 2021 at 20:07
  • @Excelsior All right, thanks a lot! I didn't notice that. Write an answer down below and I will mark this question as "Answered".
    – tush
    May 6, 2021 at 20:10

1 Answer 1

3

As mentioned by @Juan Castaño in the comments, the deg command convert the argument to degrees, so there is no need to use it for the quadratic expression.

no chirp v01

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
    \begin{tikzpicture}
        
        \begin{axis}
            \addplot[
            domain=-1:5, 
            samples=500,
            ]
            (\x,{exp(-(\x-2)^2)*cos(deg(30*(\x)-2)-6.5*(\x-2)^2)});
        \end{axis}
        
    \end{tikzpicture}
\end{document}

I personally give pgfplot the specific variable (i.e., \x), therefore I changed the expression of the function a bit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .