1
--[[ -*- coding: utf-8 -*-
3
$Id: x26.lua 11717 2011-04-21 00:47:06Z airwin $
5
Multi-lingual version of the first page of example 4.
7
Copyright (C) 2009 Werner Smekal
9
Thanks to the following for providing translated strings for this example:
10
Valery Pipin (Russian)
12
This file is part of PLplot.
14
PLplot is free software you can redistribute it and/or modify
15
it under the terms of the GNU Library General Public License as published
16
by the Free Software Foundation either version 2 of the License, or
17
(at your option) any later version.
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.
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
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
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.
43
The following strings to be translated involve some scientific/mathematical
44
jargon which is now discussed further to help translators.
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
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) .
63
-- initialise Lua bindings for PLplot examples.
64
dofile("plplot_examples.lua")
66
x_label = { "Frequency", "Частота" }
67
y_label = { "Amplitude (dB)", "Амплитуда (dB)" }
68
alty_label = { "Phase shift (degrees)", "Фазовый сдвиг (градусы)" }
69
-- Short rearranged versions of y_label and alty_label.
71
{"Amplitude", "Phase shift"},
72
{"Амплитуда", "Фазовый сдвиг"}
74
title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" }
75
line_label = { "-20 dB/decade", "-20 dB/десяток" }
77
-- return single bit (for OR)
79
return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
82
-- logic OR for number values
86
for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
90
----------------------------------------------------------------------------
94
----------------------------------------------------------------------------
96
function plot1(type, x_label, y_label, alty_label, title_label, line_label, legend_text)
103
-- Set up data for log plot
107
freql[i] = -2 + (i-1)/20
109
ampl[i] = 20 * math.log10(1/math.sqrt(1+(freq/f0)^2))
110
phase[i] = -180/math.pi*math.atan(freq/f0)
113
pl.vpor(0.15, 0.85, 0.1, 0.9)
114
pl.wind(-2, 3, -80, 0)
116
-- Try different axis and labelling styles.
119
pl.box("bclnst", 0, 0, "bnstv", 0, 0)
121
pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0)
123
pl.abort("type must be 0 or 1")
132
pl.ptex(1.6, -30, 1, -20, 0.5, line_label)
136
pl.mtex("b", 3.2, 0.5, 0.5, x_label)
137
pl.mtex("t", 2, 0.5, 0.5, title_label)
139
pl.mtex("l", 5, 0.5, 0.5, y_label)
141
-- For the gridless case, put phase vs freq on same plot
144
pl.wind(-2, 3, -100, 0)
145
pl.box("", 0, 0, "cmstv", 30, 3)
147
pl.line(freql, phase)
148
pl.string(freql, phase, "*")
150
pl.mtex("r", 5, 0.5, 0.5, alty_label)
172
-- Data for the first legend entry.
173
opt_array[1] = pl.PL_LEGEND_LINE
175
text[1] = legend_text[1]
176
-- box data unused so initialize to arbitrary values.
180
box_line_widths[1] = 0
184
-- unused arbitrary data
187
symbol_numbers[1] = 0
190
-- Data for the second legend entry.
192
opt_array[2] = lor(pl.PL_LEGEND_LINE, pl.PL_LEGEND_SYMBOL)
194
text[2] = legend_text[2]
195
-- box data unused so initialize to arbitrary values.
199
box_line_widths[2] = 0
204
symbol_scales[2] = 1.
205
symbol_numbers[2] = 4
209
pl.scol0a( 15, 32, 32, 32, 0.70 )
211
legend_width, legend_height = pl.legend(
212
lor(pl.PL_LEGEND_BACKGROUND, pl.PL_LEGEND_BOUNDING_BOX), 0, 0.0, 0.0,
213
0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0,
214
1., text_colors, text,
215
box_colors, box_patterns, box_scales, box_line_widths,
216
line_colors, line_styles, line_widths,
217
symbol_colors, symbol_scales, symbol_numbers, symbols )
222
----------------------------------------------------------------------------
225
-- Illustration of logarithmic axes, and redefinition of window.
226
----------------------------------------------------------------------------
228
-- Parse and process command line arguments
229
pl.parseopts(arg, pl.PL_PARSE_FULL)
234
if nlang ~= (# y_label) or
235
nlang ~= (# alty_label) or
236
nlang ~= (# title_label) or
237
nlang ~= (# line_label) or
238
nlang ~= (# legend_text) then
239
pl.abort("All data must be expressed in the same number of languages")
245
-- Make log plots using two different styles.
247
plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i], line_label[i], legend_text[i])