Category Archives: Compupotaters

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.

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

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