Blog Archives

HRV – Calculating Frequency Domain values

Posted on by

I’ve gotten python routines to calculate time domain values for Heart Rate Variability (HRV).  Now I’m working on doing spectrum analysis with Frequency domain.

Frequency Domain step 1.  Interpolating beats into fixed time segments.

 

FFT (Fast Fourier Transform) and Welch are the two most common methods for getting a frequency power spectrum.  Both of those require data with evenly spaced time points.  Because heart beats are not evenly spaced they need to be interpolated.

Some time back I had captured links to a number of articles that have example code for frequency power spectrum hrv calculations.  Looking at the different ways that they use for handling the interpolation.  One of the articles shows how to compare a graph of the interpolated values with your original values so I have been doing that.

Going slowly and just doing one step at a time but am at this point just comparing interpolation methods before moving on to actually creating power spectrums.

I download my heart beat intervals into an array called “beattimes”.    “beattimes” is an array of beats, in milliseconds, from my database for one session.  I will leave it to you to figure out how to fill the beattimes array whether from database or importing beat data from a file.

Let’s start by graphing the data.

 

import numpy as np

import matplotlib.pyplot as plt

#beattimes is magically filled by a routine that gets the intervals out of the database

t = np.cumsum(beattimes) / 1000.0
t -= t[0]  #alternately t = t[1:]

#that created an array t of timestamps for each of your heartbeat intervals …  milliseconds divided by 1000 to be seconds

plt.title(“Original Inter Beat Intervals”)
plt.plot(t, beattimes, label=”Original”, color=’blue’)
plt.legend()
plt.show()

If you haven’t done much with graphing thought you might like a very simple graph routine.  You do have to fill the “beattimes” arrray with your own code but that will graph any of your sessions of heart rate data.

So now the interpolation.  I’ve looked at three sources of code so far and they all interpolate with somewhat different methods.

First article I looked at.

from scipy.interpolate import splrep, splev

tx = np.arange(t[0], t[-1], 1.0 / 4.0)

tck = splrep(t, beattimes, s=0)
rrix = splev(tx, tck, der=0)

tx is the new timestamps for each of the values.  In this case they are each 1/4 of a second.  (Which greatly increases the number of data points, not quite sure why 1/4 and not 1/2 or even 1 second.)  “rrix” is the new array of interpolated values that match the evenly spaced time stamps.

Second article I looked at did it a little differently.

from scipy.interpolate import interp1d

tx = np.linspace(t[0],t[-1],t[-1])
f = interp1d(t, beattimes, kind=’cubic’)
rrix = f(tx)

He created the evenly spaced timestamp array, tx, a little differently and did the interpolation from a different library in scipy.

Third source was the python hrv module.  They did the tx timestamp array the same as the first method but used numpy for the interpolation instead of scipy.

tx = np.arange(t[0], t[-1], 1.0 / 4.0)
rrix = np.interp(tx, t, beattimes)

So now I have three methods of interpolating my heart beat interval data into evenly spaced values.  How do I compare them?  Graphing is one method. I can see how the interpolated values look compared to the original.

plt.title(“Original and Interpolated Signal”)
plt.plot(t, beattimes, label=”Original”, color=’blue’)
plt.plot(tx, rrix, label=”Interpolated”, color=’red’)
plt.legend()
plt.show()

I’ve been playing with comparing graphs of all three methods to try to see which one has the best fit to the original data.  I find for visualizing it helps to change the order the two .plot lines because having the red on top shows you some differences but having the blue on top shows other differences.
Anyway if you can make code that fills the beattimes array with values from one of your sessions the rest of this code should work as written.

Heart Rate Monitoring

Posted on by

Feel a need to catch up on writing about what I’ve been doing with Heart Rate monitoring.

Started with an Arduino board and a simple ear clip heart rate monitor and gsr sensor from Seedstudio (Grove). Made a simple biofeedback program out of it.  Set up some Python programs to read the data and save to a MySQL database. Worked with that for a while though the limitation of being tied by cables to the machine was a restriction that limited the amount of times that I would actually sit down and take measurements. Also an ear clip monitor is not the most accurate way to measure heart beats, though it was doing the job.

