Genie’s Public Software Management Methods
| An example of creating a simple application using the Genie framework is also presented in Community Engee. |
All public methods of program management are presented here. genie to work with the framework Genie. To use them in Genie applications, connect the Engee tool library using the command using Engee inside your code (app.jl).
Methods genie
#
engee.genie.start — Function
EngeeDSP.modulate(x, fc, fs)
EngeeDSP.modulate(x, fc, fs, method)
EngeeDSP.modulate(x, fc, fs, method, opt)
Modulation for modeling communication systems.
Function call
-
(y, t) = modulate(x, fc, fs, method, opt)— modulates a real useful signalxusing a carrier frequencyfc, sampling ratesfsand the methodmethodwith additional parameters specified inopt, and returns the internal time vectort. -
(y, t) = modulate(x, fc, fs, method)— modulates a real useful signalxusing a carrier frequencyfc, sampling ratesfsand the methodmethod. -
(y, t) = modulate(x, fc, fs)— modulates a real useful signalxusing a carrier frequencyfcand sampling ratesfs. IfxIf the modulated signal is a matrix, then the modulated signal is calculated independently for each column and stored in the corresponding column.y.
Arguments
# Input arguments
-
x::AbstractVector{<:Real} | AbstractMatrix{<:Real}useful signal (real vector or matrix). Ifx— matrix, the modulation is performed independently for each column. -
fc::Realcarrier frequency (real positive scalar). -
fs::Real: sampling rate (real positive scalar). -
method::String: the modulation method. Possible values:"am"(by default),"amdsb-sc","amdsb-tc","amssb","fm","pm","pwm","ppm","qam". -
"am"or"amdsb-sc"Amplitude modulation (two side bands, suppressed carrier). Multipliesxper cosine with frequencyfc.y = x .* cos(2*pi*fc*t) -
"amdsb-tc": амплитудная модуляция (две боковые полосы, передаваемая несущая). Вычитает скалярoptизxи умножает результат на косинус с частотойfc.y = (x - opt) .* cos(2*pi*fc*t)Если
optне задан, используется значение по умолчаниюmin(min(x)), чтобы(x - opt)был неотрицательным и имел минимальное значение0. -
"amssb": амплитудная модуляция (одиночная боковая полоса). Умножаетxна косинус с частотойfcи добавляет преобразование Гильбертаx, умноженное на синус с частотойfc.y = x .* cos(2*pi*fc*t) + imag(hilbert(x)) .* sin(2*pi*fc*t)Этот метод эффективно устраняет верхнюю боковую полосу частот.
-
"fm": частотная модуляция. Создает косинус с мгновенной частотой, которая изменяется в зависимости отx.y = cos(2*pi*fc*t + opt*cumsum(x))cumsum(x)— прямоугольная аппроксимация интеграла отx.optиспользуется как константа частотной модуляции. Еслиoptне задан, по умолчанию:opt = (fc/fs)*2*pi/(max(max(x))), поэтому максимальное отклонение частоты отfcбудетfcГц. -
"pm": фазовая модуляция. Создает косинус с частотойfc, фаза которого изменяется в зависимости отx.y = cos(2*pi*fc*t + opt*x)optиспользуется как константа фазовой модуляции. Еслиoptне задан, по умолчанию:opt = pi/(max(max(x))), поэтому максимальное отклонение фазы будетπрад. -
"pwm": широтно-импульсная модуляция. Создает ШИМ-сигнал на основе длин импульсов вx. Элементыxдолжны быть в диапазоне[0, 1]и задают длительность каждого импульса в долях периода. Импульсы начинаются в начале каждого периода несущей (выровнены по левому краю). При вызовеmodulate(x, fc, fs, "pwm", "centered")импульсы центрируются в начале каждого периода. Длина(y, t)равнаlength(x)*fs/fc. -
"ppm": позиционно-импульсная модуляция. Создает сигнал с ПИМ из позиций импульсов вx. Элементыxдолжны быть в диапазоне[0, 1]и задают левый край каждого импульса в долях периода.opt— скаляр от0до1, задающий длину каждого импульса в долях периода (по умолчанию0.1). Длина(y, t)равнаlength(x)*fs/fc. -
"qam": квадратурная амплитудная модуляция. Создает сигнал изxиopt.y = x .* cos(2*pi*fc*t) + opt .* sin(2*pi*fc*t)Входной аргумент
optдолжен быть той же размерности, что иx. -
opt: дополнительные параметры для некоторых методов. Подробнее вmethod.
Типы данных: Float32, Float64, Char, String. Поддержка комплексных чисел: да.
# Output arguments
-
y: модулированный полезный сигнал (вещественный вектор или матрица). Сигналyимеет ту же размерность, что иx, за исключением методовmethod:"pwm"и"ppm". -
t: внутренний вектор времени.
EngeeDSP.demod(y, fc, fs, method)
EngeeDSP.demod(y, fc, fs, method, opt)
Демодуляция для моделирования систем связи.
Function call
-
x = demod(y, fc, fs, method, opt)— demodulates a real useful signalyusing a carrier frequencyfc, sampling ratesfsand the methodmethodwith additional parameters specified inopt. -
x = demod(y, fc, fs, method)— demodulates a real useful signalyusing a carrier frequencyfc, sampling ratesfsand the methodmethod.
Arguments
# Input arguments
-
y::AbstractVector{<:Real} | AbstractMatrix{<:Real}modulated signal (real vector or matrix). The signalyhas the same dimension asx, except for the methodsmethod:"pwm"and"pmm". -
fc::Realcarrier frequency (real positive scalar). -
fs::Real: sampling rate (real positive scalar). -
method::String: the modulation method. Possible values:"am"(by default),"amdsb-sc","amdsb-tc","amssb","fm","pm","pwm","pmm","qam".-
"am"or"amdsb-sc"Amplitude demodulation (two side bands, suppressed carrier). Multipliesyper cosine with frequencyfcand applies the Butterworth low-pass filter of the 5th order usingfiltfilt.julia x = y .* cos(2*pi*fc*t) b, a = butter(5, fc*2/fs) x = filtfilt(b, a, x) -
"amdsb-tc"Amplitude demodulation (two side bands, transmitted carrier). Multipliesyper cosine with frequencyfcand applies the Butterworth low-pass filter of the 5th order usingfiltfilt. If specifiedopt, then after filtering it subtracts the scalaroptfromx(by defaultopt = 0).
x = y .* cos(2__pi__fc*t) b, a = butter(5, fc*2/fs) x = filtfilt(b, a,x) *if there is an opt: x = x .- opt*-
"amssb"Amplitude demodulation (SSB). Multipliesyper cosine with frequencyfcand applies the Butterworth low-pass filter of the 5th order usingfiltfilt. x = y .* cos(2*pi*fc*t) b, a = butter(5, fc*2/fs) x = filtfilt(b, a, x)
-
* `"fm"`: frequency demodulation. Demodulates the FM signal by modulating the Hilbert transform `y` the complex exponent of the frequency `-fc` Hz and gets an instantaneous frequency as a result. * `"pm"` phase demodulation. Demodulates the FM signal by modulating the Hilbert transform `y` the complex exponent of the frequency `-fc` Hz and gets an instantaneous phase as a result. * `"pwm"` pulse width demodulation. Determines the pulse width of the PWM signal `y` and returns the vector `x`, the elements of which set the duration of each pulse in fractions of a period. Pulses in `y` They must start from the beginning of each carrier period (aligned to the left). When modulating `modulate(x, fc, fs, "pwm", "centered")` the pulses are centered at the beginning of each period. Length `y` equal to `length(x)*fs/fc`. * `"pmm"`: positional pulse demodulation. Determines the positions of the pulses in the signal `y`. For proper demodulation, the pulses should not overlap. Length `x` equal to `length(t)*fc/fs`. * `"qam"` Quadrature amplitude demodulation. Challenge `demod(y, fc, fs, "qam")` returns two signals `(x1, x2)`: multiplies `y` for cosine and sine with frequency `fc` and applies the Butterworth low-pass filter of the 5th order, using `filtfilt`.
x1 = y .* cos(2*pi*fc*t)
x2 = y .* sin(2*pi*fc*t)
b, a = butter(5, fc*2/fs)
x1 = filtfilt(b, a, x1)
x2 = filtfilt(b, a, x2)
-
opt: additional parameters for some methods. Learn more inmethod. Data types:Float32,Float64,Char,String. Support for complex numbers: yes.= # Output arguments
-
xdemodulated useful signal (real vector or matrix). For the method"qam"two signals are returned:(x1, x2).
julia EngeeDSP.square(t) EngeeDSP.square(t, duty)
A rectangular signal.
# Function call
- x = square(t) — generates a rectangular signal with a period 2π for time array elements t. Function square it is similar to a sine, but it creates a rectangular signal with values -1 and 1.
- x = square(t, duty) — generates a rectangular signal with a specified fill factor duty. Fill factor is the percentage of the signal period during which the rectangular signal is positive.
# Arguments
# # Input arguments
- t::AbstractArray{<:Real} time array (vector, matrix, or N-dimensional array). Function square works with the first dimension of the array t, the size of which is larger 1.
Data types: Float32, Float64.
- duty::Real: fill factor (default 50). The real scalar of 0 before 100.
Data types: Float32, Float64.
# # Output arguments
- x: a rectangular signal returned as a vector, matrix, or N-dimensional array.
julia engee.genie.start(app__path::String; devel::Bool=false, log__file::String="", open_url::Bool=false)
Launches the Genie application using the specified path.
After running, the function returns GenieApplicationStatus, in which the link to the application is available (also displayed in the console as … at 'https://…/genie/<appname>/'). The link can be opened in a new tab/window or copied to open manually.
Before usage of the command engee.genie.start make sure that if the application is a directory, it contains a file with the application code and extension.jl. Also delete the config and *.toml files (if present).
# Arguments
- app_path::String: path to the application directory. It can be relative or absolute.
- devel::Bool=false: A parameter for enabling development mode, in which changes to the code are applied without restarting the application.
- log_file::String="": parameter for specifying the path to the log file. If not specified, the logs are not saved separately.
- open_url::Bool=false: if true, then Engee will automatically open the application URL in the browser (the link is also available in the returned status).
# Examples
julia-repl
*Launching Genie via the app.jl application file, without development mode and saving logs*
engee.genie.start("/user/app.jl")
*Launching Genie via the app file.jl, with development mode and log saving*
engee.genie.start("/user/app.jl", devel=true, log_file="/user/logs.txt")
*Launching and automatically opening the application in the browser*
engee.genie.start("RadarCalculate", open_url=true) ```
#
engee.genie.stop — Function
engee.genie.stop(app_path::String)
Stops the running Genie application.
Arguments
app_path::String: path to the application directory. It can be relative or absolute.
Examples
# Stopping the app on an absolute path
engee.genie.stop("/user/app.jl")
# Stopping the app by relative path
engee.genie.stop("app.jl")
#
engee.genie.list — Function
engee.genie.list()
Displays a list of all running Genie applications.
Examples
engee.genie.list()
#
engee.genie.eval — Function
engee.genie.eval(code::AbstractString)
Executes the specified code in the Engee workspace outside the context of the running Genie application. It is used to run individual expressions, debug, or dynamically execute code without having to restart the application.
Arguments
code::AbstractString: a line of code for Julia, which will be executed in the workspace Engee.
Examples
engee.genie.eval("x = 5")
#
engee.genie.recv — Function
engee.genie.recv(wsVarName::AbstractString; context::Module=GenieAPI )
Returns the value of a variable from the specified context (module) in the Engee workspace during the execution of the Genie application.
By default, the variable is searched in the module GenieAPI, but if necessary, you can explicitly specify another module through the parameter context. So, if the variable is defined in another module, then the parameter is used context, indicating in which namespace to search for it.
Arguments
-
wsVarName::AbstractString: name of the variable whose value you want to get. -
context::Module=GenieAPI: the module in which the variable is searched. It is specified explicitly if the variable does not belong to the moduleGenieAPI.
Examples
# Getting the value of variable x from the Main module
engee.genie.recv("x", Main)
# Getting the value of variable a from the module by default
engee.genie.recv("a")
# Getting the value of the value variable from the user module
engee.genie.recv("value"; context=MyModule)
#
engee.genie.send — Function
engee.genie.send(wsVarName::AbstractString, value::Any)
Saves the value value to a variable wsVarName in the workspace Engee during the execution of the application on Genie.
If a variable with this name did not exist before, it will be created automatically. The function is convenient for transferring intermediate results or user data from the Genie application to the Engee session.
Arguments
-
wsVarName::AbstractString: name of the variable to which the value is assigned. -
value::Any: the value to be stored in the variable. Can be of any type.
Examples
# Assigning the value 124 to variable x
engee.genie.send("x", 124)
# Saving a string in the message variable
engee.genie.send("message", "Hello")