Andrew Que Sites list Photos
Projects Contact
Main
      Woke up this morning enthusiastic but anxious.  The temperature was 9°F (-13°C) and I was going to cycle to work.  I'm not sure what my record is for the coldest ride into work.  I know I have cycled in the 10-20°F range, but I'm unsure what the exact temperatures were.  I have ridden in -23°F (-30°C) before, but that was only for 1.5 miles.  This would be 14.5 miles. 
   I've found that one reason I have had problems riding in the cold in the past was because I over-dressed.  Unable to vent the trapped heat I simply slowed down.  My core temperature was too high, my extremities too cold, and everything damp from sweat.  Now I was wearing far less and cycling much more comfortably.  While I knew I could make it to work, the question was, could I do so without feeling like I had gone to war with winter to do so?  I would soon get my answer.
   Since I have started riding with toe-clips I've found I can't live without them.  But my feet have been getting pretty cold on my rides as my cycling shoes are summer shoes.  I decided to try two corrections today.  First, I pulled out my heavy-duty think wool winter socks.  On my feet they barely fit into my cycling shows, but fit nonetheless.  Then I tried putting an old pair of socks over the entire shoe, cutting out a small opening on the bottom to expose the clips.  This allows me to put a hand warmer packets into the toes in an effort to provide a heat source for my toes.  I have never done a setup like this before, but I know that a heat source in my boots has helped on ride in the past.  I would try just a pair of genes for leg covering.  My riding shirt and a leather coat would be all the coverage I would use for my torso.  And a beanie hat and light balaclava would be all the facial protection I would start with.  For backup, I brought a scarf, boots, and sweatshirt.  They would be ready should I need them.
   I put my book on and started out the door.  Crisp cold air that only temperatures between 10 degrees can bring filled my lungs, and off I started.  I had the push needed to hit the peddles hard, and did so knowing that the exertion would help elevate my body temperature.  In a mile or so my heart was drumming at over 170 BPM (>90%) and I was not cold.  The trend continued.  While it was clearly cold, I was comfortable and moving at a good pace.  I thought briefly about stopping to take some pictures of the wonderful snow-covered landscape, but thought it would only lead to an uncomfortable dampness from the sweat that would surely accumulate.  So I pressed on.  By the halfway point I noticed my toes were not cold.  The combination of heat packs and heavy socks seemed to have done the trick.  The biggest problem was my runny noise, which was freezing to my mustache.
   About a mile from work my cellphone, which I use to track my trip and listen to audiobooks, decided to shutdown.  My headlight too was blinking red which means the battery is about out of power.  Seems neither could handle the cold.  But I made it to work without any issues.  It was cold, but I hadn't felt all that uncomfortable.  My water bottles had frozen, but I had not.
   At work it was donuts day, and I ate more than I should have.  By 5:00 pm when it was time to leave, the temperature had only climbed to 12°F (-11°C) but now I would have a 10 MPH headwind.  I decided to try a scarf and using my thermal pants for this ride, which would just be to State Street.  The scarf didn't last and I ditched it after a few blocks.  It meant my face was more exposed, but covering my mouth made breathing harder.  Again, the ride wasn't that bad. 
   I tried a trick while at work.  The heat packs are air activated, and it was my guess that the exothermic reaction that produced the heat was driven by oxygen.  My hypothesis was to place the heat packs in a sealed bag where, it was hoped, they would deplete the oxygen and turn off, thus preserving the reactive chemicals until the bag was opened.  It worked.  The warmers snapped right back to life and I was able to use them for both of the return legs of the trip.
   The last leg of the trip was the coldest.  By 9:30 pm when I was cycling home the temperature had dropped to 7°F (-14°C).  Winds slowed some to 7 MPH and shifted to WSW.  Knowing it was going to be colder and into the wind, I pushed hard.  I was burning 913 Calories/hour with an average heart rate of 166 BPM (91%) for 35 minutes.  But I was still comfortable.  About 300 feet from the house, my phone shutdown again, not finishing before I was pulling into the driveway.  This day was a good milestone.  I may have to look into some options for covering my cheeks, but other than that the ride went very well.
Washer Waterpump

Washer Waterpump

   Over the weekend the washing machine was acting up.  It wasn't the first time we had a problem with it.  Seems it would refuse to drain.  A couple months ago I took the hose off between the sink and water pump to see if maybe it was clogged.  It seemed to solve the problem.  But clearly the problem hadn't gone away.  So this evening I decided I would take out the water pump and see if there wasn't something I could do with it, thinking I may have to replace it entirely.  I started by removing the hoses.  When I removed the hose that ran between the washer drum and the water pump, I noticed what I was pretty sure was causing the problem.  After getting the entire segment of hose removed, I found an almost complete blockage that consisted of lint, hair ties, plastic wrappers, coins, and a plastic device designed to trap garbage from getting into the water pump.  It took me awhile to pull all the trash from the trap, but afterward it was good as new.  Xiphos had to assist me in getting the machine back together as positioning the hoses and hose clamps requires more than 2 hands.  The results: just like new.  The water pump had no trouble clearing a full drum out and I was able to get all 3 of my wash loads completed before the evening was over.  Good stuff.
 
   It has snowed most of the weekend, accumulating around 7 inches (18 cm).  The week to follow is forecast to be very cold.  While I love cold weather, I wonder if I will be good enough to bike to and from work a couple times a week like I have for the past 8 months.  After the game this evening, our group went out for our bi-weekly sushi.  Two boats of sushi this time, and it didn't last 10 minutes.

December 10, 2016

Implementing a Discrete Fourier Transform

