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

signal(A::Real, n::Int) Constructor

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
signal(Real[1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5], Real[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

We can now check the fieldnames of signal s:

s |>  typeof
signal
s |> typeof |> fieldnames
(:A, :n)
s.A |> println
Real[1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5]
s.n |> println
Real[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
plot(s.n, s.A, line= :stem, title = "Signal", marker=:o, size=(400,300), ylabel="Amplitude", xlabel="Sample")

signal(A::Real, start::Int, stop::Int) Constructor

s1 = signal(π , -5,7) # create a signal with amplitude pi , starting from sample -5 and ending at sample 7
signal(Real[3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793], Real[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7])
plot(s1.n, s1.A, line= :stem, title = "Signal", marker=:o, size=(400,300), ylabel="Amplitude", xlabel="Sample")

signal(A::Vector, n::Vector) Constructor

With this constructor, we can buld a signal by passing two vectors to the function, one for the amplitude and one for the sample vector.

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.