OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ $Id: x04.lua 9414 2009-01-29 22:48:54Z airwin $ |
| 2 | |
| 3 | Log plot demo. |
| 4 | Simple line plot and multiple windows demo. |
| 5 | |
| 6 | Copyright (C) 2008 Werner Smekal |
| 7 | |
| 8 | This file is part of PLplot. |
| 9 | |
| 10 | PLplot is free software you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Library Public License as published |
| 12 | by the Free Software Foundation either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | PLplot is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU Library General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU Library General Public License |
| 21 | along with PLplot if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | --]] |
| 24 | |
| 25 | -- initialise Lua bindings for PLplot examples. |
| 26 | dofile("plplot_examples.lua") |
| 27 | |
| 28 | ---------------------------------------------------------------------------- |
| 29 | -- plot1 |
| 30 | -- |
| 31 | -- Log-linear plot. |
| 32 | ---------------------------------------------------------------------------- |
| 33 | |
| 34 | function plot1(type) |
| 35 | freql = {} |
| 36 | ampl = {} |
| 37 | phase = {} |
| 38 | |
| 39 | pl.adv(0) |
| 40 | |
| 41 | -- Set up data for log plot |
| 42 | f0 = 1 |
| 43 | for i=1, 101 do |
| 44 | freql[i] = -2 + (i-1) / 20 |
| 45 | freq = 10^freql[i] |
| 46 | ampl[i] = 20 * math.log10(1 / math.sqrt(1 + (freq / f0)^2)) |
| 47 | phase[i] = -(180 / math.pi) * math.atan(freq / f0) |
| 48 | end |
| 49 | |
| 50 | pl.vpor(0.15, 0.85, 0.1, 0.9) |
| 51 | pl.wind(-2, 3, -80, 0) |
| 52 | |
| 53 | -- Try different axis and labelling styles. |
| 54 | pl.col0(1) |
| 55 | if type == 0 then |
| 56 | pl.box("bclnst", 0, 0, "bnstv", 0, 0) |
| 57 | end |
| 58 | |
| 59 | if type == 1 then |
| 60 | pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0) |
| 61 | end |
| 62 | |
| 63 | -- Plot ampl vs freq |
| 64 | pl.col0(2) |
| 65 | pl.line(freql, ampl) |
| 66 | pl.col0(1) |
| 67 | pl.ptex(1.6, -30, 1, -20, 0.5, "-20 dB/decade") |
| 68 | |
| 69 | -- Put labels on |
| 70 | pl.col0(1) |
| 71 | pl.mtex("b", 3.2, 0.5, 0.5, "Frequency") |
| 72 | pl.mtex("t", 2, 0.5, 0.5, "Single Pole Low-Pass Filter") |
| 73 | pl.col0(2) |
| 74 | pl.mtex("l", 5, 0.5, 0.5, "Amplitude (dB)") |
| 75 | |
| 76 | -- For the gridless case, put phase vs freq on same plot |
| 77 | if type == 0 then |
| 78 | pl.col0(1) |
| 79 | pl.wind(-2, 3, -100, 0) |
| 80 | pl.box("", 0, 0, "cmstv", 30, 3) |
| 81 | pl.col0(3) |
| 82 | pl.line(freql, phase) |
| 83 | pl.col0(3) |
| 84 | pl.mtex("r", 5, 0.5, 0.5, "Phase shift (degrees)") |
| 85 | end |
| 86 | end |
| 87 | |
| 88 | |
| 89 | ---------------------------------------------------------------------------- |
| 90 | -- main |
| 91 | -- |
| 92 | -- Illustration of logarithmic axes, and redefinition of window. |
| 93 | ---------------------------------------------------------------------------- |
| 94 | |
| 95 | -- Parse and process command line arguments |
| 96 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
| 97 | |
| 98 | -- Initialize plplot |
| 99 | pl.init() |
| 100 | pl.font(2) |
| 101 | |
| 102 | -- Make log plots using two different styles. |
| 103 | plot1(0) |
| 104 | plot1(1) |
| 105 | |
| 106 | pl.plend() |
| 107 |
