OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ -*- coding: utf-8 -*- |
| 2 | |
| 3 | $Id: x26.lua 9506 2009-02-11 08:23:29Z smekal $ |
| 4 | |
| 5 | Multi-lingual version of the first page of example 4. |
| 6 | |
| 7 | Copyright (C) 2009 Werner Smekal |
| 8 | |
| 9 | Thanks to the following for providing translated strings for this example: |
| 10 | Valery Pipin (Russian) |
| 11 | |
| 12 | This file is part of PLplot. |
| 13 | |
| 14 | PLplot is free software you can redistribute it and/or modify |
| 15 | it under the terms of the GNU General Library Public License as published |
| 16 | by the Free Software Foundation either version 2 of the License, or |
| 17 | (at your option) any later version. |
| 18 | |
| 19 | PLplot is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU Library General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU Library General Public License |
| 25 | along with PLplot if not, write to the Free Software |
| 26 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | --]] |
| 28 | |
| 29 | |
| 30 | --[[ |
| 31 | This example designed just for devices (e.g., psttfc and the |
| 32 | cairo-related devices) that use the pango and fontconfig libraries. The |
| 33 | best choice of glyph is selected by fontconfig and automatically rendered |
| 34 | by pango in way that is sensitive to complex text layout (CTL) language |
| 35 | issues for each unicode character in this example. Of course, you must |
| 36 | have the appropriate TrueType fonts installed to have access to all the |
| 37 | required glyphs. |
| 38 | |
| 39 | Translation instructions: The strings to be translated are given by |
| 40 | x_label, y_label, alty_label, title_label, and line_label below. The |
| 41 | encoding used must be UTF-8. |
| 42 | |
| 43 | The following strings to be translated involve some scientific/mathematical |
| 44 | jargon which is now discussed further to help translators. |
| 45 | |
| 46 | (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel . |
| 47 | (2) degrees is an angular measure, see |
| 48 | http://en.wikipedia.org/wiki/Degree_(angle) . |
| 49 | (3) low-pass filter is one that transmits (passes) low frequencies. |
| 50 | (4) pole is in the mathematical sense, see |
| 51 | http://en.wikipedia.org/wiki/Pole_(complex_analysis) . "Single Pole" |
| 52 | means a particular mathematical transformation of the filter function has |
| 53 | a single pole, see |
| 54 | http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html . |
| 55 | Furthermore, a single-pole filter must have an inverse square decline |
| 56 | (or -20 db/decade). Since the filter plotted here does have that |
| 57 | characteristic, it must by definition be a single-pole filter, see also |
| 58 | http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm |
| 59 | (5) decade represents a factor of 10, see |
| 60 | http://en.wikipedia.org/wiki/Decade_(log_scale) . |
| 61 | --]] |
| 62 | |
| 63 | -- initialise Lua bindings for PLplot examples. |
| 64 | dofile("plplot_examples.lua") |
| 65 | |
| 66 | x_label = { "Frequency", "Частота" } |
| 67 | y_label = { "Amplitude (dB)", "Амплитуда (dB)" } |
| 68 | alty_label = { "Phase shift (degrees)", "Фазовый сдвиг (градусы)" } |
| 69 | title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" } |
| 70 | line_label = { "-20 dB/decade", "-20 dB/десяток" } |
| 71 | |
| 72 | |
| 73 | ---------------------------------------------------------------------------- |
| 74 | -- plot1 |
| 75 | -- |
| 76 | -- Log-linear plot. |
| 77 | ---------------------------------------------------------------------------- |
| 78 | |
| 79 | function plot1(typ, x_label, y_label, alty_label, title_label, line_label) |
| 80 | freql = {} |
| 81 | ampl = {} |
| 82 | phase = {} |
| 83 | |
| 84 | pl.adv(0) |
| 85 | |
| 86 | -- Set up data for log plot |
| 87 | |
| 88 | f0 = 1 |
| 89 | for i = 1, 101 do |
| 90 | freql[i] = -2 + (i-1)/20 |
| 91 | freq = 10^freql[i] |
| 92 | ampl[i] = 20 * math.log10(1/math.sqrt(1+(freq/f0)^2)) |
| 93 | phase[i] = -180/math.pi*math.atan(freq/f0) |
| 94 | end |
| 95 | |
| 96 | pl.vpor(0.15, 0.85, 0.1, 0.9) |
| 97 | pl.wind(-2, 3, -80, 0) |
| 98 | |
| 99 | -- Try different axis and labelling styles. |
| 100 | pl.col0(1) |
| 101 | if typ==0 then |
| 102 | pl.box("bclnst", 0, 0, "bnstv", 0, 0) |
| 103 | else |
| 104 | pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0) |
| 105 | end |
| 106 | |
| 107 | -- Plot ampl vs freq |
| 108 | pl.col0(2) |
| 109 | pl.line(freql, ampl) |
| 110 | pl.col0(1) |
| 111 | pl.ptex(1.6, -30, 1, -20, 0.5, line_label) |
| 112 | |
| 113 | -- Put labels on |
| 114 | pl.col0(1) |
| 115 | pl.mtex("b", 3.2, 0.5, 0.5, x_label) |
| 116 | pl.mtex("t", 2, 0.5, 0.5, title_label) |
| 117 | pl.col0(2) |
| 118 | pl.mtex("l", 5, 0.5, 0.5, y_label) |
| 119 | |
| 120 | -- For the gridless case, put phase vs freq on same plot |
| 121 | if typ==0 then |
| 122 | pl.col0(1) |
| 123 | pl.wind(-2, 3, -100, 0) |
| 124 | pl.box("", 0, 0, "cmstv", 30, 3) |
| 125 | pl.col0(3) |
| 126 | pl.line(freql, phase) |
| 127 | pl.col0(3) |
| 128 | pl.mtex("r", 5, 0.5, 0.5, alty_label) |
| 129 | end |
| 130 | end |
| 131 | |
| 132 | |
| 133 | ---------------------------------------------------------------------------- |
| 134 | -- main |
| 135 | -- |
| 136 | -- Illustration of logarithmic axes, and redefinition of window. |
| 137 | ---------------------------------------------------------------------------- |
| 138 | |
| 139 | -- Parse and process command line arguments |
| 140 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
| 141 | |
| 142 | -- Initialize plplot |
| 143 | pl.init() |
| 144 | pl.font(2) |
| 145 | |
| 146 | -- Make log plots using two different styles. |
| 147 | for i = 1, 2 do |
| 148 | plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i], line_label[i]) |
| 149 | end |
| 150 | |
| 151 | pl.plend() |
| 152 |