Sitting fireside at my local coffee shop with a heavy snowstorm taking place outside, listening to Jehan Ariste Alain's Litanies, I came much closer to my goal of understanding how a Fast Fourier Transforms (FFT) works by understanding how to implement a Discrete Fourier Transform (DFT). The equation for a Fourier Transform:

Where g( t ) is some function with respect to time, f is some frequency, i is the square root of negative one. You can basically ask the function, what is the phase and amplitude for a given frequency for the time domain function g.

This is fine for transforming functions, but for most programming application we need to transform based on discrete data points. For this we can use a Discrete Fourier Transform (DFT):

Where xn is a data sample at time n, N is the total number of data samples, f is some integer frequency between 0 and N – 1, and G( f ) is amplitude of the given frequency. The discrete form is similar to the general form, except that the function g( t ) is replaced by our discrete sample, and there is now a finite range.

I have seen this equation in many places, but what the exponent is doing isn’t terribly obvious until you remember Euler’s formula:

Substitute this back in and we get:

Now we just have the imaginary number i as part of the equation, but this is fine because what we actually have is a complex number. They are generally represented in the form:

And here that breaks down pretty straight-forward:

In the form I’ve written it, G is a function. But it is actually a set just like x. So a slightly better form maybe:

There data, x, is actually complex data. Since the discrete data we are putting in consists of real values, it means the imaginary part is just 0. Now we just need to remember how to multiply complex numbers.

Where a and b are complex numbers made for a real part (nr) and an imaginary part (ni) represented n=(nr , ni).

With that, I actually have enough information to implement a Discrete Fourier Transform.

#include <math.h>
#include <stdio.h>

#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795028841971693993751058209749445923
#endif

int main()
{
  enum { N = 16 };
  double inReal[ N ];
  double inImag[ N ];

  double outReal[ N ];
  double outImag[ N ];

  // Generate a signal.
  for ( unsigned index = 0; index < N; index += 1 )
  {
    inReal[ index ]  =       cos( 7 * 2 * M_PI * index / N );
    inReal[ index ] += 0.3 * sin( 3 * 2 * M_PI * index / N );
    inReal[ index ] += 0.5 * sin( 2 * 2 * M_PI * index / N );
    inImag[ index ] = 0;
  }

  // For each of the sample outputs...
  for ( unsigned k = 0; k < N; k += 1 )
  {
    // Start sum at zero.
    outReal[ k ] = 0;
    outImag[ k ] = 0;

    // For each input sample...
    for ( unsigned n = 0; n < N; n += 1 )
    {
      double cosTerm = cos( -2 * M_PI * k * n / N );
      double sinTerm = sin( -2 * M_PI * k * n / N );

      outReal[ k ] += inReal[ n ] * cosTerm - inImag[ n ] * sinTerm;
      outImag[ k ] += inReal[ n ] * sinTerm + inImag[ n ] * cosTerm;
    }
  }

  // Print the results.
  for ( unsigned index = 0; index < N; index += 1 )
    printf( "%u: %f %fi\n", index, outReal[ index ] / N, outImag[ index ] / N );

  return 0;
}

Here we construct a waveform consisting of 3 sine waves. One at 7 Hz, amplitude of 1, and phase 90°; one at 3 Hz, 0.3 amplitude, and 0°; and 2 Hz, 0.5 amplitude, and 0°. Then the transform, which consists of two loops. The outer loop is for each available integer frequency. The inner loop is the summation above. The last part prints the normalized of the transform, which agree with what I see when I do an FFT on the data.

This is a major step forward in my goal to understand an FFT. I still have a couple of questions, like why the output seems to be split between the upper and lower half. But I have proven (to myself anyway) that I can implement a DFT and that is a lot of progress.

   Cool ride to breakfast this morning at 23°F (-5°C) but I was pretty comfortable.  The biggest problem I have with my Friday ride to breakfast is having to leave breakfast and get back on the bike.  My clothing is usually still quite damp.  So I have started to bring a shirt change, which helps.  My pants, coat, and gloves are still wet, but are much more tolerable damp than my shirt.  Unfortunately we found that our breakfast spot is no longer going to be open 24 hours on the weekends like it has been, and will begin to open at 6:00 am.  That is still alright because we plan to be there at 6:00 am, but at exactly 6:00 am.  As long as the doors are open at exactly 6:00 I should be good.  Otherwise, they will have a very cold Que doing a little dance outside waiting for doors to open.

I made a discovery a few days ago that helps a great deal in understanding Fast Fourier Transforms (FFT). The complex numbers from an FFT contain both amplitude (which I did know) and phase (which I did not).

Where a is the amplitude, p the phase, x is a complex number with xr being the real part and xi being the imaginary part. This put together a much better picture of how the output of an FFT is able to represent the original waveform. I have begun work on an FFT demo that should help illustrate this, but it isn’t finished yet.

   Cycled into work today.  The temperatures have been staying right around freezing but the sunlight from the last couple of days cleared off roads and bike paths.  I biked to work with only a sweatshirt and gloves (no coat) and felt fine.  When I left work the temperature had dropped a little and the wind had picked up and was now directly at me.  I put on my coat as I set out for home.  Where I work it is pretty open and there is no windbreak.  So the first few blocks are slow-moving, especially when you are not warmed up.  But by the time I got to Monona Drive I was overly warm.  I had to stop and remove the sweatshirt--aptly named because in just 2 miles it was soaked with sweat.  After this point there is a good deal of tree cover and the wind isn't as noticeable until John Nolen Drive.  Once to John Nolen there is a stretch of road between Lake Monona and Monona Bay where the winds have nothing to stop them.  But by this point in the ride I was good and warmed up so it didn't bother me.  Winter has come, and I am doing much better with the cold this year over last.