SharedVLSI_L4.sagewsOpen in CoCalc
def sinc(t):
	if t == 0:
		return 1
	else:
		return N(sin(pi*t)/(pi*t))

def lanczos2(t):
	if -2 < t < 2:
		return sinc(t)*sinc(t/2)
	else:
		return 0
plot(lanczos2, (x, -5, 5))
/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
def h(n, L):
	return lanczos2(n/L-2)
L = 160
M = 147

L = 3
M = 4

coeffs = []
for n in range(4*L):
    #print n, N(n/L)-2, lanczos2(n/L - 2)
    coeffs.append(lanczos2(n/L - 2))
list_plot(coeffs)
import numpy
cf = numpy.array(coeffs)
#list(cf)
new_coeff = cf/sum(cf)*L
print list(new_coeff)
[0.0, -0.031284299585499609, -0.084665619314517659, 0.0, 0.33866247725807064, 0.78210748963749033, 0.99035990400891194, 0.78210748963749033, 0.33866247725807064, 0.0, -0.084665619314517659, -0.031284299585499609]
rounded_coeff = [int(round(i)) for i in (cf*2^15)]
max(rounded_coeff), min(rounded_coeff)
(32768, -2801)
import numpy as np
np.array(rounded_coeff)
array([ 0, -1035, -2801, 0, 11205, 25878, 32768, 25878, 11205, 0, -2801, -1035])
import struct
for c in new_coeff:
    c = round(c*2^15/4)
    if c >= 2**15 - 1:
        c = 2**15 - 1
    print struct.pack('>h', c).encode('hex')
