A DSP task in Erlang ?
Massimo Cesaro
massimo.cesaro@REDACTED
Tue Jan 20 17:12:09 CET 2004
On Tue, 2004-01-20 at 17:11, Corrado Santoro wrote:
> Hi Massimo,
> maybe do you need something like this?
>
> -module(l).
> -export ([add/2, add_list/1]).
>
> add ([H1], [H2]) ->
> [H1 + H2];
> add ([H1 | T1], [H2 | T2]) ->
> [ H1 + H2 | add (T1, T2)].
>
> add_list ([A , B]) ->
> add (A, B);
> add_list ([H | T]) ->
> add (H, add_list(T)).
>
> 16> l:add([1,2,3],[4,5,6]).
> [5,7,9]
> 17> l:add_list([[1,2,3],[4,5,6],[7,8,9],[11,12,13],[1,2,3]]).
> [24,29,34]
this was my first attempt.
>
> or the following version that takes advantage of tail recursion?
>
> -module(ll).
> -export ([add/2, add_list/1]).
>
> add (L1, L2) ->
> lists:reverse (add (L1, L2, [])).
>
> add ([H1], [H2], Acc) ->
> [H1 + H2 | Acc];
> add ([H1 | T1], [H2 | T2], Acc) ->
> add (T1, T2, [H1 + H2 | Acc]).
>
> add_list ([A , B]) ->
> add (A, B);
> add_list ([H | T]) ->
> add (H, add_list(T)).
>
>
> The complexity should be O(n*m), with n=number of lists and m=size of each
> list. This means that the execution time should be predictable.
>
> Is this what you need?
Nice. I'm developing an audio conference with N pars in the conference.
To keep up with the RTP streaming rate, I must sum from 3 to 8 packets
(my lists) in less than 10ms. Afterward, I have to subtract for each
part its own source, basically to cancel echo, and stream everything
back on the network.
This should be done agan in less than 10 ms, so the total processing
time should be lower than 20 ms.
I'm concerned of what happens if and when the garbage collector kicks
in.
Anyway, I'm just starting to test this approach as well.
By the way, since I've read the last paper on HiPE, something HiPE
friendly would be even more useful...
>
> Ciao,
> -Corrado
Massimo
>
> Quoting Massimo Cesaro <massimo.cesaro@REDACTED>:
>
> > 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
> >
> >
> >
> >
> >
>
>
>
> --
> ======================================================
> Eng. Corrado Santoro, Ph.D.
>
> University of Catania - Engineering Faculty
> Department of Computer Science and
> Telecommunications Engineering
> Viale A. Doria, 6 - 95125 CATANIA (ITALY)
>
> Tel: +39 095 7382364 Fax: +39 095 338280
> +39 095 7382365
> +39 095 7382380
>
> EMail: csanto@REDACTED
> Personal Home Page:
> http://www.diit.unict.it/users/csanto
>
> NUXI Home Page:
> http://nuxi.iit.unict.it
> ======================================================
>
> -------------------------------------------------
> This mail sent through IMP: http://www.cdc.unict.it/
More information about the erlang-questions
mailing list