## Sensor Fusion controller using Fuzzy Logic approach (software implementation)

##### Description and architecture

In this systems, the sensors are read under interrupt, while some low-speed processes are executed under a 1 sec repetitive timer. The interrupt rates vary, from a few tens of ms  (light measures)  to completely arbitrary rates (motion detection) or very long periods (Heart Rate value). Hence I had to defined software components at 2 layers Continue reading “Sensor Fusion controller using Fuzzy Logic approach (software implementation)”

## Sensor Fusion controller using Fuzzy Logic approach (Design choices)

Following the previous article, I now concentrate on design choices and implementation.

The  device was an OHRM gadget, so there was already some sensors available which could be used: Continue reading “Sensor Fusion controller using Fuzzy Logic approach (Design choices)”

## FFT based frequency calculation (implementation)

In a previous article I described the goal, which was to do a simple tool to measure the fundamental frequency of a simple sine wave. In this article, I describe the implementation, which is based on 2 open source libraries:

1.  lib FFTW for Fourier calculation
2. libsndfile for wav file parsing

## Creating multipart email in PHP

Sending a simple and short email in PHP is an easy task. The following lines do just that ( http://php.net/manual/en/function.mail.php )

```// The message
\$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
\$message = wordwrap(\$message, 70, "\r\n");

// Send
mail('caffeinated@example.com', 'My Subject', \$message);
```

However, sending a more involved email, including attachment and several MIME parts require some more code. Fortunately, this is not very complicated. Continue reading “Creating multipart email in PHP”

## Cortex M4 floating point optimisation

Carefully hand-written assembly language routines can bring dramatic savings in the runtime and RAM/ROM budget, for deeply embedded systems. This is especially true on very tiny Wearable devices, where small micro controllers are very often used, running at low frequency, with very limited memory resources.

## FFT based frequency calculation (algorithm)

Determining the frequency of a sinusoidal waveform can be achieved using an FFT based method. If we restrain ourselves to the simple case where the waveform is made of one single sine wave, then the fundamental frequency (f0) is indeed what we call the “waveform frequency”.

If that is the case, a simple FFT would allow isolating the frequency peaks. An histogram would then detect the highest one: the fundamental frequency. Again, this is valid only for this kind of waveforms. We can even tolerate some level of harmonics which are due to distortions.

## Nested C Preprocessor Macros

The C preprocessor and macros are one of the most useful elements for writing portable C/C++ code . It even can  be used to completely different purposes, like text processing.  However, it suffers one major drawback: it does not support nested macros expansion (put differently, macros within macros).

## Some X-Macros Usages

Clever use of X-Macros (https://en.wikipedia.org/wiki/X_Macro ) allow  to decorrelate a set of data from the code which will handle them. For example,  I had recently to implement a parser, which would  analyse an incoming stream, isolate the embedded command and act upon.

So in this typical situation, you generally get the stream matched against some predefined-strings, arranged in an ordered way. Then, you get an ID, parameters and call a specific handler. Nothing fancy.

However, if you want this code to be maintainable (for example, you decide to change the handler name), and upgradable (adding new commands ID), you certainly would like some mechanism which would gather all the changeable bits (the commands, the ID’s, etc ..) from the pure parser structure. This is where X-Macros become handy.