Last winter decided to move up to a bluetooth chest strap to measure heart rate. Decided on a Polar H10 chest strap. Polar is well rated for their accuracy as consumer devices and I thought because they are somewhat popular that it probably would be something I could access with Linux.

Found a blog post specifically about getting the H10 to connect.
https://nob.ro/post/polar_h10_ubuntu/

If it wasn’t for that blog I might have not gotten my device working under Linux but with those instructions was able to get a connection with gattool and start measuring heart beats. I was not able to get Python to connect with pygatt or pybluez but by using the one liner for gattool I could run it as a system command and capture back the data in Python.

So, I don’t have the gsr readings that I was getting with my Arduino solution but it is a more accurate heart rate monitor and I am not tied to my machine while recording. I have Python routines that activate the device, collect the data and save it to database. I have an interactive, biofeedback type, of program that shows not only my heart rate but a number of heart rate variability values. HRV can give you various ways to do biofeedback to achieve certain states that improve the values or can simply be an indication of over all heart health.

Besides being able to do live sessions displaying HRV values as I am recording heart rate I have some routines that give me statistics and create graphs of existing sessions that have been saved in the database.

It has been a nice project and there are plenty of tweaks to make it even more useful. One feature of the Polar H10 is that it can save a session of data in memory and then transfer the data back to your machine. However, I can find no information on the codes necessary to make it do that. There is an Android application Polar Beat, andofficial app for the Polar heart rate monitors, which will tell the strap to save a session in memory but still no documentation on how to do it yourself.

I’m hoping that by capturing bluetooth packets I might be able to figure out the codes myself. That is the current project. This is a high level overview of what I’ve done with heart rate over the past year.  I will intend to try and write up some more details of the projects I have accomplished with the Polar HRM to get to where I am currently and follow those to where I’m trying to go.

Feet are made for walking

Posted on by

When I built my foot controller out of a cheap game controller with a cardboard enclosure I had also purchased a DIY arcade game controller kit.  The kit is designed so that someone can build their own arcade housing and put the controller into it.

Finally got around to making an enclosure for it and trying it out.  First attempt I wired it backwards and it wasn’t working but when I flipped the wire it is working as expected.  (Chinese product with no instructions, I simply wired it the way that was more intuitive.)

My game controller in cardboard worked okay, but sometimes I would hit the buttons with my feet (regularly) and it would make things happen that I didn’t want. (Launching my robot at awkward times, switching weapons, etc.) The new controller is currently just a joystick so I can’t do anything with it except forward, back, left, and right.

The arcade controller kit does come with a bunch of buttons.  If I really wanted to get into making a full foot kit I could wire up some buttons for run, jump, and crouch.  Instead of using the joystick I could set up buttons for the wasd keys for movement as well.  But for now it is just a joystick for movement.  Will have to test for a while but I think it will be better than the game controller mounted in cardboard.

My woodworking skills are comparable to that of an eight year old.  (Unless the eight year old is actually good at wood working.)

Category: Games

Android RSS Feed Reader Reviews

Posted on by

I’ve been searching through lists of best RSS feed readers and the problem is that everyone has different tastes on what they are looking for in a reader. I do not want one that syncs to online accounts or has a lot of fancy images and graphics all over the screen. I want my feeds sorted into categories (news, science, tech, etc) and the ability to read all the feeds for each category at once instead of each feed individually. I just want a simple list of headlines but having one or two lines of text for each headline is preferred.

I had been using RSS Demon version 3.1.19 for quite a while now and it did all of the above. I reinstalled my system and now I’m finding that the search screen of RSS Demon 3 does not work and I don’t really want to add all the feeds by hand with URLs. The program does have OPML import. Wish I had the foresight to have saved my feeds in OPML before reinstalling but I did not. I could use another application to save my feeds and then import it into RSS Demon.

Read 1.4
Does have a working search for feeds
Does not sort feeds into categories, you have to read them one at a time
Does not have OPML import/export
Articles are listed with headline and a couple lines of text.

