A DSP task in Erlang ?

Massimo Cesaro <>
Tue Jan 20 16:14:05 CET 2004


Hi,
I'm trying to simulate a DSP operation in Erlang, but I have
difficulties in figuring out the best way to write it.
My aim is to be able to sum the contents of several lists, e.g.:
if A = [1,2,3], and B = [1,2,3] and C = [1,2,3], I'd like to findaa fast
end efficient way to get a resulting list summing the elements such as D
= [3, 6, 9], i.e. the first element of the result is the sum of the
first element of the lists, etc.
I checked with list comprehension, but I found that they are useful to
write generators rather than adders:

Erlang (BEAM) emulator version 5.2 [source] [hipe]

Eshell V5.2  (abort with ^G)
1> A = [1,2,3].
[1,2,3]
2> B=[1,2,3].
[1,2,3]
3> C=[1,2,3].
[1,2,3]
4> [X+Y+Z || X <- A, Y <- B, Z <- C].
[3,4,5,4,5,6,5,6,7,4,5,6,5,6,7,6,7,8,5,6,7,6,7,8,7,8,9]
5>

clearly not what I need.

The "best way" I'm looking for is something that could be used in a soft
real time system. Given a fixed input length of lists, I'd like to have
a predictable and constant time of execution of the function.
Anybody have suggestions on this ?
Regards,
Massimo







More information about the erlang-questions mailing list