Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created March 6, 2014 15:58
Show Gist options
  • Save kuniyoshi/9392862 to your computer and use it in GitHub Desktop.
Save kuniyoshi/9392862 to your computer and use it in GitHub Desktop.
a convolution program.
-module(fir).
-export([convolute/2]).
convolute_acc(F, G, Acc) when length(F) =:= 2 * length(G) - 1 ->
lists:reverse(Acc);
convolute_acc(F, G, Acc) ->
V = lists:sum(lists:map(fun({A, B}) -> A * B end,
lists:zip(lists:sublist(F, length(G)), G))),
convolute_acc(tl(F), G, [V | Acc]).
convolute(F, G) ->
F2 = lists:append([lists:duplicate(length(G) - 1, 0.0), F, lists:duplicate(length(G), 0.0)]),
convolute_acc(F2, lists:reverse(G), []).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment