2

I tried to plot a frequency response of a matched filter, which its response defined by:

H(f) = enter image description here

Since x (=f) runs from very big negative value to very big positive value, and y (=H(f)) runs only between 0 to 1, I used Pgfplots Semilogxaxis. My code look like this:

\begin{tikzpicture}
    \begin{semilogxaxis}[xlabel=Frequency, ylabel=Gain, xmin=1, xmax=20000, ymin=0, ymax=2]
      \addplot[domain=1:1e4,color=red] {((2*pi*x)^2 + 10^6)/(11(2*pi*x)^2 + 10^6 + 10^4)};
    \end{semilogxaxis}
\end{tikzpicture}

I got the next error message:

! Package PGF Math Error: You've asked me to divide '195.000000000' by '0.0', but I cannot divide any number by '0.0'.

I'm breaking my head over here, but can't figure out where exactly there's a division by 0.

Nevertheless, if anyone have a better idea how should I plot this function in Latex, I'd love to hear it, 'cause I've been sitting on this way-too-much-time...

Thanks.

3
  • 2
    I think there is just a typo in your equation, you're missing the * in (11*(2*pi*x).... Could you try if that fixes the problem? If it doesn't, could you complete your code snippet to make a minimal compilable example document (starting from \documentclass)? – Jake May 25 '16 at 7:02
  • 1
    Also, you say "x (=f) runs from very big negative value". I guess that's a typo, since that wouldn't work with a logarithmic domain, and you're correctly using a strictly positive domain in your code. – Jake May 25 '16 at 7:03
  • @Jake, actually - that wasn't a typo, more like heart-wish :) On one hand - x (=f) can be negative (by theorem, of course), and on the other hand - I want the scale of x to be logarithmic, since the change in x is way faster than the change in y. I know there's no negative values for log-based numbers, I just can't find the right option to plot x in logarithmic manner, and still have the negative values. Help will appreciate on this as well :) – Bak Itzik May 25 '16 at 13:09
3

It is just as Jake commented. The * for multiplication was missing.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{semilogxaxis}[xlabel=Frequency, ylabel=Gain, xmin=1, xmax=20000, ymin=0, ymax=2]
      \addplot[domain=1:1e4,color=red]
        {((2*pi*x)^2 + 10^6)/(11*(2*pi*x)^2 + 10^6 + 10^4)};
        %                       ^
        %  This `*' was missing |
    \end{semilogxaxis}
\end{tikzpicture}
\end{document}

enter image description here

I'd also use autosizing with turned off enlarge x limits and also smooth the curve.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{semilogxaxis}[
      enlarge x limits=false,
      xlabel=Frequency,
      ylabel=Gain]
      \addplot[domain=1:1e4,red,smooth]
        {((2*pi*x)^2 + 10^6)/(11*(2*pi*x)^2 + 10^6 + 10^4)};
    \end{semilogxaxis}
\end{tikzpicture}
\end{document}

enter image description here

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.