kopia lustrzana https://github.com/xaelsouth/rtl-wmbus
dc removal offset
rodzic
f2a89a0a1b
commit
6354b039ba
59
rtl_wmbus.c
59
rtl_wmbus.c
|
@ -63,6 +63,14 @@
|
|||
#define RUN_LENGTH_ALGORITHM_ENABLED 1
|
||||
#endif
|
||||
|
||||
#ifndef T1_C1_DC_OFFSET_ALPHA
|
||||
#define T1_C1_DC_OFFSET_ALPHA 0.992f
|
||||
#endif
|
||||
|
||||
#ifndef S1_DC_OFFSET_ALPHA
|
||||
#define S1_DC_OFFSET_ALPHA 0.999f
|
||||
#endif
|
||||
|
||||
static const uint32_t ACCESS_CODE_T1_C1 = 0b0101010101010000111101u;
|
||||
static const uint32_t ACCESS_CODE_T1_C1_BITMASK = 0x3FFFFFu;
|
||||
static const unsigned ACCESS_CODE_T1_C1_ERRORS = 1u; // 0 if no errors allowed
|
||||
|
@ -123,6 +131,13 @@ static const uint8_t deglitch_filter_s1[16] = {
|
|||
};
|
||||
|
||||
|
||||
//static FILE *demod_out = NULL;
|
||||
//static FILE *demod_out2 = NULL;
|
||||
//static FILE *clock_out = NULL;
|
||||
//static FILE *bits_out = NULL;
|
||||
//static FILE *rawbits_out = NULL;
|
||||
|
||||
|
||||
static inline float moving_average_t1_c1(float sample, size_t i_or_q)
|
||||
{
|
||||
#define COEFFS 8
|
||||
|
@ -455,6 +470,26 @@ static float rssi_filter_s1(float sample)
|
|||
return old_sample;
|
||||
}
|
||||
|
||||
static float s1_remove_dc_offset_demod(float x, float alpha)
|
||||
{
|
||||
static float x_old, y_old;
|
||||
|
||||
y_old = x - x_old + alpha*y_old;
|
||||
x_old = x;
|
||||
|
||||
return y_old;
|
||||
}
|
||||
|
||||
static float t1_c1_remove_dc_offset_demod(float x, float alpha)
|
||||
{
|
||||
static float x_old, y_old;
|
||||
|
||||
y_old = x - x_old + alpha*y_old;
|
||||
x_old = x;
|
||||
|
||||
return y_old;
|
||||
}
|
||||
|
||||
static inline float polar_discriminator_t1_c1(float i, float q)
|
||||
{
|
||||
static float complex s_last;
|
||||
|
@ -976,9 +1011,10 @@ void t1_c1_signal_chain(float i_t1_c1, float q_t1_c1,
|
|||
//fwrite(&demodulated_signal, sizeof(demodulated_signal), 1, demod_out);
|
||||
|
||||
// Post-filtering to prevent bit errors because of signal jitter.
|
||||
const float delta_phi_t1_c1 = lp_fir_butter_800kHz_100kHz_160kHz(_delta_phi_t1_c1);
|
||||
//const float delta_phi_t1_c1 = equalizer_t1_c1(_delta_phi_t1_c1, _delta_phi_t1_c1 >= 0.f ? 1.f : -1.f);
|
||||
//int16_t demodulated_signal = (INT16_MAX-1)*delta_phi;
|
||||
float delta_phi_t1_c1 = lp_fir_butter_800kHz_100kHz_160kHz(_delta_phi_t1_c1);
|
||||
//float delta_phi_t1_c1 = equalizer_t1_c1(_delta_phi_t1_c1, _delta_phi_t1_c1 >= 0.f ? 1.f : -1.f);
|
||||
delta_phi_t1_c1 = t1_c1_remove_dc_offset_demod(delta_phi_t1_c1, T1_C1_DC_OFFSET_ALPHA);
|
||||
//int16_t demodulated_signal = (INT16_MAX-1)*delta_phi_t1_c1;
|
||||
//fwrite(&demodulated_signal, sizeof(demodulated_signal), 1, demod_out2);
|
||||
|
||||
// Get the bit!
|
||||
|
@ -1067,9 +1103,10 @@ void s1_signal_chain(float i_s1, float q_s1,
|
|||
//fwrite(&demodulated_signal, sizeof(demodulated_signal), 1, demod_out);
|
||||
|
||||
// Post-filtering to prevent bit errors because of signal jitter.
|
||||
const float delta_phi_s1 = lp_fir_butter_800kHz_32kHz_36kHz(_delta_phi_s1);
|
||||
//const float delta_phi_s1 = equalizer_s1(_delta_phi_s1, _delta_phi_s1 >= 0.f ? 1.f : -1.f);
|
||||
//int16_t demodulated_signal = (INT16_MAX-1)*delta_phi;
|
||||
float delta_phi_s1 = lp_fir_butter_800kHz_32kHz_36kHz(_delta_phi_s1);
|
||||
//float delta_phi_s1 = equalizer_s1(_delta_phi_s1, _delta_phi_s1 >= 0.f ? 1.f : -1.f);
|
||||
delta_phi_s1 = s1_remove_dc_offset_demod(delta_phi_s1, S1_DC_OFFSET_ALPHA);
|
||||
//int16_t demodulated_signal = (INT16_MAX-1)*delta_phi_s1;
|
||||
//fwrite(&demodulated_signal, sizeof(demodulated_signal), 1, demod_out2);
|
||||
|
||||
// Get the bit!
|
||||
|
@ -1187,11 +1224,11 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//FILE *demod_out = fopen("demod.bin", "wb");
|
||||
//FILE *demod_out2 = fopen("demod.bin", "wb");
|
||||
//FILE *clock_out = fopen("clock.bin", "wb");
|
||||
//FILE *bits_out = fopen("bits.bin", "wb");
|
||||
//FILE *rawbits_out = fopen("rawbits.bin", "wb");
|
||||
//demod_out = fopen("demod.bin", "wb");
|
||||
//demod_out2 = fopen("demod2.bin", "wb");
|
||||
//clock_out = fopen("clock.bin", "wb");
|
||||
//bits_out = fopen("bits.bin", "wb");
|
||||
//rawbits_out = fopen("rawbits.bin", "wb");
|
||||
|
||||
setup_lookup_tables_for_frequency_translation(fs_kHz);
|
||||
|
||||
|
|
|
@ -0,0 +1,304 @@
|
|||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%rw/build/rtl_wmbus"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='gcc -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='gcc %xup -g -o "%o" %f %libs'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make all"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make rebuild"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='vsdebugio -prog "%o"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='"%o"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<Rules Name="Compile">
|
||||
<Rule
|
||||
InputExts="*.ada"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gnat -g -c -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.adb"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gnat -g -c -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.f"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gfortran -c -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.f90"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gfortran -c -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.d"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gdc -c -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
</Rules>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="Executable"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%rw/build/rtl_wmbus"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='gcc -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='gcc %xup -o "%o" %f %libs'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make all"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make rebuild"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='vsdebugio -prog "%o"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='"%o"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<Rules Name="Compile">
|
||||
<Rule
|
||||
InputExts="*.ada"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gnat -O -c -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.adb"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gnat -O -c -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.f"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gfortran -O -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.f90"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gfortran -O -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
<Rule
|
||||
InputExts="*.d"
|
||||
OutputExts="*.o"
|
||||
LinkObject="1">
|
||||
<Exec CmdLine='gdc -c -g -o "%bd%n.o" "%f"'/>
|
||||
</Rule>
|
||||
</Rules>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="Executable"/>
|
||||
</List>
|
||||
</Config>
|
||||
<CustomFolders>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.scala;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d;*.m;*.mm;*.go;*.groovy;*.gsh"
|
||||
GUID="{0C19CD2F-C5EE-49D5-BC64-CA378B318201}"></Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.h++;*.inc;*.sh;*.cpy;*.if"
|
||||
GUID="{BBDE0769-47E0-4386-9137-10175CE5EFBE}"></Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"
|
||||
GUID="{1E1A1243-F929-4CBE-9691-37BD362B0055}"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"
|
||||
GUID="{46CCCA3F-96F2-4777-B582-7AA09975694A}"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters=""
|
||||
GUID="{3483AD1D-7C36-49D7-B257-47CBFC0918FE}"></Folder>
|
||||
</CustomFolders>
|
||||
<Files AutoFolders="DirectoryView">
|
||||
<Folder Name="build">
|
||||
<F N="build/version.h"/>
|
||||
</Folder>
|
||||
<Folder Name="include">
|
||||
<Folder Name="fixedptc">
|
||||
<F N="include/fixedptc/fixedptc.h"/>
|
||||
<F N="include/fixedptc/Makefile"/>
|
||||
<F N="include/fixedptc/test.c"/>
|
||||
<F N="include/fixedptc/verify.c"/>
|
||||
</Folder>
|
||||
</Folder>
|
||||
<F N="atan2.h"/>
|
||||
<F N="fir.h"/>
|
||||
<F N="iir.h"/>
|
||||
<F N="Makefile"/>
|
||||
<F N="moving_average_filter.h"/>
|
||||
<F N="net_support.h"/>
|
||||
<F N="ppf.h"/>
|
||||
<F N="rtl_wmbus.c"/>
|
||||
<F N="s1_packet_decoder.h"/>
|
||||
<F N="t1_c1_packet_decoder.h"/>
|
||||
</Files>
|
||||
<List Name="RTE">
|
||||
</List>
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE Workspace SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpw.dtd">
|
||||
<Workspace Version="10.0" VendorName="SlickEdit">
|
||||
<Projects>
|
||||
<Project File="rtl_wmbus.vpj"/>
|
||||
</Projects>
|
||||
</Workspace>
|
Ładowanie…
Reference in New Issue