Source

psk31 / make-table

#!/usr/bin/perl
use warnings;
use strict;

print "static const uint8_t sin_table[] = {\n";
my $pi = 2.0 * atan2(1,0);
my $bits = 5;
my $count = 128;
my $scale = 1 << ($bits - 1);

for my $t (0..$count-1)
{
	my $s = sin($t * $pi * 2 / $count);
	my $i = $s * $scale;

	$i = -$scale		if $i < -$scale;
	$i =  $scale - 1	if $i >= $scale;

	printf "\t%d, // t=%d -> %.4f\n", $i + $scale, $t, $s;
}

print "};\n";