FFHT library (Walsh Hadamard transform)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

FFHT library (Walsh Hadamard transform)

Postby sean_vn » Feb 19, 2019 1:26

https://github.com/FALCONN-LIB/FFHT
The code compiles to 2 objects. In linux you have to use ar to make a libwht.a static library from the objects.
wht.bi file:

Code: Select all

#inclib "wht"
declare sub fht_float alias "fht_float" (x as single ptr,ln2size as ulongint)
declare sub fht_double alias "fht_double" (x as double ptr,ln2size as ulongint)

function fht_popcount(p as ulong) as ulong
   p= p - ((p shr 1) and &h55555555)
   p = (p and &h33333333) + ((p shr 2) and &h33333333)
   return (((p + (p shr 4)) and &h0F0F0F0F) * &h01010101) shr 24
end function

'No scaling Walsh Hadamard transform
'Number of elements in x() must be a power of 2. eg dim as single x(7)=8 elements
'dim as single x(15)=16 elemets
sub wht_raw overload(x() as single)
   fht_float(@x(0),fht_popcount(ubound(x)))
end sub

sub wht_raw(x() as double)
   fht_double(@x(0),fht_popcount(ubound(x)))
end sub

'WHT with scaling
sub wht overload(x() as single)
   wht_raw(x())
   dim as ulong ub=ubound(x)
   dim as single scale=1.0/sqr(ub+1)
   for i as ulong=0 to ub
      x(i)*=scale
   next
end sub

sub wht(x() as double)
   wht_raw(x())
   dim as ulong ub=ubound(x)
   dim as double scale=1.0/sqr(ub+1)
   for i as ulong=0 to ub
      x(i)*=scale
   next
end sub



test.bas:

Code: Select all

#include "wht.bi"
dim as single x(15)   '16 elements labeled 0 to 15
for i as ulong=0 to ubound(x)
x(i)=1!:next

'Walsh Hadamard transform of 16 elements (n=4. 2 to the power of 4 = 16)
wht(x())
for i as ulong=0 to ubound(x)
print x(i):next

'undo because the transform is self-inverse
wht(x())
for i as ulong=0 to ubound(x)
print x(i):next

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests