Signal Processing with Julia Language- Part I
Signal Constructors
Installation
This notebook will make use of my package located at MySignalProcessing.jl.
For installation, please follow the instructions in the README.md file at my github repository.
Signal Constructors
In these examples, we deal with Discrete Signals only. Discrete Signal, are most often used in the context of digital communication and have many applications in various engineering fields.
A discrete signal is a sequence of samples, each of which is a value of a specific type.
The correct way to represent a discrete signal is to use two vectors:
-
x
: the time vector of the signal (horizontal axis), or in the discete case, the vector of the indices of the samples (n) -
y
: the values of the signal (vertical axis), or its amplitude, at each of the samples (n).
As such, I define a custom type, namely Signal
, which is a structure that contains the two vectors above.
It has a .A fieldname, which is the amplitude of the signal and a .n fieldname, which is the sample vector.
mutable struct signal
A::Vector{Real} #Amplitude of the signal
n::Vector{Real} #horizontal axis (discrete) of signal (in samples)
end
using MySignalProcessing
using Plots
s = signal(1.5, 10) # create a signal with amplitude 1.5 and number of samples 10, starting from sample 0
We can now check the fieldnames of signal s:
s |> typeof
s |> typeof |> fieldnames
s.A |> println
s.n |> println
plot(s.n, s.A, line= :stem, title = "Signal", marker=:o, size=(400,300), ylabel="Amplitude", xlabel="Sample")
s1 = signal(π , -5,7) # create a signal with amplitude pi , starting from sample -5 and ending at sample 7
plot(s1.n, s1.A, line= :stem, title = "Signal", marker=:o, size=(400,300), ylabel="Amplitude", xlabel="Sample")
A = rand(4);
n = [-1, 0, 1, 2];
s3 = signal(A, n);
plot(s3.n, s3.A, line= :stem, title = "Signal", marker=:o, size=(400,300), ylabel="Amplitude", xlabel="Sample")
The signal
type is the basic building block for various functions. Now you have a good understanding of the basic structure of a signal.