Output RPM from X4M200

Discussion in 'Respiration Sensor' started by Chinhan, Jul 27, 2017.

  1. Chinhan

    Chinhan New Member

    Hi all,

    I am using X4M200, I want to output respiration rate from X4M200 in my python script.
    I used function, peek_message_respiration_sleep(), to read RPM. But it seems no packets return in the queue.
    I think there are some steps i missed, could anyone give me a suggestion. Many thanks

    import sys
    from optparse import OptionParser
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation
    from pymoduleconnector import ModuleConnector
    from time import sleep
    zstart = 0.5
    zend = 5.0
    XTS_ID_APP_RESPIRATION_2 = int("0x064e57ad",16)
    XTS_ID_RESP_STATUS = int("0x2375fe26",16)
    XTS_ID_RESPIRATION_DETECTIONLIST = int("0x610a3b02", 16)
    XTID_SM_RUN = int("0x01",16)
    XTID_SM_MANUAL = int("0x12",16)
    XTID_SM_STOP = int("0x13",16)
    FPS = 10
    #Reset module
    mc = ModuleConnector("COM4")
    x4m200 = mc.get_x4m200()
    #Assume an X4M300/X4M200 module and try to enter XEP mode
    mc = ModuleConnector("COM4")
    x4m200 = mc.get_x4m200()
    #Stop running application and set module in manual mode.
        x4m200.set_sensor_mode(0x13, 0) #Make sure no profile is running
    except RuntimeError:
        #Profile not running, OK
    #Load x4m200 respiration detection profile
        x4m200.set_sensor_mode(0x1,0)#RUN mode
    except RuntimeError:
        #Sensor already stopped, OK
    x4m200.set_output_control(XTS_ID_RESPIRATION_DETECTIONLIST, 1)
    while x4m200.peek_message_respiration_sleep():
        rdata = x4m200.read_message_respiration_sleep()

    Attached Files:

  2. Aksel Johnsby

    Aksel Johnsby Moderator Staff Member

    Hey Chinchan

    Looked through your code and everything looks fine except one thing:

    Don't use peek_message_respiration_sleep() as a condition in your while loop.
    The module will need between 1 and 2 minutes to initialize.

    I've attached a version of your program that works with some print functions.
    Just let it run for approx 2 min and it should start outputting data.

    Aksel :)

    Attached Files:

  3. Chinhan

    Chinhan New Member

    Hi Aksel

    Thanks for pointing out the problem. It's very useful.
  4. Je_Jordan

    Je_Jordan New Member

    I have X4M03, will this code will work on my device to get the respiration rate. If not, where can I find one.
  5. Bjørn Åge Brandal

    Bjørn Åge Brandal Moderator Staff Member

    Hi Jordan,
    the code posted in this thread is for interfacing the X4M200 sensor from a host computer. The X4M200 is a turn-key respiration sensor that contains the neccessary signal processing code to extract respiration movement, and outputs the respiration data as part of its serial protocol messages.

    The X4M03 however is made as a development kit for customers that want to develop their own signal processing, and therefore contains no signal processing code from Novelda. So the output you get from the X4M03 is raw data or down converted base band data. To get the movement and respiration data from the baseband data you have to develop and implement signal processing algorithms that can extract this data.
  6. Lovexethru

    Lovexethru New Member

    This worked but the RPM value doesn't go above 0 for me. Sensor is on my table about 30 cm away from chest and I waited about 10 min but only get the movement numbers up like:

    Frame: 10572 RPM: 0.0 Distance: 0.480539858341 Movement Slow: 62.3884849548 Movement Fast: 4.55782318115
    Frame: 10589 RPM: 0.0 Distance: 0.474060058594 Movement Slow: 58.5117607117 Movement Fast: 48.6621322632
    Frame: 10606 RPM: 0.0 Distance: 0.486482203007 Movement Slow: 60.8596916199 Movement Fast: 74.0929718018
    Frame: 10623 RPM: 0.0 Distance: 0.466982185841 Movement Slow: 65.2027587891 Movement Fast: 74.2403640747
    Frame: 10640 RPM: 0.0 Distance: 0.463851779699 Movement Slow: 65.9245758057 Movement Fast: 73.7868499756
    BTW: the Python samples for x4m200 aren't working. i.e. the x4m200_respiration_message_example.py contains the API code for the x2m400.
  7. Bjørn Åge Brandal

    Bjørn Åge Brandal Moderator Staff Member

    Hi Lovexethru,
    as you might know the X4M200 sensor require the person to be still to enter Breathing state and measure RPM. In the other staes RPM is reported as 0. This can easily be tested if you plug your X4M200 to a computer running XeThru explorer. Looking at your movement slow and movement fast numbers I see you are moving quite a lot.

    You can modify the python script console print to output state by adding rdata.sensor_state:
    print "Frame: {} State: {} RPM: {} Distance: {} Movement Slow: {} Movement Fast: {}" .format(rdata.frame_counter, rdata.sensor_state, rdata.respiration_rate, rdata.distance, rdata.movement_slow, rdata.movement_fast)
    Sensor_State will be 0 when in BREATHING state. You can see below that as soon as state 0 is entered RPM value is shown
    Frame: 915 State: 2 RPM: 0.0 Distance: 0.861613988876 Movement Slow: 0.103141859174 Movement Fast: 0.0
    Frame: 932 State: 2 RPM: 0.0 Distance: 0.857542157173 Movement Slow: 0.0872738808393 Movement Fast: 0.0
    Frame: 949 State: 2 RPM: 0.0 Distance: 0.85852253437 Movement Slow: 0.0952078700066 Movement Fast: 0.0
    Frame: 966 State: 0 RPM: 16.5465393066 Distance: 0.86384677887 Movement Slow: 0.103141859174 Movement Fast: 0.0
    Frame: 983 State: 0 RPM: 16.9309539795 Distance: 0.864058852196 Movement Slow: 0.103141859174 Movement Fast: 0.0
    Also notice that Movement Fast is 0, and movement slow very low, as I am sitting very still in front of the sensor.
    Lovexethru likes this.
  8. Lovexethru

    Lovexethru New Member

    Thanks for your reply! I see this now. RPM (respirations per minute?) phases only appear slowly (after a while of standing still) and last quite short in my tests when sitting beside it, trying to be quite. My goal is to get pure breathing data as fast as possible and for a longer duration without having to stand still (as much). What's the easiest approach to do this?

    i.e. in this breathing LED example, would the test subject (Øyvind?) also have to stand still for a long time to see the LEDs blinking for a short period or did this use another approach?

    Is that fade effect achieved with that brightness value from:
     RespirationData data = radar.get_respiration_data();
      if (data.valid_data == true)
        // Set brightness of LED if in breathing state
        if (data.state_code == radar._xts_val_resp_state_breathing) {
          //Movement is usually between -1 and 1, so move it to 0 to 1 instead:
          float brightness = data.movement + 1.0;
          brightness += 1.0;
          brightness = brightness/2.0;
          // Set brightness of the blue LED
          setColor(0, 0, 255, brightness);
    Is that Arduino XeThruRadar::get_respiration_data API getting breathing data faster? If so, what would be the equivalent of the Windows Python wrappers?

    it appears there's only sleep profiles available out of the box but my use case isn't for sleep but breathing.
  9. Bjørn Åge Brandal

    Bjørn Åge Brandal Moderator Staff Member

    The way the X4M200 is implemented you need to be still to extract respiration data. And as the integration period for Movement slow is 20 seconds you typically have to be still for >20 seconds before the sensor locks on the respiration movement.

    Øyvinds example use the X2M200 respiration sensor, which also outputs respiration pattern, not only respiration rate. And the respiration pattern (actual movement of the chest) is used to fade the LED. On the X4M200 respiration sensor only Respiration rate is currently supported. But we plan to add respiration pattern in a future firmware upgrade of the sensor.

    The speed of respiration aquisition is determined by the module implementation, not the API.

    The use of the Sleep term here might be a bit misleading. Both X2M200 and X2M400 provide respiration data, not sleep stage data. While the X4M200 module implements two profiles, "Adult Respiration Profile", and "Baby Respiration" Profile, the X2M200's two profiles are called "Respiration Profile" and "Sleep Profile". The term "Sleep Profile" where used for X2M200 as it is "optimized to give the best possible readings of an adult sleeping in a bed ..." as described in the X2M200 datasheet. So while it is called Sleep Profile, it is still respiration data that is provided.

    Hope this clarifies a bit. The different profiles in X2M200 and X4M200 is further described in their respective datasheets.
  10. leohouzi

    leohouzi New Member

    Hi Bjorn:
    How can I get the RespirationData through x4m200\ModuleConnector-win32_win64-1.2.2\matlab? RespirationData.png
  11. Lovexethru

    Lovexethru New Member

    I seem to get false positives on the x4m200 using. It triggers short presence messages when no one is there. Maybe it detects neighboors across floors just like the x4m300, so I tried to change the sensitivity and detection zone API as the Python docs show, but first: what are the valid values for x4m200 and if calling the API it returns an error as if it's not implemented. I've used x4m200_RPM_output_working.py.

    I added the API calls between
    while True:
  12. Charlie Shao

    Charlie Shao Moderator Staff Member

    HI Lovexethru,
    The detection zone for X4M200 is 0.4m to 5m, you should put the configuration codes before profile running. X4M300_presence_simpleoutput.py shows how to do customize configurations for sensor and run it, it is similar with X4M200.
    You may get more information from X4M200 datasheet or try XeThru Explorer at first.