Elementary waveform generator

This commit is contained in:
Christophe Jacquet 2014-03-31 00:24:33 +02:00
parent 49121b72a4
commit 892f865016
4 changed files with 95 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.wav

58
src/generate_waveforms.py Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/python
# This program uses Pydemod, see https://github.com/ChristopheJacquet/Pydemod
import pydemod.app.rds as rds
import pydemod.modulation.am as am
import numpy
import scipy.io.wavfile as wavfile
import io
sample_rate = 228000
outc = io.open("waveforms.c", mode="w", encoding="utf8")
outh = io.open("waveforms.h", mode="w", encoding="utf8")
header = u"""
/* This file was automatically generated by "generate_waveforms.py".
(C) 2014 Christophe Jacquet.
Released under the GNU GPL v3 license.
*/
"""
outc.write(header)
outh.write(header)
def format_number(x):
if abs(x) < 1e-10:
return u"0"
else:
return unicode(x)
def generate_bit_in_context(prev, current, next):
name = u"{}{}{}".format(prev, current, next)
shapedSamples = rds.unmodulated_signal([prev, current, next], sample_rate)
out = am.modulate(shapedSamples, sample_rate, frequency=57000, phase=0)
out = out[336:336+192]
iout = (out * 20000./max(abs(out)) ).astype(numpy.dtype('>i2'))
wavfile.write(u"{}.wav".format(name), sample_rate, iout)
outc.write(u"float symbol_{name}[] = {{{values}}};\n\n".format(
name = name,
values = u", ".join(map(format_number, out))))
outh.write(u"extern float symbol_{name}[];\n".format(name=name))
for prev in [0, 1]:
for current in [0, 1]:
for next in [0, 1]:
generate_bit_in_context(prev, current, next)
outc.close()
outh.close()

22
src/waveforms.c Normal file
View File

