pms67 / HadesFCS

Complete flight control system designed from scratch. Hardware designed with KiCad.
http://philsal.co.uk
BSD 3-Clause "New" or "Revised" License
739 stars 246 forks source link

FIRWinSyncDesign, Filter data Exports Broken for some countries/systems #8

Open LucaBianco opened 3 years ago

LucaBianco commented 3 years ago

Hello, I found that Coefficients, Time Domain and Frequency Domain Data exports are broken for FIRWinSyncDesign.

Problem: In some countries, a comma "," is used instead of the dot "." as a decimal separator, so the exported list of coefficients is unusable:

float coeff[] = {0,0005084f,0,0008706f,0,0000000f,-0,0011129f,-0,0008133f,0,0009761f, [...] -0,0008133f,-0,0011129f,0,0000000f,0,0008706f};

The problem is in frmMain.cs.

Floats are converted to string like in this example: data[2] = "float coeff[] = {" + windowedImpulseResponse[0].ToString("F7") + "f";

float.ToString() Converts a float to string, but when executed on different systems the output can be different, for example:

Suggested Solution: What I did to fix this little inconvenence was to define the culture of the conversion ("en-US", that uses "." as decimal separator): CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");

and then convert all the floats to string specifying the culture to be used, for example: data[2] = "float coeff[] = {" + windowedImpulseResponse[0].ToString("F7", culture) + "f";

By doing this, the resulting export is as expected:

float coeff[] = {0.0005084f,0.0008706f,0.0000000f,-0.0011129f,-0.0008133f,0.0009761f, [...] -0.0008133f,-0.0011129f,0.0000000f,0.0008706f};

P.S.: Thanks for sharing these projects and for the very very clear explanations in the videos. I am not very familiar with git, so I opened this issue instead of contributing directly.