0000 0000 0000 ffff ffff fffe fffd fffc fffb fff9 fff8 fff6 fff4 fff2 ffef ffed ffea ffe7 ffe4 ffe1 ffdd ffd9 ffd5 ffd1 ffcd ffc9 ffc4 ffbf ffba ffb5 ffaf ffaa ffa4 ff9e ff98 ff91 ff8b ff84 ff7d ff76 ff6f ff67 ff60 ff58 ff50 ff48 ff40 ff38 ff2f ff26 ff1e ff15 ff0c ff03 fefa fef0 fee7 fedd fed4 feca fec0 feb7 fead fea3 fe99 fe8f fe85 fe7b fe71 fe67 fe5d fe53 fe49 fe3f fe35 fe2b fe22 fe18 fe0e fe05 fdfb fdf2 fde9 fde0 fdd7 fdce fdc5 fdbd fdb5 fdad fda5 fd9d fd96 fd8f fd88 fd81 fd7b fd75 fd6f fd69 fd64 fd5f fd5b fd57 fd53 fd4f fd4c fd4a fd47 fd46 fd44 fd43 fd43 fd43 fd43 fd44 fd46 fd48 fd4a fd4d fd51 fd55 fd59 fd5f fd64 fd6b fd72 fd7a fd82 fd8b fd94 fd9e fda9 fdb5 fdc1 fdce fddb fde9 fdf8 fe08 fe18 fe2a fe3b fe4e fe61 fe75 fe8a fea0 feb6 fecd fee5 fefe ff17 ff32 ff4d ff69 ff85 ffa3 ffc1 ffe0 0000 0021 0042 0064 0088 00ab 00d0 00f6 011c 0143 016b 0194 01bd 01e8 0213 023f 026b 0299 02c7 02f6 0326 0356 0388 03ba 03ec 0420 0454 0489 04bf 04f5 052c 0564 059c 05d5 060f 0649 0684 06bf 06fb 0738 0775 07b3 07f1 0830 0870 08b0 08f0 0931 0972 09b4 09f6 0a39 0a7c 0ac0 0b03 0b48 0b8c 0bd1 0c16 0c5b 0ca1 0ce7 0d2d 0d73 0dba 0e00 0e47 0e8e 0ed5 0f1c 0f63 0faa 0ff2 1039 1080 10c7 110e 1155 119c 11e3 122a 1270 12b7 12fd 1343 1388 13ce 1413 1457 149c 14e0 1524 1567 15aa 15ec 162e 1670 16b1 16f1 1731 1770 17af 17ed 182b 1868 18a4 18df 191a 1954 198e 19c6 19fe 1a35 1a6b 1aa0 1ad5 1b08 1b3b 1b6d 1b9e 1bce 1bfd 1c2b 1c58 1c83 1cae 1cd8 1d01 1d29 1d50 1d75 1d9a 1dbd 1de0 1e01 1e21 1e40 1e5d 1e7a 1e95 1eaf 1ec8 1edf 1ef6 1f0b 1f1f 1f32 1f43 1f53 1f62 1f70 1f7c 1f87 1f91 1f99 1fa0 1fa6 1fab 1fae 1fb0 1fb1 1fb0 1fae 1fab 1fa6 1fa0 1f99 1f91 1f87 1f7c 1f70 1f62 1f53 1f43 1f32 1f1f 1f0b 1ef6 1edf 1ec8 1eaf 1e95 1e7a 1e5d 1e40 1e21 1e01 1de0 1dbd 1d9a 1d75 1d50 1d29 1d01 1cd8 1cae 1c83 1c58 1c2b 1bfd 1bce 1b9e 1b6d 1b3b 1b08 1ad5 1aa0 1a6b 1a35 19fe 19c6 198e 1954 191a 18df 18a4 1868 182b 17ed 17af 1770 1731 16f1 16b1 1670 162e 15ec 15aa 1567 1524 14e0 149c 1457 1413 13ce 1388 1343 12fd 12b7 1270 122a 11e3 119c 1155 110e 10c7 1080 1039 0ff2 0faa 0f63 0f1c 0ed5 0e8e 0e47 0e00 0dba 0d73 0d2d 0ce7 0ca1 0c5b 0c16 0bd1 0b8c 0b48 0b03 0ac0 0a7c 0a39 09f6 09b4 0972 0931 08f0 08b0 0870 0830 07f1 07b3 0775 0738 06fb 06bf 0684 0649 060f 05d5 059c 0564 052c 04f5 04bf 0489 0454 0420 03ec 03ba 0388 0356 0326 02f6 02c7 0299 026b 023f 0213 01e8 01bd 0194 016b 0143 011c 00f6 00d0 00ab 0088 0064 0042 0021 0000 ffe0 ffc1 ffa3 ff85 ff69 ff4d ff32 ff17 fefe fee5 fecd feb6 fea0 fe8a fe75 fe61 fe4e fe3b fe2a fe18 fe08 fdf8 fde9 fddb fdce fdc1 fdb5 fda9 fd9e fd94 fd8b fd82 fd7a fd72 fd6b fd64 fd5f fd59 fd55 fd51 fd4d fd4a fd48 fd46 fd44 fd43 fd43 fd43 fd43 fd44 fd46 fd47 fd4a fd4c fd4f fd53 fd57 fd5b fd5f fd64 fd69 fd6f fd75 fd7b fd81 fd88 fd8f fd96 fd9d fda5 fdad fdb5 fdbd fdc5 fdce fdd7 fde0 fde9 fdf2 fdfb fe05 fe0e fe18 fe22 fe2b fe35 fe3f fe49 fe53 fe5d fe67 fe71 fe7b fe85 fe8f fe99 fea3 fead feb7 fec0 feca fed4 fedd fee7 fef0 fefa ff03 ff0c ff15 ff1e ff26 ff2f ff38 ff40 ff48 ff50 ff58 ff60 ff67 ff6f ff76 ff7d ff84 ff8b ff91 ff98 ff9e ffa4 ffaa ffaf ffb5 ffba ffbf ffc4 ffc9 ffcd ffd1 ffd5 ffd9 ffdd ffe1 ffe4 ffe7 ffea ffed ffef fff2 fff4 fff6 fff8 fff9 fffb fffc fffd fffe ffff ffff 0000 0000
list_plot(rounded_coeff)

Verification of the equations

L=160
M=147

for n in range(30) + range(155, 170):
    print "n =", n
    print '    ',
    summands = []
    for j in [0..3]:
        summands.append("h[" + str(j*L+(n*M)%L) + "] * x[" + str(int(n*M / L) - j) + "]")
    print " + ".join(summands)
