Created
November 4, 2014 05:08
-
-
Save anj1/ebf84454bc288a88dbe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# T: type of underlying data | |
# N: dimensionality of filter | |
type ConvolveFilter{T,N} | |
fk::Array{Complex{T},N} | |
end | |
# apply a filter to data. | |
# If the dimensionality of the data (M) is larger than the filter (N), | |
# then apply the filter to the first N dimensions of the data. | |
*{T,N,M}(f::ConvolveFilter{T,N},x::Array{T,M}) = real(ifft(conj(f.fk) .* fft(x,1:N), 1:N)) | |
# transpose operation on filters is simple. | |
ctranspose{T,N}(f::ConvolveFilter{T,N}) = Filter1D{T,N}(conj(f.fk)) | |
# numerical manipulation of filters | |
# filter $op number | |
for op = (:.+, :.*, :.-, :./) | |
eval(quote | |
($op){T,N}(f::ConvolveFilter{T,N}, x::T)= ConvolveFilter{T,N}(($op)(f.fk, x)) | |
end) | |
eval(quote | |
($op){T,N}(x::T, f::ConvolveFilter{T,N})= ConvolveFilter{T,N}(($op)(f.fk, x)) | |
end) | |
end | |
# filter $op filter | |
for op = (:+, :-, :.+, :.-) | |
eval(quote | |
($op){T,N}(f::ConvolveFilter{T,N}, g::ConvolveFilter{T,N})= ConvolveFilter{T,N}(($op)(f.fk, g.fk)) | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment