DSPRelated.com
Forums

statistical signal processing on Blackfin

Started by Marko Kanadi March 7, 2009
Hi, I'm Marko from DSP research group of Institut Teknologi Bandung
Currently I'm tackling with the implementation of a statistical signal processing algorithm on Blackfin BF561EZ. I just started working with the machine thus, you can consider me as a newbie.
In my work, the machine needs to handle calculations with real numbers.
The problem is even the algorithm is successfully compiled, the machine doesn't give the expected performance of the algorithm.
Well, I have implemented the algorithm before on a floating-point based DSP: TMS320C6713 by Texas Instruments and it works well.
I just copied the same algorithm and doing some modification by changing the initialization of the variables from 'float' to 'fract32'.
I thought it would work, but I was wrong..

Can anyone explain the problem I face here?
Or.. Has anyone successfully implemented some statistical signal processing algorithm on Blackfin board (of any type)? I would really appreciate if you can give me some hints and tips for the implementation.

Thank you before

________________________________

Regards,
Marko Kanadi

________________________________
Howdy Marko,

I have not worked with Blackfin, but I have converted code from
floating to fixed point. Check your numbers - if any are greater
than one to start with you will need to scale the entire algorithm
so that all numbers are in the range -1...+1, and also look at
points inside the algorithm to make sure you can account for values
that do exceed one.

Fixed point representation has to have an external scale factor, for
floating point you can keep the scale factor in the calculation. That
would be the first place to look. You may have to modify the algorithm
too, but hopefully not. It depends on how things add up and where you
get overflows (or underflows if that is important).

Patience, persistence, truth,
Dr. mike

On Sat, 7 Mar 2009, Marko Kanadi wrote:

> Hi, I'm Marko from DSP research group of Institut Teknologi Bandung
> Currently I'm tackling with the implementation of a statistical signal processing algorithm on Blackfin BF561EZ. I just started working with the machine thus, you can consider me as a newbie.
> In my work, the machine needs to handle calculations with real numbers.
> The problem is even the algorithm is successfully compiled, the machine doesn't give the expected performance of the algorithm.
> Well, I have implemented the algorithm before on a floating-point based DSP: TMS320C6713 by Texas Instruments and it works well.
> I just copied the same algorithm and doing some modification by changing the initialization of the variables from 'float' to 'fract32'.
> I thought it would work, but I was wrong..
>
> Can anyone explain the problem I face here?
> Or.. Has anyone successfully implemented some statistical signal processing algorithm on Blackfin board (of any type)? I would really appreciate if you can give me some hints and tips for the implementation.
>
> Thank you before
>
> ________________________________
>
> Regards,
> Marko Kanadi
>
> ________________________________
>
Thank you Mike for your reply,