RSS News Reader
Does not seem to have any search for news feeds, add by URL only
Does have OPML import/export
Lets you categorize feeds, however you need to still read each feed individually – cannot read posts by category.
There is a tab feature where you can read All feeds at once or Favorites but you not by finer catetories.
Articles are listed with headline only.

Flym
Search does work
Does not have categories
Does not have OPML import/export
Articles are headline only with pictures.

Aggregator
No search
Does have categories
Does have OPML import/export
No ads
Article list seems to be headlines only

spaRSS
Does have categories
Search does not work
Does have OPML import/export
Article list is title, round picture, and author name

RSS Reader
Search does work
Does have categories
Does have OPML
Article list is headlines only
Ad or paid versions

gReader
Has search but sources seem more limited
Does have categories
Headlines and some text in article list
OPML export/import
Free and paid versions

RSS Demon 4.0.2
Does have search
Does not seem to have categories
Displays with headline, some text and pictures
Cannot find OPML functions
Ad and paid versions

For my purposes it looks like either sticking with RSS Demon 3.1.19 and creating an OPML list to import or using gReader are the best options. If I want completely free and no ads Aggregator or spaRSS would be a good option if I didn’t mind the headline only article lists.

Category: Musings

The quest for a better game controller

Posted on by

I’ve been playing first person shooter games for many years. I’ve never been very good at them and they aren’t my favorite game genre but it is nice to play in a game world from a first person perspective once in a while.

Movement in games is done traditionally by using the WASD keys for forward back and side to side. While the movement keys work pretty well I’ve always found it a little awkward to keep up a smooth movement while trying to perform other functions by pressing keys with the same hand. Crouch, jump, use, punch, reload, grenade, run, and often other functions as well. In the heat of the battle, trying to press special keys makes me lose my position in movement and I end up spun around and disoriented.

I got to thinking that it would make sense to use your feet for movement. Forward back and side to side. That would better align with your neural pathways so should be more intuitive and natural to use your feet to control movement in a game.

So I started looking for existing foot powered game controllers. Found a couple controllers that were made in just the past few years that were more specifically designed for VR environments. Rock forward and back and side to side. That is what I’m thinking of but they are kind of expensive. Also, why did it take VR before people started using foot controllers for game movement? Shouldn’t foot control have been an obvious solution for game movement all along?

Found some single click foot pedals. You can map one key or a set of macro keys to the foot pedal but it only does one function when you step on it. Did find different manufacturers that bundle foot pedals into banks of two, three or four (for both feet). Some people even say they use them for game functions but not for movement. Of course there are accelerator pedals for driving games and rudder controls for flight simulators but not much popularity in using your feet for walking in games. There do seem to be some individuals that have made their own foot powered controllers but no commercial products at all for foot game movement, other than the very recent and expensive VR controls.

Then decided if I want a foot controller maybe I can make one myself. I’m not a handy man and not great at DYI projects but starting with an existing game controller and maybe adding some adaptations to give it a foot platform might not be too hard of a project.

First I thought about D-pads. They are four directional and are often used in game controllers for the four directional movement.

Just figured you’d have to attach some sort of cross post to the d-pad so you could make a foot platform that would be large enough to use for feet instead of hands. Maybe even the buttons could be adapted for feet for functions like crouch, jump and run that are also natural leg activities along with movement. But foot controlled movement is the base goal I am trying to achieve, if the feet can do other functions as well those are nice to haves but not necessary.

Then as I researched a little more started realizing that a game pad joystick might even be more natural movement for the feet than a d-pad. Just slide forward and back and side to side. Joysticks typically have eight movement directions instead of four but game pads generally are recognized already by your system and either the left joystick or d-pad is already going to be mapped to movement in game.

I currently have a Logitech game controller that has two thumb joysticks (and a d-pad as well). I couldn’t really use the d-pad with my feet without attaching some sort of larger platform to it but the joystick can be controlled with my foot just by sliding it around. So without any modification, for a test I just propped the game pad on a cushion at the bottom of my computer desk and tried it out as a foot control.

