Ejemplos de código en Julia de la Guía 1
Código auxiliar
# Cargo un par de paquetitos básicos
using DSP, Plots
# Y armo un par de funciones auxiliares
stem(args...; kwargs...) = sticks(args...;
marker=:circle,
leg=false,
kwargs...)
# Delta
d(n) = n == 0 ? 1. : 0.
# Escalón
u(n) = n >= 0 ? 1. : 0.
0.7s
Julia
u (generic function with 1 method)
1) Graficar
formula not implementedlet
ns = -4:4
x = -2 .* d.(ns .+ 2)
stem(ns, x;
xaxis="n",
title="a) -2d(n+2)")
end
0.6s
Julia
let
ns = -3:3
x = 2.0 .^ ns .* u.(ns)
stem(ns, x;
xaxis="n",
title="b) 2^n*u(n)")
end
0.5s
Julia
let
ns = -3:3
x = 2.0 .^ -ns .* u.(ns)
stem(ns, x;
xaxis="n",
title="c) 2^-n*u(n)")
end
0.6s
Julia
let
ns = -4:4
x = 2.0 .^ -ns .* u.(-ns)
stem(ns, x;
xaxis="n",
title="...")
end
0.7s
Julia
let
ns = 0:11
x = cos.(pi/3 .* ns) .* u.(ns .- 2)
stem(ns, x;
xaxis="n",
title="...")
end
0.6s
Julia
2) Corroborar sumas
sum(exp(-im*π/2*n) for n in 0:9)
0.3s
Julia
1.0-1.0im
sum(exp(im*π/2*n) for n in -2:7)
0.3s
Julia
-1.0-1.0im
sum((1/2)^n * exp(im*π/2*n) for n in 0:9)
0.3s
Julia
0.800781+0.400391im
sum(cos(π/2*n) for n in 0:9)
0.3s
Julia
1.0
4) Pulso rectangular
Supongamos inline_formula not implemented y inline_formula not implemented
let
N = 10
A = 7
ns = -5:15
xs = A .* (u.(ns) - u.(ns .- N))
stem(ns, xs)
end
0.5s
Julia
10) Submuestreo y sobremuestreo
sub2(x) = x[1:2:end]
function sobre2(x)
out = zeros(2 * length(x))
out[1:2:end] = x
return out
end
# Ejemplo
x = cos.(0:0.3:10)
stem(x)
0.5s
Julia
stem(sub2(x))
0.5s
Julia
stem(sobre2(x))
0.5s
Julia