@ -0,0 +1,22 @@
/* This file was automatically generated by "generate_waveforms.py".
(C) 2014 Christophe Jacquet.
Released under the GNU GPL v3 license.
*/
float symbol_000[] = {0, -0.0688924767714, 0, 0.160476027168, 0, -0.251405034722, 0, 0.341307939122, 0, -0.429816470713, 0, 0.516566856073, 0, -0.601201031227, 0, 0.683367863703, 0, -0.76272438406, 0, 0.838937026839, 0, -0.911682880148, 0, 0.980650942258, 0, -1.04554338271, 0, 1.10607680447, 0, -1.16198350282, 0, 1.2130127156, 0, -1.25893185853, 0, 1.29952773851, 0, -1.33460773675, 0, 1.36400095304, 0, -1.38755930158, 0, 1.40515854821, 0, -1.41669927855, 0, 1.422107786, 0, -1.4209101738, 0, 1.41310777364, 0, -1.39917719852, 0, 1.37919502884, 0, -1.35326381164, 0, 1.3215112686, 0, -1.28408941638, 0, 1.24117360847, 0, -1.19296150733, 0, 1.13967199528, 0, -1.08154403238, 0, 1.01883546886, 0, -0.951821819184, 0, 0.880795004393, 0, -0.806062068456, 0, 0.72794387397, 0, -0.646773781723, 0, 0.562896318018, 0, -0.476665833037, 0, 0.388445152869, 0, -0.298604227296, 0, 0.207518774887, 0, -0.115568926523, 0, 0.0231378680857, 0, 0.0693895172325, 0, -0.161628006774, 0, 0.253193396276, 0, -0.343703857662, 0, 0.432781296583, 0, -0.520052709381, 0, 0.605151538892, 0, -0.687719028179, 0, 0.767405570842, 0, -0.843872056124, 0, 0.916791206429, 0, -0.985848904339, 0, 1.05074550545, 0, -1.11119713309, 0, 1.16693694952, 0, -1.21771639861, 0, 1.26330641337, 0, -1.30349858178, 0, 1.33810626336, 0, -1.3669656487, 0, 1.38993675357, 0, -1.40690433891, 0, 1.41777874782, 0, -1.42249665043, 0, 1.42017364013, 0, -1.41169144692, 0, 1.39711061857, 0, -1.37651782114, 0, 1.35002499518, 0, -1.31776842624, 0, 1.2799077409, 0, -1.23662483888, 0, 1.18812277181, 0, -1.13462457836, 0, 1.07637208496, 0, -1.01362468058, 0, 0.946658073004, 0, -0.875763033693, 0, 0.80124413653, 0, -0.723418495748, 0, 0.642614506708, 0, -0.559170592547, 0, 0.473433958761, 0, -0.385759356914, 0, 0.296507857888, 0, -0.206045634362, 0, 0.114742751598, 0, -0.0229719650907};
float symbol_001[] = {0, -0.0688924767714, 0, 0.160476027168, 0, -0.251405034722, 0, 0.341307939122, 0, -0.429816470713, 0, 0.516566856073, 0, -0.601201031227, 0, 0.683367863703, 0, -0.76272438406, 0, 0.838937026839, 0, -0.911682880148, 0, 0.980650942258, 0, -1.04554338271, 0, 1.10607680447, 0, -1.16198350282, 0, 1.2130127156, 0, -1.25893185853, 0, 1.29952773851, 0, -1.33460773675, 0, 1.36400095304, 0, -1.38755930158, 0, 1.40515854821, 0, -1.41669927855, 0, 1.422107786, 0, -1.46167439235, 0, 1.45404064154, 0, -1.43956092877, 0, 1.41828935759, 0, -1.39031738878, 0, 1.35577372442, 0, -1.31482394436, 0, 1.26766989019, 0, -1.21454879344, 0, 1.15573214697, 0, -1.09152432041, 0, 1.0222609228, 0, -0.948306917838, 0, 0.870054499449, 0, -0.787920737727, 0, 0.702345007717, 0, -0.613786215801, 0, 0.522719840769, 0, -0.429634808861, 0, 0.335030224189, 0, -0.239411977903, 0, 0.143289261321, 0, -0.0471710098037, 0, -0.0484376943631, 0, 0.143039230713, 0, -0.236147030654, 0, 0.327289117905, 0, -0.416011568082, 0, 0.501881856137, 0, -0.584492060718, 0, 0.663461895111, 0, -0.738441535427, 0, 0.809114217969, 0, -0.875198579363, 0, 0.936450714972, 0, -0.992665933357, 0, 1.043680187, 0, -1.08937116266, 0, 1.12965901699, 0, -1.16450674727, 0, 1.19392018979, 0, -1.21794764224, 0, 1.23667911027, 0, -1.2502451818, 0, 1.2588155368, 0, -1.26259710362, 0, 1.26183187709, 0, -1.29721507979, 0, 1.28787743776, 0, -1.27424291301, 0, 1.25667951096, 0, -1.23558399413, 0, 1.21137792785, 0, -1.18450348684, 0, 1.15541906265, 0, -1.1245947143, 0, 1.09250750617, 0, -1.05963677844, 0, 1.02645939621, 0, -0.993445023832, 0, 0.96105147071, 0, -0.929720154741, 0, 0.899871727579, 0, -0.871901905518, 0, 0.846177546948, 0, -0.823033015423, 0, 0.80276686443, 0, -0.785638876839, 0, 0.771867488518, 0, -0.761627621767, 0, 0.755048950196, 0, -0.752214612349};
float symbol_010[] = {0, 0.753160386924, 0, -0.757874337815, 0, 0.766296932528, 0, -0.77832163279, 0, 0.793795951449, 0, -0.812522965109, 0, 0.834263267412, 0, -0.858737343471, 0, 0.885628341798, 0, -0.914585216098, 0, 0.945226205683, 0, -0.977142619896, 0, 1.009902889, 0, -1.04305684135, 0, 1.07614016456, 0, -1.1086790066, 0, 1.14019467145, 0, -1.17020836322, 0, 1.19824593214, 0, -1.22384257617, 0, 1.24654745231, 0, -1.26592815291, 0, 1.28157500391, 0, -1.29310514353, 0, 1.25982881871, 0, -1.26276641138, 0, 1.26129058812, 0, -1.2551427399, 0, 1.24409811191, 0, -1.227968148, 0, 1.20660250556, 0, -1.17989072409, 0, 1.14776353433, 0, -1.11019379855, 0, 1.06719707633, 0, -1.01883181387, 0, 0.965199158848, 0, -0.906442406057, 0, 0.842746082883, 0, -0.77433468688, 0, 0.701471090849, 0, -0.624454633785, 0, 0.543618918671, 0, -0.459329340547, 0, 0.371980370315, 0, -0.281992621583, 0, 0.189809729273, 0, -0.0958950698886, 0, 0.000728354101177, 0, 0.0951978771733, 0, -0.191381821916, 0, 0.287316020235, 0, -0.382490961038, 0, 0.476398662257, 0, -0.568536195794, 0, 0.658409129628, 0, -0.74553486106, 0, 0.829445816782, 0, -0.909692497372, 0, 0.985846345847, 0, -1.05750242201, 0, 1.12428186692, 0, -1.1858341434, 0, 1.24183904185, 0, -1.29200844205, 0, 1.33608782467, 0, -1.37385752815, 0, 1.40513374882, 0, -1.42976928457, 0, 1.44765402418, 0, -1.4587151862, 0, 1.42249665043, 0, -1.42017364013, 0, 1.41169144692, 0, -1.39711061857, 0, 1.37651782114, 0, -1.35002499518, 0, 1.31776842624, 0, -1.2799077409, 0, 1.23662483888, 0, -1.18812277181, 0, 1.13462457836, 0, -1.07637208496, 0, 1.01362468058, 0, -0.946658073004, 0, 0.875763033693, 0, -0.80124413653, 0, 0.723418495748, 0, -0.642614506708, 0, 0.559170592547, 0, -0.473433958761, 0, 0.385759356914, 0, -0.296507857888, 0, 0.206045634362, 0, -0.114742751598, 0, 0.0229719650907};
float symbol_011[] = {0, 0.753160386924, 0, -0.757874337815, 0, 0.766296932528, 0, -0.77832163279, 0, 0.793795951449, 0, -0.812522965109, 0, 0.834263267412, 0, -0.858737343471, 0, 0.885628341798, 0, -0.914585216098, 0, 0.945226205683, 0, -0.977142619896, 0, 1.009902889, 0, -1.04305684135, 0, 1.07614016456, 0, -1.1086790066, 0, 1.14019467145, 0, -1.17020836322, 0, 1.19824593214, 0, -1.22384257617, 0, 1.24654745231, 0, -1.26592815291, 0, 1.28157500391, 0, -1.29310514353, 0, 1.30059303726, 0, -1.30369927929, 0, 1.30167431836, 0, -1.29423706865, 0, 1.28115168905, 0, -1.26223060382, 0, 1.23733703354, 0, -1.2063870058, 0, 1.16935082044, 0, -1.12625395025, 0, 1.07717736436, 0, -1.02225726781, 0, 0.961684257503, 0, -0.895701901113, 0, 0.824604752155, 0, -0.748735820626, 0, 0.668483524927, 0, -0.584278156535, 0, 0.496587894496, 0, -0.405914411867, 0, 0.312788120923, 0, -0.217763108016, 0, 0.121411812554, 0, -0.0243195074398, 0, -0.0729213593797, 0, 0.169716901053, 0, -0.265477543545, 0, 0.359623730655, 0, -0.451591520592, 0, 0.540838013594, 0, -0.626846552013, 0, 0.709131636876, 0, -0.787243508186, 0, 0.860772340021, 0, -0.929352005915, 0, 0.992663374866, 0, -1.05043710356, 0, 1.1024558965, 0, -1.14855621088, 0, 1.18862939052, 0, -1.22262221847, 0, 1.25053688514, 0, -1.27243037506, 0, 1.28841328192, 0, -1.2986480678, 0, 1.30334678889, 0, -1.30276831547, 0, 1.29721507979, 0, -1.28787743776, 0, 1.27424291301, 0, -1.25667951096, 0, 1.23558399413, 0, -1.21137792785, 0, 1.18450348684, 0, -1.15541906265, 0, 1.1245947143, 0, -1.09250750617, 0, 1.05963677844, 0, -1.02645939621, 0, 0.993445023832, 0, -0.96105147071, 0, 0.929720154741, 0, -0.899871727579, 0, 0.871901905518, 0, -0.846177546948, 0, 0.823033015423, 0, -0.80276686443, 0, 0.785638876839, 0, -0.771867488518, 0, 0.761627621767, 0, -0.755048950196, 0, 0.752214612349};
float symbol_100[] = {0, -0.0688924767714, 0, 0.160476027168, 0, -0.251405034722, 0, 0.341307939122, 0, -0.429816470713, 0, 0.516566856073, 0, -0.601201031227, 0, 0.683367863703, 0, -0.76272438406, 0, 0.838937026839, 0, -0.911682880148, 0, 0.980650942258, 0, -1.04554338271, 0, 1.10607680447, 0, -1.16198350282, 0, 1.2130127156, 0, -1.25893185853, 0, 1.29952773851, 0, -1.33460773675, 0, 1.36400095304, 0, -1.38755930158, 0, 1.40515854821, 0, -1.41669927855, 0, 1.422107786, 0, -1.4209101738, 0, 1.41310777364, 0, -1.39917719852, 0, 1.37919502884, 0, -1.35326381164, 0, 1.3215112686, 0, -1.28408941638, 0, 1.24117360847, 0, -1.19296150733, 0, 1.13967199528, 0, -1.08154403238, 0, 1.01883546886, 0, -0.951821819184, 0, 0.880795004393, 0, -0.806062068456, 0, 0.72794387397, 0, -0.646773781723, 0, 0.562896318018, 0, -0.476665833037, 0, 0.388445152869, 0, -0.298604227296, 0, 0.207518774887, 0, -0.115568926523, 0, 0.0231378680857, 0, 0.0693895172325, 0, -0.161628006774, 0, 0.253193396276, 0, -0.343703857662, 0, 0.432781296583, 0, -0.520052709381, 0, 0.605151538892, 0, -0.687719028179, 0, 0.767405570842, 0, -0.843872056124, 0, 0.916791206429, 0, -0.985848904339, 0, 1.05074550545, 0, -1.11119713309, 0, 1.16693694952, 0, -1.21771639861, 0, 1.26330641337, 0, -1.30349858178, 0, 1.33810626336, 0, -1.3669656487, 0, 1.38993675357, 0, -1.40690433891, 0, 1.41777874782, 0, -1.42249665043, 0, 1.42017364013, 0, -1.41169144692, 0, 1.39711061857, 0, -1.37651782114, 0, 1.35002499518, 0, -1.31776842624, 0, 1.2799077409, 0, -1.23662483888, 0, 1.18812277181, 0, -1.13462457836, 0, 1.07637208496, 0, -1.01362468058, 0, 0.946658073004, 0, -0.875763033693, 0, 0.80124413653, 0, -0.723418495748, 0, 0.642614506708, 0, -0.559170592547, 0, 0.473433958761, 0, -0.385759356914, 0, 0.296507857888, 0, -0.206045634362, 0, 0.114742751598, 0, -0.0229719650907};
float symbol_101[] = {0, -0.0688924767714, 0, 0.160476027168, 0, -0.251405034722, 0, 0.341307939122, 0, -0.429816470713, 0, 0.516566856073, 0, -0.601201031227, 0, 0.683367863703, 0, -0.76272438406, 0, 0.838937026839, 0, -0.911682880148, 0, 0.980650942258, 0, -1.04554338271, 0, 1.10607680447, 0, -1.16198350282, 0, 1.2130127156, 0, -1.25893185853, 0, 1.29952773851, 0, -1.33460773675, 0, 1.36400095304, 0, -1.38755930158, 0, 1.40515854821, 0, -1.41669927855, 0, 1.422107786, 0, -1.46167439235, 0, 1.45404064154, 0, -1.43956092877, 0, 1.41828935759, 0, -1.39031738878, 0, 1.35577372442, 0, -1.31482394436, 0, 1.26766989019, 0, -1.21454879344, 0, 1.15573214697, 0, -1.09152432041, 0, 1.0222609228, 0, -0.948306917838, 0, 0.870054499449, 0, -0.787920737727, 0, 0.702345007717, 0, -0.613786215801, 0, 0.522719840769, 0, -0.429634808861, 0, 0.335030224189, 0, -0.239411977903, 0, 0.143289261321, 0, -0.0471710098037, 0, -0.0484376943631, 0, 0.143039230713, 0, -0.236147030654, 0, 0.327289117905, 0, -0.416011568082, 0, 0.501881856137, 0, -0.584492060718, 0, 0.663461895111, 0, -0.738441535427, 0, 0.809114217969, 0, -0.875198579363, 0, 0.936450714972, 0, -0.992665933357, 0, 1.043680187, 0, -1.08937116266, 0, 1.12965901699, 0, -1.16450674727, 0, 1.19392018979, 0, -1.21794764224, 0, 1.23667911027, 0, -1.2502451818, 0, 1.2588155368, 0, -1.26259710362, 0, 1.26183187709, 0, -1.29721507979, 0, 1.28787743776, 0, -1.27424291301, 0, 1.25667951096, 0, -1.23558399413, 0, 1.21137792785, 0, -1.18450348684, 0, 1.15541906265, 0, -1.1245947143, 0, 1.09250750617, 0, -1.05963677844, 0, 1.02645939621, 0, -0.993445023832, 0, 0.96105147071, 0, -0.929720154741, 0, 0.899871727579, 0, -0.871901905518, 0, 0.846177546948, 0, -0.823033015423, 0, 0.80276686443, 0, -0.785638876839, 0, 0.771867488518, 0, -0.761627621767, 0, 0.755048950196, 0, -0.752214612349};
float symbol_110[] = {0, 0.753160386924, 0, -0.757874337815, 0, 0.766296932528, 0, -0.77832163279, 0, 0.793795951449, 0, -0.812522965109, 0, 0.834263267412, 0, -0.858737343471, 0, 0.885628341798, 0, -0.914585216098, 0, 0.945226205683, 0, -0.977142619896, 0, 1.009902889, 0, -1.04305684135, 0, 1.07614016456, 0, -1.1086790066, 0, 1.14019467145, 0, -1.17020836322, 0, 1.19824593214, 0, -1.22384257617, 0, 1.24654745231, 0, -1.26592815291, 0, 1.28157500391, 0, -1.29310514353, 0, 1.25982881871, 0, -1.26276641138, 0, 1.26129058812, 0, -1.2551427399, 0, 1.24409811191, 0, -1.227968148, 0, 1.20660250556, 0, -1.17989072409, 0, 1.14776353433, 0, -1.11019379855, 0, 1.06719707633, 0, -1.01883181387, 0, 0.965199158848, 0, -0.906442406057, 0, 0.842746082883, 0, -0.77433468688, 0, 0.701471090849, 0, -0.624454633785, 0, 0.543618918671, 0, -0.459329340547, 0, 0.371980370315, 0, -0.281992621583, 0, 0.189809729273, 0, -0.0958950698886, 0, 0.000728354101177, 0, 0.0951978771733, 0, -0.191381821916, 0, 0.287316020235, 0, -0.382490961038, 0, 0.476398662257, 0, -0.568536195794, 0, 0.658409129628, 0, -0.74553486106, 0, 0.829445816782, 0, -0.909692497372, 0, 0.985846345847, 0, -1.05750242201, 0, 1.12428186692, 0, -1.1858341434, 0, 1.24183904185, 0, -1.29200844205, 0, 1.33608782467, 0, -1.37385752815, 0, 1.40513374882, 0, -1.42976928457, 0, 1.44765402418, 0, -1.4587151862, 0, 1.42249665043, 0, -1.42017364013, 0, 1.41169144692, 0, -1.39711061857, 0, 1.37651782114, 0, -1.35002499518, 0, 1.31776842624, 0, -1.2799077409, 0, 1.23662483888, 0, -1.18812277181, 0, 1.13462457836, 0, -1.07637208496, 0, 1.01362468058, 0, -0.946658073004, 0, 0.875763033693, 0, -0.80124413653, 0, 0.723418495748, 0, -0.642614506708, 0, 0.559170592547, 0, -0.473433958761, 0, 0.385759356914, 0, -0.296507857888, 0, 0.206045634362, 0, -0.114742751598, 0, 0.0229719650907};
float symbol_111[] = {0, 0.753160386924, 0, -0.757874337815, 0, 0.766296932528, 0, -0.77832163279, 0, 0.793795951449, 0, -0.812522965109, 0, 0.834263267412, 0, -0.858737343471, 0, 0.885628341798, 0, -0.914585216098, 0, 0.945226205683, 0, -0.977142619896, 0, 1.009902889, 0, -1.04305684135, 0, 1.07614016456, 0, -1.1086790066, 0, 1.14019467145, 0, -1.17020836322, 0, 1.19824593214, 0, -1.22384257617, 0, 1.24654745231, 0, -1.26592815291, 0, 1.28157500391, 0, -1.29310514353, 0, 1.30059303726, 0, -1.30369927929, 0, 1.30167431836, 0, -1.29423706865, 0, 1.28115168905, 0, -1.26223060382, 0, 1.23733703354, 0, -1.2063870058, 0, 1.16935082044, 0, -1.12625395025, 0, 1.07717736436, 0, -1.02225726781, 0, 0.961684257503, 0, -0.895701901113, 0, 0.824604752155, 0, -0.748735820626, 0, 0.668483524927, 0, -0.584278156535, 0, 0.496587894496, 0, -0.405914411867, 0, 0.312788120923, 0, -0.217763108016, 0, 0.121411812554, 0, -0.0243195074398, 0, -0.0729213593797, 0, 0.169716901053, 0, -0.265477543545, 0, 0.359623730655, 0, -0.451591520592, 0, 0.540838013594, 0, -0.626846552013, 0, 0.709131636876, 0, -0.787243508186, 0, 0.860772340021, 0, -0.929352005915, 0, 0.992663374866, 0, -1.05043710356, 0, 1.1024558965, 0, -1.14855621088, 0, 1.18862939052, 0, -1.22262221847, 0, 1.25053688514, 0, -1.27243037506, 0, 1.28841328192, 0, -1.2986480678, 0, 1.30334678889, 0, -1.30276831547, 0, 1.29721507979, 0, -1.28787743776, 0, 1.27424291301, 0, -1.25667951096, 0, 1.23558399413, 0, -1.21137792785, 0, 1.18450348684, 0, -1.15541906265, 0, 1.1245947143, 0, -1.09250750617, 0, 1.05963677844, 0, -1.02645939621, 0, 0.993445023832, 0, -0.96105147071, 0, 0.929720154741, 0, -0.899871727579, 0, 0.871901905518, 0, -0.846177546948, 0, 0.823033015423, 0, -0.80276686443, 0, 0.785638876839, 0, -0.771867488518, 0, 0.761627621767, 0, -0.755048950196, 0, 0.752214612349};

14
src/waveforms.h Normal file
View File

@ -0,0 +1,14 @@
/* This file was automatically generated by "generate_waveforms.py".
(C) 2014 Christophe Jacquet.
Released under the GNU GPL v3 license.
*/
extern float symbol_000[];
extern float symbol_001[];
extern float symbol_010[];
extern float symbol_011[];
extern float symbol_100[];
extern float symbol_101[];
extern float symbol_110[];
extern float symbol_111[];