I was just doing a quick proof of concept test. I expected it to be awkward and not a great test because the controller is just loose, not fastened down and prone to slide and move, and the tiny joystick is a little small for a foot. I was pleasantly surprised that it worked quite well. Sure a little getting used to not using the keyboard for movement as I’ve been doing that for years and occasionally bumping the other controls. But started out being able to move around without problems and after a couple hours of game play I was actually playing better with my hokey foot set up than I do with the keyboard.

Very promising. If I get a controller well mounted so that it is fixed in a location comfortable for the feet and attach some sort of larger cap to the joystick (a foot platform) then I should have a very good foot controller for game movement.

I don’t want to ruin my existing game pad so I ordered a cheap one to play with mounting and gluing on attachments to make it better as a foot pad. (lots of off brand models very cheap). I even had a game controller that had broken keys that I got rid of last year. Now I wish that I had saved it as something that I could play with adapting for foot control use. I’m going to start with joysticks and that seems like a good idea but I think d-pads could also be easily adapted as foot controls. I think this is going to improve my game play and will also situate me if I do get into VR some time in the future.

Category: Games

IP Phone

Posted on by

Some years ago I had looked into getting a Skype phone as a cheap way to have a phone that would work anywhere that I had wifi access.  Finally after doing some research I bought a SIP phone and created an account with Callcentric as even cheaper than Skype and more versatile as I wasn’t trapped with one service provider.  Well, I liked Callcentric service but hated the phone, it wasn’t all that great and I could only get it to connect to my home wifi (after a lot of tries) and never to any other.  (An unlocked Android phone would have been a better choice as a wifi phone – would do skype or SIP)

So come to the present.  I’m looking at upping the speed on my internet connection (it is pitiful right now) and thinking that if I get a faster connection then I really should look again at VoIP phones and get rid of my land line service.  The land line service is way too expensive for how much I don’t use it and I do have a cell phone any way.

Did a little searching around and came across the Obihai products.  They have a couple of little router devices that you just plug it into your ethernet connection (wifi is an option) and you plug a regular phone into that.  It will work with a Google voice account or pretty much any SIP provider.  This definitely looks like the solution to get rid of my land line.  Reviews are pretty good about voice quality and it supports up to four providers that you can connect to.  So I can connect to both Google Voice and my Call Centric account.  Call Centric can give me the ability to dial out 911 for as little as $1.95 a month.  I can use my cell for 911 but nice to have phones around the house that are handy as well.

That gives me full functionality of my land line for way way cheaper.  I can save close to $30 a month, though the phone company will give me a surcharge on my internet connection if I don’t have a phone account as well with, ding you with fees any way they can.  Actually it gives me more functionality than my existing land line because it has more features such as black listing spam numbers (why doesn’t the regular telco give you that ability?)

There are a couple of low cost alternatives to Obihai, such as Magic Jack and Ooma, but not only is Obihai likely cheaper than those but it gives me more choices in back end providers.  (If I want to set up my own SIP server like Asterix I have the option as well)

I think this is a service I’m going to like, mostly because it will save a lot of money.  I always get a little frustrated with how many fees are tacked on my regular  phone bill.  This shouldn’t feel like a rinky dink cheap work around as was the experience I had previously trying out a SIP phone, I think it will seem fairly seamless as a full service phone around the house.

Category: Compupotaters

Mind Mapping

Had listened to a recent episode of the Linux Action Show and there was a quick review of Freemind, Mind Mapping software. The host mentioned that he was using it all the time now for notes. Better for keeping organized notes than a text editor and better for putting up related text than a graphics program as the canavas automically resizes.

Nice review and I decided to look into it. I had learned basic mind mapping techniques on paper years ago but never really got into the style. On paper you can’t move things around once you’ve placed them there and it is too easy to hit the edge of the paper while you are writing down your ideas. Software mind mapping resolves those issue.

So playing around with the program to see how it works for keeping notes and trying to organize thoughts and ideas. It is fairly easy to use and does have a nice style to it. Looking around at the site I also found a fork of Freemind called Freeplane. Even though if you look at any top x lists for mind mapping software you will see references to Freemind but not Freeplane and download activity of Freemind is much bigger, Freeplane seems to have the most active and most user responsive development which means a somewhat more complete feature set.

