# Plot a chirped gaussian pulse with pgfplots

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

This plot was created with Desmos.com online tool.

The function that generated this waveform is

My result with pgfplots is the following:

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

\begin{axis}
{exp(-(x-2)^2)*cos(30*(deg(x)-2)-6.5*(deg(x)-2)^2)};
\end{axis}

\end{tikzpicture}
\end{document}


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?

• 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
• @tush Using (\x,{exp(-(\x-2)^2)*cos(deg(30*(\x)-2)-6.5*(\x-2)^2)}) will give the desired output 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

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.

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

\begin{document}
\begin{tikzpicture}

\begin{axis}

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