If you don't mind, I still have several questions to ask:
- when I convert the integer (int) to fractional (fract32) by commands (for example):
int a0;
fract32 b = 0;
b = (fract32) a;
will a be automatically in the range : -1 < a < 1? Or I should scale it separately by dividing a by the max number of integer (in case of int32 : 2^32)?
- I wonder how the shift function works in fixed-point calculation. When I read some methods in fixed-point calculation, some give me hint to shift the number several bits. For 32 bit integer, it is written that it is better to shift the number 16 bit to the right (which means that the number is divided by 2^16). I still don't understand why I need to do this. Even though I have tried and it worked, but if I didn't shift it, the algorithm didn't work.
- Can I multiply a fract16 variable with another fract16 variable and results in a fract16 variable too?
I used Blackfin built-in functions and if I use a function which returns 16 bit results
mult_fr1x16(fract16 x1, fract16 x2
it didn't work..
But when I used a function which returns 32 bit results, even though I still need to saturate it with the another built-in functions
mult_fr1x32(fract16 x1, fract16 x2)
sat_fr1x32(fract32 y)
it worked.
Why I can not use the function which returns a 16 bit results from two 16-bit input? Why I need to use the other function which returns the 32 bit and why I need to saturate it? I still don't have any idea about this

I really hope you can explain me about fixed-point mathematics. I have no idea about how to program when I don't understand about what happens with the machines when it multiplies, add, or any other operation.

Thank you before,
________________________________

Regards,
Marko Kanadi

________________________________

________________________________
From: Mike Rosing
To: Marko Kanadi
Cc: a...
Sent: Saturday, March 7, 2009 11:09:14 PM
Subject: Re: [adsp] statistical signal processing on Blackfin

Howdy Marko,

I have not worked with Blackfin, but I have converted code from
floating to fixed point. Check your numbers - if any are greater
than one to start with you will need to scale the entire algorithm
so that all numbers are in the range -1...+1, and also look at
points inside the algorithm to make sure you can account for values
that do exceed one.

Fixed point representation has to have an external scale factor, for
floating point you can keep the scale factor in the calculation. That
would be the first place to look. You may have to modify the algorithm
too, but hopefully not. It depends on how things add up and where you
get overflows (or underflows if that is important).

Patience, persistence, truth,
Dr. mike

On Sat, 7 Mar 2009, Marko Kanadi wrote:

> Hi, I'm Marko from DSP research group of Institut Teknologi Bandung
> Currently I'm tackling with the implementation of a statistical signal processing algorithm on Blackfin BF561EZ. I just started working with the machine thus, you can consider me as a newbie.
> In my work, the machine needs to handle calculations with real numbers.
> The problem is even the algorithm is successfully compiled, the machine doesn't give the expected performance of the algorithm.
> Well, I have implemented the algorithm before on a floating-point based DSP: TMS320C6713 by Texas Instruments and it works well.
> I just copied the same algorithm and doing some modification by changing the initialization of the variables from 'float' to 'fract32'.
> I thought it would work, but I was wrong..
>
> Can anyone explain the problem I face here?
> Or.. Has anyone successfully implemented some statistical signal processing algorithm on Blackfin board (of any type)? I would really appreciate if you can give me some hints and tips for the implementation.
>
> Thank you before
>
> ________________________________
>
> Regards,
> Marko Kanadi
>
> ________________________________
>
On Sun, 8 Mar 2009, Marko Kanadi wrote:

> Thank you Mike for your reply,
>
> If you don't mind, I still have several questions to ask:
> - when I convert the integer (int) to fractional (fract32) by commands (for example):
> int a0;
> fract32 b = 0;
> b = (fract32) a;
> will a be automatically in the range : -1 < a < 1? Or I should scale it separately by dividing a by the max number of integer (in case of int32 : 2^32)?

Good question - I don't know the compiler. If you have a debugger,
single step through that and watch what it does. It might set it
to max (7fffffff...), it might set it to zero, or it might scale it.
To be safe, you should scale everything yourself.

> - I wonder how the shift function works in fixed-point calculation.
>When I read some methods in fixed-point calculation, some give me hint to
>shift the number several bits. For 32 bit integer, it is written that
>it is better to shift the number 16 bit to the right (which means that
>the number is divided by 2^16). I still don't understand why I need to do
>this. Even though I have tried and it worked, but if I didn't shift it,
>the algorithm didn't work.

If that is just before a multiply, then what you are doing is using
integer (not fractional) math - 16 x 16 => 32 bits and it still fits
in a register. For fractional math, that shouldn't be necessary.

> - Can I multiply a fract16 variable with another fract16 variable and
>results in a fract16 variable too?

No, it should be a 32 bit result. But the compiler may do a shift for
you so it's worth testing.

> I used Blackfin built-in functions and if I use a function which
>returns 16 bit results
> mult_fr1x16(fract16 x1, fract16 x2
> it didn't work..
> But when I used a function which returns 32 bit results, even though
>I still need to saturate it with the another built-in functions
> mult_fr1x32(fract16 x1, fract16 x2)
> sat_fr1x32(fract32 y)
> it worked.
> Why I can not use the function which returns a 16 bit results from
>two 16-bit input? Why I need to use the other function which returns the
>32 bit and why I need to saturate it? I still don't have any idea about
>this

It's in the hardware - the processor core is 16 bit and the result of a
multiply is the full 32 bits so you don't lose accuracy. The accumulator
should be 36 bits so you can deal with summation overflow as well, but
unless you program in assembler you won't see that.

> I really hope you can explain me about fixed-point mathematics. I
>have no idea about how to program when I don't understand about what
>happens with the machines when it multiplies, add, or any other
>operation.

Get hold of the hardware manual:
http://www.analog.com/en/embedded-processing-dsp/blackfin/processors/manuals/resources/index.html
and look at the core. Then watch your code either on a simulator or with
a debugger and see what the registers do. Things will make a lot more
sense then!

The essence of fixed point is that for _integer_ math you lose the most
significant bits and for _fractional_ math you lose the least significant
bits. Both have serious problems, but in different conditions. The
Blackfin does both, so you need to set up the core to do what you want. I
don't know how to tell the compiler to always code for fractional rather
than integer, but somebody out here must know! That's just one more
reason why I like sticking to assembler - I control the outcome!

Good luck and have fun learning!

Patience, persistence, truth,
Dr. mike
Hi,

It has nothing to do with statistical signal processing. Your trouble comes our of implementing a floating point algorithm on a fixed point processor; all the math will be emulated.

Instead of a very high speed double core fixed point processor, you could have kept with a lower speed processor, but floating point; nowadays all of the newer SHARCs are SIMD (starting from the 21160, aka Hammerhead), which for parallelizable / vectorizable algorithms is almost the same as a dual core.

Otherwise, be prepared to do a good job converting your algorithm from floating point to fixed point. If you know your algorithm very well, you have good chances to know when and how to scale, truncate, etc, etc, etc...

Looks like a lot of work and fun ahead of you.

Regards,


Jaime Andr Aranguren Cardona
j...@ieee.org
j...@computer.org

________________________________
From: Marko Kanadi
To: a...
Sent: Saturday, March 7, 2009 5:21:56 AM
Subject: [adsp] statistical signal processing on Blackfin
Hi, I'm Marko from DSP research group of Institut Teknologi Bandung
Currently I'm tackling with the implementation of a statistical signal processing algorithm on Blackfin BF561EZ. I just started working with the machine thus, you can consider me as a newbie.
In my work, the machine needs to handle calculations with real numbers.
The problem is even the algorithm is successfully compiled, the machine doesn't give the expected performance of the algorithm.
Well, I have implemented the algorithm before on a floating-point based DSP: TMS320C6713 by Texas Instruments and it works well.
I just copied the same algorithm and doing some modification by changing the initialization of the variables from 'float' to 'fract32'.
I thought it would work, but I was wrong..

Can anyone explain the problem I face here?
Or.. Has anyone successfully implemented some statistical signal processing algorithm on Blackfin board (of any type)? I would really appreciate if you can give me some hints and tips for the implementation.

Thank you before



________________________________

Regards,
Marko Kanadi

________________________________