Freemind gives you 73 icons that you can put in your nodes for graphical representation of your ideas (which is supposed to be an important component of mind mapping.) That may sound like a lot but is fairly limited in what you can express with it. You can manually also enter your own images if you have what you want and have them organized. But most images, and even most clip art, are too big for the documents.

Freeplane on the other hand allows user created icons, comes with more icons out of the box, and there are a couple of readily available add ons that give you a lot more icons (over 700). For some people the extra icons is an important feature, for others maybe not so much in their text/idea documents.

Another feature I liked of Freeplane is the ability to place free standing nodes on the screen that aren’t attached to the main node tree. You can then later decide to move them back into the regular node tree or you can have stand alone nodes on your screen. A standard mind map is supposed to be a single theme and all ideas branch off of that but it is nice for making documents that you have the flexibility of placing things where ever you want them on the screen.

Anyway, both programs are very handy utilities for brainstorming, taking notes for educational purposes, just making general notes or to do lists for yourself, for outlines and maybe even for creating organized full fledged informational documents. I have been using notepad for years to make to do lists at work and trying out Freeplane this week for my to do lists and so far I’m finding the format to be very nice for keeping ideas organized and being able to prioritize what I’m working on as well as readily capture any momentary ideas that need to be added to the list.

I’d certainly recommend trying mind mapping programs out. There are other titles out there as well both desktop applications and web based mind mapping sites but these two are fully cross platform and completely free so are a very good place to start.

Category: Musings | Tags: ,

Music

Posted on by

I’m not an accomplished musician in any sense of the term.  I learned how to play flutophone in 4th grade.  Took Clarinet in band in 5th and 6th grades.  In my late teens /early twenties I learned to play guitar a little bit but never really learned to play with others in a group.  In October 95 I started playing the recorder and played that almost every day for about ten years and started to taper off.

Recently when at the parent’s house I was seeing an old guitar and thought about the idea of getting back into music.  Guitar is nice but you have to deal with picks or calloused fingers.  The recorder was fun but too much saliva and also the pain of having to get new corks on the wooden ones.  I thought about maybe a portable keyboard which was an idea but not quite hitting home.

Thought about a xylophone.  I was thinking of metal bars for sound but turns out a xylophone technically is wooden bars, the toys that have metals bars and are called xylophones are mis-labeled.  (The word xylophone means wooden tone)  Metal bar instruments are glockenspiels.

Anyway got a somewhat cheap 27 key glockenspiel.  In all the instruments in the past I learned in a similar pattern.  Start with simple songs, like merrily we roll along, and work your way up to learn the instrument.  Using sheet music the whole way and using the written music most of the time.  This time I wanted to do something different.  The glockenspiel is harder than other instruments I’ve used before with sheet music because I have to look at the keys to play and can’t be looking at sheet music at the same time.  I can hunt and peck with sheet music but I also want to just play it more free form.  Work on just banging on the keys and learning the sounds and developing patterns.  Also I’ve never learned to get a full ear for picking out music just for listening too it.  It’s always been a bit tedious and having sheet music is easier (for me at least).  So I want to just play along with other music more often.

I’ll still play from the sheets but want to make it as often just playing around rather than just reading new songs and only playing by rote from them.  Different for me.  I’ll never be a great musician but it is still fun to dink around with.  I’m enjoying just drumming on the keys enough that I did also decide to order a 15 key wooden xylophone.  That should be fun as well.

Category: Musings | Tags:

Dilemma

Posted on by

I am sitting outdoors in the wilderness and look across the lake and it is cloudy on the other side with bright lighting that has a little bit of radiant green in it.  I wonder if I might be able to capture the lighting in a picture and run back to camp to grab my camera before the light changes.  As I grab my camera and start heading out a goat comes down and starts heading towards camp.  I worry that maybe I should try and protect the camp by chasing the goat away and then figure that probably he won’t actually bother anything and it is all right to go ahead and take my pictures.
[It wasn’t until after waking that I think this “wild” mountain goat was wearing a red plaid pack]

