Skip to content

Instantly share code, notes, and snippets.

@lendle
Created July 31, 2014 19:56
Show Gist options
  • Save lendle/897eea1e5458eedb8e43 to your computer and use it in GitHub Desktop.
Save lendle/897eea1e5458eedb8e43 to your computer and use it in GitHub Desktop.
module firmod
type FIR{in_t,coef_t}
in::Vector{in_t}
coef::Vector{coef_t}
function FIR (coef::Vector{coef_t})
new (zeros (in_t, size (coef)), copy (coef))
end
end
function shift! (f::FIR, u)
si = length(f.in)
for i =si-1:-1:1
f.in[i+1] = f.in[i]
end
f.in[1] = u
end
function compute1{in_t, coef_t}(f::FIR{in_t, coef_t})
s = zero (promote_type (in_t, coef_t))
size = length(f.coef)
for i = 1:size
s += f.in[i] * f.coef[i]
end
return s
end
function shift_compute1(f::FIR, u)
shift! (f, u)
return compute1 (f) #could replace with dot(f.in, f.coef)
end
function compute{in_t, coef_t}(f::FIR{in_t, coef_t}, u::Vector)
out = similar (u, promote_type (in_t,coef_t))
size = length (u)
for i = 1:size
out[i] = shift_compute1 (f, u[i])
end
return out
end
c = float ([1:4])
const g = FIR{Float64,Float64} (c)
h = FIR{Complex{Float64},Float64} (c)
j = float ([1:10])
k = compute (g, j)
function timeit()
n = 10
l = 1000000
u = zeros(Float64, l)
for i=1:n
v = compute (g, u)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment