Signal Processing with Julia Language- Part 5
Sinusoidal Signals and Synthesis
# Load dependencies
using MySignalProcessing
using Plots
# with 100 samples every 2 full 2pi cycles
s = 1.0 * sinseq(0,100, 0.125);
plot(s.n, s.A, line=:stem, title="Sinusoidal signal", marker = :o, color = :blue)
The same thing can be accomplished with the canonical form constructor:$$x[n]=sin(\frac{M}{N} 2\pi n)$$
#N = 100
s = 1.0 * sinseqmn(0,100, 2, 100);
plot(s.n, s.A, line=:stem, title="Sinusoidal signal", marker = :o, color = :black)
# then going to take these negative cycles and flip polarity to positive cycles
# and then add back to the original signal.
# this will result in a signal with only positive cycles
M= stepseq(0,25);
m1 = M |> sigshift(25);
m2 = M |> sigshift(75);
p1 = plot(m1.n, m1.A, line=:stem, title="Step sequence", marker = :o, color = :red, xlims=(0,100))
p2 = plot(m2.n, m2.A, line=:stem, title="Step sequence", marker = :o, color = :red, xlims=(0,100))
plot(p1, p2, layout=(2,1))
mask = m1+m2
s2 = s*mask
plot(s2.n, s2.A, line=:stem, title="Sinusoidal signal", marker = :o, color = :blue)
s3 = s + (-1*s*mask) + (-1*s*mask);
plot(s3.n, s3.A, line=:stem, title="Sinusoidal signal", marker = :o, color = :blue)
s3 = s + (-1*s*mask) + (-1*s*mask);
s3 = s + (-2s*mask);
plot(s3.n, s3.A, line=:stem, title="Sinusoidal signal", marker = :o, color = :blue)
Similarly , we define Odd signals if :
$$Xₒ(-n) = Xₒ(n)$$
Any artibrary real-valued signal can be decomposed into Even and Odd signals:
$$x(n) = xₑ(n) + xₒ(n)$$
where even and odd signals are given by:
$$xₑ(n) = \frac{1}{2}[x(n) + x(-n)]$$
$$Xₒ(n) = \frac{1}{2}[x(n) - x(-n)]$$
With our building block function we have already defined, we can now define the synthesis of the signal.
Let $$x(n) = u(n) -u(n-10)$$ ,
Decompose it into Even and Odd signals:
x = stepseq(-30, 30) + (-1*stepseq(-20,20)|> sigshift(10))
plot(x.n, x.A, line=:stem, title="unit signal", marker = :o, color = :blue)
Xₑ = (1/2)* (x + (x |> sigfold)); # pls see fold function definition
Xₒ = (1/2)* (x + -1*(x |> sigfold)); # pls see fold function definition
p1 = plot(x.n, x.A, line=:stem, title="unit signal", marker = :o, color = :blue, label = "x")
p2 = plot(Xₑ.n, Xₑ.A, line=:stem, title="Even Part", marker = :o, color = :red, label = "Xₑ")
p3 = plot(Xₒ.n, Xₒ.A, line=:stem, title="Odd Part", marker = :o, color = :green, label = "Xₒ")
plot(p1, p2, p3, layout=(3,1))