## 2 Materials and Methods  
### Pressure Mapping Layer  
The pressure mapping layer (PML) was based on a piezoresistive fabric placed on the foam layer below the top cover of the mattress. We designed the PML as a bidimensional array of pressure sensors able to detect the pressure map of the subject sleeping on the mattress. The pressure map describes the topology of pressure exerted by the subject in multiple sensing areas on the mattress. The static information from the pressure map can be used to derive sleep posture (i.e., supine, prone, and lateral on the right or left sides), while the dynamic content of signals can be analyzed to extract the subject's movement and respiratory activity. Movement of the subject, defined as the transition between consecutive sleeping postures, induces the change in outputs of most of the elements of the array. At the same time, chest expansion during breathing causes a small periodic variation in the output of the sensors that are distributed around the subject's chest area. Note that the chest position over the mattress can change according to the sleeping posture of the subject. We built the PML as an array of 13 \(\times\) 15 piezoresistive elements spread over an area of 125 \(\times\) 75 cm. We applied the PML on a single mattress of 190 \(\times\) 90 cm. The PML was centered on the mattress in such a way that the head and foot areas were excluded from the measurement. As shown in Figure 1, the PML is made of three layers. The central layer is a piezoresistive fabric: the CARBOTEX 03-82 fabric produced by SEFAR AG (Heiden, Switzerland). The top and bottom layers are polyethylene terephthalate (PET) fabrics (produced by SEFAR AG) with integrated metallic threads that are woven to obtain conductive stripes (2 cm width). The stripes of the top layer (the row conductors) and the bottom layer (column conductors) are perpendicular. Following our design, in the top layer, the stripes are separated by 3 cm, while in the bottom layer, the separation is 8 cm. The principle behind the PML is inspired by the work of [PERSON] et al. [24]: each intersection between a row and a column is a sensing area (see the insert in Figure 1) where the electrical resistance decreases when the applied pressure increases. We performed a bench static characterization of the pressure sensor by applying known weights to a single active area when the sensor was stable on a flat surface. This basic characterization confirmed the nonlinear characteristic typical of textile-based piezoresistive sensors, in which the electrical resistance decreases nonlinearly depending on the applied pressure [24; 25; 26]. We have not characterized the sensor hysteresis, but it is known that the textile-based piezoresistive sensors are affected by this phenomenon; see, for reference, the works reported in [27; 28; 29]. Note that calibration of the sensors strictly depends on the substrate on which they are applied and should therefore be done when the PMLhas been inserted into the mattress, and this is very difficult in our application context. For this reason, we decided to apply the posture and movement recognition and respiratory activity extraction algorithms directly on the raw data extracted from the PML. We modified the principle described in [24] to reduce the effect of the parasitic electrical resistances and to save the amount of piezoresistive material used. As described in [23], the effect of parasitic resistances is in fact a cross-talk between the sensors that share the same electrodes. To reduce the effect of parasitic electrical resistances in the transverse directions due to the surface conductivity of the piezoresistive layer [23], we sliced the piezoresistive layer in strips parallel to the row direction (width of the strips is about 3.5 cm) and we sewed the strips onto the top layer aligned to the center of the row conductors. The amount of piezoresistive material saved is about the 30%. This solution is not optimal as we eliminated parasitic resistance only in the column direction.