Skip to content

Commit

Permalink
conv2 for x-y separable kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 22, 2011
1 parent 7cd1f9e commit 823cff9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion j/abstractarray.j
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function hcat{T}(V::AbstractVector{T}...)
for j = 2:length(V)
if length(V[j]) != height; error("hcat: mismatched dimensions"); end
end
[ V[j][i] | i=1:length(V[1]), j=1:length(V) ]
[ V[j][i]::T | i=1:length(V[1]), j=1:length(V) ]
end

function vcat{T}(V::AbstractVector{T}...)
Expand Down
16 changes: 16 additions & 0 deletions j/signal.j
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ function conv{T}(u::Vector{T}, v::Vector{T})
return y
end

function conv2{T}(y::Vector{T}, x::Vector{T}, A::Matrix{T})
m = length(y)+size(A,1)-1
n = length(x)+size(A,2)-1
B = zeros(T, m, n)
B[1:size(A,1),1:size(A,2)] = A
y = fft([y;zeros(T,m-length(y))])./m
Y = repmat(reshape(y,m,1), 1, n)
x = fft([x;zeros(T,n-length(x))])./n
X = repmat(reshape(x,1,n), m, 1)
C = ifft2(fft(fft(B,(),2).*X,(),1).*Y)
if T <: Real
return real(C)
end
return C
end

function xcorr(u, v)
su = size(u,1); sv = size(v,1)
if su < sv
Expand Down

0 comments on commit 823cff9

Please sign in to comment.