n = 0 h[0] * x[0] + h[160] * x[-1] + h[320] * x[-2] + h[480] * x[-3] n = 1 h[147] * x[0] + h[307] * x[-1] + h[467] * x[-2] + h[627] * x[-3] n = 2 h[134] * x[1] + h[294] * x[0] + h[454] * x[-1] + h[614] * x[-2] n = 3 h[121] * x[2] + h[281] * x[1] + h[441] * x[0] + h[601] * x[-1] n = 4 h[108] * x[3] + h[268] * x[2] + h[428] * x[1] + h[588] * x[0] n = 5 h[95] * x[4] + h[255] * x[3] + h[415] * x[2] + h[575] * x[1] n = 6 h[82] * x[5] + h[242] * x[4] + h[402] * x[3] + h[562] * x[2] n = 7 h[69] * x[6] + h[229] * x[5] + h[389] * x[4] + h[549] * x[3] n = 8 h[56] * x[7] + h[216] * x[6] + h[376] * x[5] + h[536] * x[4] n = 9 h[43] * x[8] + h[203] * x[7] + h[363] * x[6] + h[523] * x[5] n = 10 h[30] * x[9] + h[190] * x[8] + h[350] * x[7] + h[510] * x[6] n = 11 h[17] * x[10] + h[177] * x[9] + h[337] * x[8] + h[497] * x[7] n = 12 h[4] * x[11] + h[164] * x[10] + h[324] * x[9] + h[484] * x[8] n = 13 h[151] * x[11] + h[311] * x[10] + h[471] * x[9] + h[631] * x[8] n = 14 h[138] * x[12] + h[298] * x[11] + h[458] * x[10] + h[618] * x[9] n = 15 h[125] * x[13] + h[285] * x[12] + h[445] * x[11] + h[605] * x[10] n = 16 h[112] * x[14] + h[272] * x[13] + h[432] * x[12] + h[592] * x[11] n = 17 h[99] * x[15] + h[259] * x[14] + h[419] * x[13] + h[579] * x[12] n = 18 h[86] * x[16] + h[246] * x[15] + h[406] * x[14] + h[566] * x[13] n = 19 h[73] * x[17] + h[233] * x[16] + h[393] * x[15] + h[553] * x[14] n = 20 h[60] * x[18] + h[220] * x[17] + h[380] * x[16] + h[540] * x[15] n = 21 h[47] * x[19] + h[207] * x[18] + h[367] * x[17] + h[527] * x[16] n = 22 h[34] * x[20] + h[194] * x[19] + h[354] * x[18] + h[514] * x[17] n = 23 h[21] * x[21] + h[181] * x[20] + h[341] * x[19] + h[501] * x[18] n = 24 h[8] * x[22] + h[168] * x[21] + h[328] * x[20] + h[488] * x[19] n = 25 h[155] * x[22] + h[315] * x[21] + h[475] * x[20] + h[635] * x[19] n = 26 h[142] * x[23] + h[302] * x[22] + h[462] * x[21] + h[622] * x[20] n = 27 h[129] * x[24] + h[289] * x[23] + h[449] * x[22] + h[609] * x[21] n = 28 h[116] * x[25] + h[276] * x[24] + h[436] * x[23] + h[596] * x[22] n = 29 h[103] * x[26] + h[263] * x[25] + h[423] * x[24] + h[583] * x[23] n = 155 h[65] * x[142] + h[225] * x[141] + h[385] * x[140] + h[545] * x[139] n = 156 h[52] * x[143] + h[212] * x[142] + h[372] * x[141] + h[532] * x[140] n = 157 h[39] * x[144] + h[199] * x[143] + h[359] * x[142] + h[519] * x[141] n = 158 h[26] * x[145] + h[186] * x[144] + h[346] * x[143] + h[506] * x[142] n = 159 h[13] * x[146] + h[173] * x[145] + h[333] * x[144] + h[493] * x[143] n = 160 h[0] * x[147] + h[160] * x[146] + h[320] * x[145] + h[480] * x[144] n = 161 h[147] * x[147] + h[307] * x[146] + h[467] * x[145] + h[627] * x[144] n = 162 h[134] * x[148] + h[294] * x[147] + h[454] * x[146] + h[614] * x[145] n = 163 h[121] * x[149] + h[281] * x[148] + h[441] * x[147] + h[601] * x[146] n = 164 h[108] * x[150] + h[268] * x[149] + h[428] * x[148] + h[588] * x[147] n = 165 h[95] * x[151] + h[255] * x[150] + h[415] * x[149] + h[575] * x[148] n = 166 h[82] * x[152] + h[242] * x[151] + h[402] * x[150] + h[562] * x[149] n = 167 h[69] * x[153] + h[229] * x[152] + h[389] * x[151] + h[549] * x[150] n = 168 h[56] * x[154] + h[216] * x[153] + h[376] * x[152] + h[536] * x[151] n = 169 h[43] * x[155] + h[203] * x[154] + h[363] * x[153] + h[523] * x[152]

Example

print [N(sin(x)*cos(x)*2-0.5, digits=3) for x in srange(0, 1, 1/20)]
[-0.500, -0.400, -0.301, -0.204, -0.111, -0.0206, 0.0646, 0.144, 0.217, 0.283, 0.341, 0.391, 0.432, 0.464, 0.485, 0.497, 0.500, 0.492, 0.474, 0.446]