I don’t go back to exactly where I was sitting before because I want to take the shorter route towards the lake to get a picture more quickly with the lighting.  Looking across the lake now there is a small village way on the other side and the lighting is an almost sunny brightness with the buildings mostly centered in it.  I zoom up and take a shot but want to get a better angle to where I can get a shot of the whole lake.

I head back towards where I had been sitting before but there is a rock between here and there so I think maybe if I stand on the rock that would be a good angle for the picture.  I walk around the back of the rock to the edge on the far side and start to climb up.  My right hand is on the top and my left hand is on a little ledgy area just below.  The right hand is solid rock but the left touches something soft an squishy.  Must be a mossy spot.  The rock doesn’t look very hard to climb up but I am holding the camera on my right wrist and suddenly get a little nervous about climbing up on it.  It is not too hard but I decide I don’t want to do it so turn around.  I had just easily walked around the rock on the way up but now the down route is a steep side with very little hand holds and missing spots on the tiny foot ledge.  The logical part of my mind thinks “hey this was really easy and I had just walked up to here, why is is hard on the way down?”  I think maybe it is easier than it looks but still it is daunting.  I look the other way and it is a steep side off the front of the rock.  I wonder if I climb up the part I didn’t want to climb up before if it would be easy on the far side but it doesn’t look like it.  Stuck.

Another dilemma dream, these are an occaisional theme for me.

EEG

Posted on by

I’ve read articles for years in various magazines and sites that show EEG readings from studies or patients demonstrating what is going on in someone’s brain under different conditions.  That has always seemed like something that you would only encounter in a research lab or a hospital.  How cool would it be if we could take casual EEG readings of ourselves all the time under different conditions.  Can we tell if meditation is actually doing anything?  How about comparing that with recordings of experienced meditators?  What does your EEG look like when listening to music?  When viewing pictures?  When you are in a happy mood?  How about when you are mad or sad?

Well, in the past ten years, and especially in the past few years, suddenly EEG is available to the casual home user.   What a great tool for biofeedback, personal development and even keeping historical records of your brain activity.

Of course someone who is a serious hobbyist would be willing to pay a thousand or few for a device and there are some very nice machines in that price range but there are also very low cost devices that pretty much anyone can afford as more of a casual toy.

One of the first commercial EEG headbands is the Neurosky Mindwave.  It is roughly $100 and because it is so cheap and has been around quite a while there is a lot of support and software for it.  The limitation of such a cheap device is that it only reads one EEG channel (the left side of your frontal cortex to be precise).  Also, I tried one and it was too small for my head, causing the electrode to not sit flat and make a dent in my forehead.  Seems to fit women or teenagers just fine but not so much for an adult male.  (Though I have seen articles where people have taken apart the headband to make something more comfortable out of the parts.)

Looking at options there are quite a few in the consumer price range  In order of increasing price;  Melon headset, OpenEEG, Muse, Emotiv Insight, OpenBCI, Emotiv Epoc.

Well, I am a Linux enthusiast and don’t have a computer with Windows installed.  Some of the headsets support Android which I can use but I want to really be able to graph, view and save my sessions on my PC.  While the Muse and Emotiv headsets have limited Linux support they don’t really do it well, most of their software is geared towards Windows.  That left me with the OpenEEG and OpenBCI.  They are more primitive in that you have to individually place your electrodes instead of having a nice fancy headset like the others but on the other hand that means I can place electrodes wherever I want to and measure different areas of the brain where the fixed headsets only measure a few specific fixed points.

OpenEEG is a project that lists free circuit diagrams for people to build their own EEG machine.  That is a little beyond me but fortunately there is a company, Olimex, that will ship a pre-assembled and boxed machine for 99 Euros (EEG-SMT).  It is only a two channel EEG but I’ve decided to start with it as the cheaper option.  If I decide in the future I want something fancier and pantsier I will opt for an OpenBCI board (8 channels).  It is possible that if Muse gets official support for Brainbay and OpenVibe software I could really consider getting one of those.  (Emotiv products can work with Brainbay or OpenVibe but you have to pay an extra $200 for the SDK which is required to interface with those applications, which makes them a lot less attractive.)

 

Category: Becoming a Cyborg