Signal Processing with Julia Language- Part 4
Theory is nearly Implementation with Julia...
Background Information
in previous posts we have seen how to create a signal with a given amplitude and sample range, as well as presented some basic functions for signal processing. Now we are ready to put these functions to good use.
For more information, pls see the following links:
For background information, pls see Signal Processing with Julia Language- Part I
In part 1 we discussed how to represent a signal, and constructor functions using my signal package in Julia.
My signal processing package can be found at MySignalProcessing.jl
# Load dependencies
using MySignalProcessing
using Plots
given the signal $$x(n) = \{1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1\} \text{ , where } n= \{-2, -1 , 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}$$
- The first part is obtained by shifting x(n) by +5 and the second part by shifting x(n) by -4.
x = [1,2,3,4,5,6,7,6,5,4,3,2,1]; #amplitude vector
n = [-2,-1,0,1,2,3,4,5,6,7,8,9,10]; #sample position vector
s = signal(x,n) # create signal from the two vectors
# Original signal
p1 = plot(s.n, s.A, line =:stem, marker=:o, color=:blue, label = "s", ylims = (-10,15),
xlims=(-10,20), framestyle = :origin,xtick=-10:20,ytick=-10:15)
x₂ = 2.0 * ( s |> sigshift(5) ) ;
plot(x₂.n, x₂.A, line =:stem, marker=:o, color=:red, label = "x₂", ylims = (-10,15),
xlims=(-10,20), framestyle = :origin, xtick=-10:20, ytick=-10:15)
x₃ = -3.0 * ( s |> sigshift(-4) )
plot(x₃.n, x₃.A, line =:stem, marker=:o, color=:green, label = "x₃", ylims = (-25,15),
xlims=(-10,20), framestyle = :origin, xtick=-10:20, ytick=-25:15)
x₁ = x₂ + x₃
plot(x₁.n, x₁.A, line =:stem, marker=:o, color=:black, label = "x₁", ylims = (-25,15),
xlims=(-10,20), framestyle = :origin, xtick=-10:20, ytick=-25:15)
x₁ = 2.0 * ( s |> sigshift(5) ) + (-3.0) * ( s |> sigshift(-4) )
p1 = plot(s.n, s.A, line =:stem, marker=:o, color=:blue, label = "s", ylims = (-10,15),
xlims=(-10,20), framestyle = :origin, xtick=-10:20, ytick=-10:15);
p2 = plot(x₁.n, x₁.A, line =:stem, marker=:o, color=:black, label = "x₁", ylims = (-25,15),
xlims=(-10,20), framestyle = :origin, xtick=-10:20, ytick=-25:15);
plot(p1,p2, layout = (2,1), size = (800,800))