<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Matthew van Eerde's web log</title><subtitle type="html" /><id>http://blogs.msdn.com/matthew_van_eerde/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/matthew_van_eerde/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-04-27T11:04:00Z</updated><entry><title>How to turn on HDCP or SCMS in an audio playback app</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/11/10/how-to-turn-on-hdcp-or-scms-in-an-audio-playback-app.aspx" /><link rel="enclosure" type="application/zip" length="46923" href="http://blogs.msdn.com/matthew_van_eerde/attachment/9920366.ashx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/11/10/how-to-turn-on-hdcp-or-scms-in-an-audio-playback-app.aspx</id><published>2009-11-10T19:07:00Z</published><updated>2009-11-10T19:07:00Z</updated><content type="html">
&lt;p&gt;There's an &lt;a href="http://msdn.microsoft.com/en-us/library/dd756608%28VS.85%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd756608(VS.85).aspx"&gt;MSDN sample&lt;/a&gt; of how to turn on HDCP or SCMS in a playback app.&amp;nbsp; The sample is loosely based on a test app I wrote, but there are still some rough edges.&amp;nbsp; For example, the &lt;span style="font-family: monospace;"&gt;CMFAttributeImpl&amp;lt;T&amp;gt;&lt;/span&gt; template is not part of the SDK or the DDK.&amp;nbsp; Also, there's a leak in the &lt;span style="font-family: monospace;"&gt;GetDigitalAudioEndpoint&lt;/span&gt; implementation.&amp;nbsp; (Using the private template was my bug.&amp;nbsp; The leak was someone else's.)&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Exercise:&lt;/i&gt; find the leak.&lt;/p&gt;

&lt;p&gt;There are also rough edges in the test app.&amp;nbsp; For one thing, it doesn't play audio - the way to use the app is to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start playing audio using your favorite audio playback application, to the digital output on which want to turn on HDCP or SCMS.&lt;/li&gt;

&lt;li&gt;Run the trustedaudiodrivers2.exe command line to do what you want it to.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Source and binaries (x86 and amd64) attached.&lt;/p&gt;

&lt;blockquote style="font-family: monospace;"&gt;
&amp;gt;trustedaudiodrivers2&lt;br&gt;trustedaudiodrivers2 --list-devices&lt;br&gt;&lt;br&gt;trustedaudiodrivers2&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --device [ communications | console | multimedia | &lt;device-name&gt; &amp;lt;device-name&amp;gt;]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --copy-ok [ 0 | 1 ]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --digital-output-disable [ 0 | 1 ]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --test-certificate-enable [ 0 | 1 ]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --drm-level&lt;drm-level&gt; &amp;lt;drm-level&amp;gt;&lt;br&gt;&lt;br&gt;
--list-devices: displays a list of output devices.&lt;br&gt;&lt;br&gt;Sets a Trusted Audio Drivers 2 output policy on a given audio endpoint.&lt;br&gt;--device&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; communications: set policy on default communications render endpoint.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; console: set policy on default console render endpoint.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; multimedia: set policy on default multimedia render endpoint.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;device-name&amp;gt;&lt;device-name&gt;: set policy on the endpoint with this long name.&lt;br&gt;--copy-ok: 1 or 0. Set to 0 to turn on "copy protection" (SCMS or HDCP)&lt;br&gt;--digital-output-disable: 1 or 0. Set to 1 to disable output (or turn on HDCP.)
--test-certificate-enable: 1 or 0. Set to 1 to allow the test certificate.&lt;br&gt;--drm-level: set to a number. 1100 is a good default.
&lt;/device-name&gt;&lt;/drm-level&gt;&lt;/device-name&gt;&lt;/blockquote&gt;

&lt;p&gt;Here's a sample command line which should disable the digital out (or enable HDCP, if the driver supports it.)&amp;nbsp; This is line-wrapped for readability only.&lt;br&gt;&lt;/p&gt;

&lt;blockquote style="font-family: monospace;"&gt;
&lt;p&gt;&amp;gt;trustedaudiodrivers2.exe&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --device "Acer H213H (High Definition Audio Device)"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --copy-ok 1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --digital-output-disable 1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --test-certificate-enable 1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; --drm-level 1300 &lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If all goes well the output should look something like this:&lt;/p&gt;

&lt;blockquote style="font-family: monospace;"&gt;
&lt;p&gt;Output Trust Authorities on this endpoint: 2&lt;br&gt;Processing Output Trust Authority #1 of 2&lt;br&gt;OTA action is PEACTION_PLAY (1)&lt;br&gt;GetOriginatorID() called&lt;br&gt;GetOriginatorID() called&lt;br&gt;GenerateRequiredSchemas() called&lt;br&gt;dwAttributes: MFOUTPUTATTRIBUTE_DIGITAL (0x00000001)&lt;br&gt;guidOutputSubType: MFCONNECTOR_HDMI ({57CD596D-CE47-11D9-92DB-000BDB28FF98})&lt;br&gt;cProtectionSchemasSupported: 1&lt;br&gt;MFPROTECTION_TRUSTEDAUDIODRIVERS ({65BDF3D2-0168-4816-A533-55D47B027101})&lt;br&gt;MFPROTECTION_TRUSTEDAUDIODRIVERS supported.&lt;br&gt;IMFOutputSchema::GetSchemaType called&lt;br&gt;IMFOutputSchema::GetConfigurationData called&lt;br&gt;IMFOutputTrustAuthority::SetPolicy returned 0x00000000&lt;br&gt;Processing Output Trust Authority #2 of 2&lt;br&gt;OTA action is PEACTION_EXTRACT (4)&lt;br&gt;Skipping as the OTA action is not PEACTION_PLAY&lt;br&gt;Policy successfully applied.&amp;nbsp; Press any key to release IMFTrustedOutput... &lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At that point I pressed a key, which redacted the policy, and the music started playing again.&lt;/p&gt;

&lt;p&gt;Common causes of failures:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No audio is playing to that device.&amp;nbsp; Setting protection requires an active audio stream.&lt;/li&gt;

&lt;li&gt;The audio device is not S/PDIF or HDMI.&lt;br&gt;&lt;/li&gt;

&lt;li&gt;The audio driver is not capable of enforcing the protection.&lt;/li&gt;

&lt;li&gt;The audio driver is test-signed only; try --test-certificate-enable 1&lt;/li&gt;

&lt;li&gt;Kernel debugging is enabled.&lt;/li&gt;

&lt;li&gt;Driver verifier is enabled.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This source should compile with just publically available headers and no special voodoo on the part of the developer.&lt;br&gt;&lt;br&gt;&lt;b&gt;EDIT: 11/13/2009 10:05 AM&lt;/b&gt;&lt;br&gt;&lt;br&gt;A subtle problem was called to my attention.&amp;nbsp; This line triggers an ATL &lt;span style="font-family: monospace;"&gt;ASSERT&lt;/span&gt;:&lt;/p&gt;

&lt;blockquote style="font-family: monospace;"&gt;
&lt;p&gt;hr = pMFOutputTrustAuthority-&amp;gt;SetPolicy(&amp;amp;pMFOutputPolicy, 1, &amp;amp;pbTicket, &amp;amp;cbTicket);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;span style="font-family: monospace;"&gt;ASSERT&lt;/span&gt; is in &lt;span style="font-family: monospace;"&gt;CComPtr&amp;lt;IMFOutputPolicy&amp;gt;::operator&amp;amp;&lt;/span&gt; which &lt;span style="font-family: monospace;"&gt;ASSERT&lt;/span&gt;s if the pointer &lt;span style="font-family: monospace;"&gt;CComPtr&amp;lt;IMFOutputPolicy&amp;gt;::p&lt;/span&gt; is not &lt;span style="font-family: monospace;"&gt;NULL&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;My first instinct was to bypass the assertion like this:&lt;/p&gt;

&lt;blockquote style="font-family: monospace;" e=""&gt;
&lt;p&gt;hr = pMFOutputTrustAuthority-&amp;gt;SetPolicy(&amp;amp;pMFOutputPolicy&lt;span style="background-color: yellow;"&gt;.p&lt;/span&gt;, 1, &amp;amp;pbTicket, &amp;amp;cbTicket);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But &lt;span style="font-family: monospace;"&gt;ASSERT&lt;/span&gt;s are there for a reason.&amp;nbsp; The fundamental problem here is that I'm trying to be too clever.&lt;/p&gt;

&lt;p&gt;Despite its name, &lt;span style="font-family: monospace;"&gt;IMFOutputTrustAuthority::SetPolicy&lt;/span&gt; takes, not an &lt;span style="font-family: monospace;"&gt;IMFOutputPolicy *&lt;/span&gt;, but an &lt;i&gt;array&lt;/i&gt; of &lt;span style="font-family: monospace;"&gt;IMFOutputPolicy *&lt;/span&gt;s.&amp;nbsp; A little confusing, yes.&amp;nbsp; As this is effectively a sample, I should be emphasizing this behavior, not covering it up.&lt;/p&gt;

&lt;p&gt;So here's the fix I decided on.&amp;nbsp; Updated source and binaries attached.&lt;/p&gt;

&lt;blockquote style="font-family: monospace;"&gt;// we're only setting a single policy but the API allows setting multiple policies&lt;br&gt;// (like WaitForMultipleObjects)&lt;br&gt;IMFOutputPolicy *rMFOutputPolicies[1] = { pMFOutputPolicy };&lt;br&gt;hr = pMFOutputTrustAuthority-&amp;gt;SetPolicy(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rMFOutputPolicies,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ARRAYSIZE(rMFOutputPolicies),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;pbTicket,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;cbTicket&lt;br&gt;);&lt;br&gt;&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9920366" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Audio" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Audio/default.aspx" /><category term="Win32" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Win32/default.aspx" /></entry><entry><title>Perl one-liner: approximate pi via Monte Carlo method</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/10/12/perl-one-liner-approximate-pi-via-monte-carlo-method.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/10/12/perl-one-liner-approximate-pi-via-monte-carlo-method.aspx</id><published>2009-10-12T17:32:00Z</published><updated>2009-10-12T17:32:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://programmingpraxis.com/2009/10/09/calculating-pi/" mce_href="http://programmingpraxis.com/2009/10/09/calculating-pi/"&gt;http://programmingpraxis.com/2009/10/09/calculating-pi/&lt;/a&gt; &lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;&amp;gt;&lt;span style="background-color: yellow;"&gt;perl -e"print 4/(map{$n+=rand()**2+rand()**2&amp;lt;1}1..pop)*$n"&lt;/span&gt; 5000&lt;br&gt; 3.1336&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="background-color: yellow;"&gt;59 characters&lt;/span&gt;, plus arguments.&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906231" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Perl" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Perl/default.aspx" /></entry><entry><title>Nitpicking László Polgár's Chess: ... #1071</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/09/02/nitpicking-l-szl-polg-r-s-chess-1071.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/09/02/nitpicking-l-szl-polg-r-s-chess-1071.aspx</id><published>2009-09-02T15:55:00Z</published><updated>2009-09-02T15:55:00Z</updated><content type="html">&lt;p&gt;I was reading László Polgár's excellent book &lt;i&gt;Chess: 5334 Problems, Combinations, and Games &lt;/i&gt;and ran across #1071, White to move and mate in 2:&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9890372/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9890372/original.aspx" width="288" height="288"&gt;&lt;/p&gt;

&lt;p&gt;The purported solution is...&lt;/p&gt;

&lt;blockquote&gt;&lt;p style="font-size: larger;"&gt;1. ♘xf6+&amp;nbsp;♚xf6&lt;br&gt;2. ♕f7#&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;... which, indeed, works - and there is no other mate in two that I can see - so why blog this?&lt;/p&gt;

&lt;p&gt;Because there's a mate in &lt;i&gt;one.&lt;/i&gt; &lt;br&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9890374" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Chess" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Chess/default.aspx" /></entry><entry><title>Forcing Windows to install on a single partition</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/21/forcing-windows-to-install-on-a-single-partition.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/21/forcing-windows-to-install-on-a-single-partition.aspx</id><published>2009-08-21T19:58:00Z</published><updated>2009-08-21T19:58:00Z</updated><content type="html">&lt;p&gt;If you're installing Windows via a boot DVD, and you choose Custom, you have the option to rearrange partitions.&amp;nbsp; &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/20/tweaks-i-make-every-time-i-install-windows.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/20/tweaks-i-make-every-time-i-install-windows.aspx"&gt;I like use this to have each drive be one big partition.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Windows 7 wants to set aside a 100 MB partition for something-or-other.&amp;nbsp; I'm sure there's a very good reason for this but I am too lazy to look up the team that owns this space and ask them what it is.&lt;/p&gt;&lt;p&gt;So I'm in the "Where do you want to install Windows?" stage, I've gone into "advanced drive setup", and I've deleted all the partitions.&amp;nbsp; Fine.&amp;nbsp; I then create a partition that fills the drive, and I get this popup:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Install Windows&lt;br&gt;To ensure that all Windows features work correctly, Windows might create additional partitions for system files.&lt;br&gt;OK | Cancel&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;After letting Windows finish installing, I jump into diskpart.exe and sure enough, Windows &lt;i&gt;has&lt;/i&gt; created an additional partition.&amp;nbsp; A small one, to be sure... but an &lt;i&gt;additional partition&lt;/i&gt; (horrors!)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Not being one to let Windows push me around, I decided to experiment, and came up with the following dance to allow me to just have one big partition thankyouverymuch:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Boot from the Windows DVD&lt;/li&gt;&lt;li&gt;Choose Custom (advanced) as opposed to Upgrade&lt;/li&gt;&lt;li&gt;Go into Drive options (advanced)&lt;br&gt;&lt;/li&gt;&lt;li&gt;Delete all partitions on the drive&lt;/li&gt;&lt;li&gt;Create a new partition - you will get the prompt above&lt;/li&gt;&lt;li&gt;Click OK&lt;/li&gt;&lt;li&gt;There will now be two partitions - a small (System) one and a large (Primary) one.&lt;br&gt;&lt;/li&gt;&lt;li&gt;Delete the large one.&lt;/li&gt;&lt;li&gt;Extend the new one to fill the drive.&lt;/li&gt;&lt;li&gt;Install Windows.&lt;/li&gt;&lt;li&gt;Open Windows Explorer&lt;/li&gt;&lt;li&gt;Right-click the C: drive | Properties&lt;/li&gt;&lt;li&gt;Delete the "System Reserved" partition name&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;i&gt;Et voilà&lt;/i&gt;, Windows installs perfectly happily on the single partition (confirmed with diskpart.exe post-installation.)&lt;br&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9878987" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Win32" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Win32/default.aspx" /><category term="Philosophy" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Philosophy/default.aspx" /></entry><entry><title>Tweaks I make every time I install Windows</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/20/tweaks-i-make-every-time-i-install-windows.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/20/tweaks-i-make-every-time-i-install-windows.aspx</id><published>2009-08-21T00:11:00Z</published><updated>2009-08-21T00:11:00Z</updated><content type="html">&lt;p&gt;As preparation for moving one of my machines from Vista to Windows 7, I'm compiling a list of all the little tweaks I like to make to machines that I use a lot:&lt;/p&gt;&lt;p&gt;Boot from the Windows DVD.&amp;nbsp; Delete all partitions; make each hard drive one big partition.&amp;nbsp; (Hmm... apparently Windows 7 &lt;i&gt;really&lt;/i&gt; wants a second 100 MB partition.&amp;nbsp; &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/21/forcing-windows-to-install-on-a-single-partition.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/21/forcing-windows-to-install-on-a-single-partition.aspx"&gt;Do the partition dance to force it into installing on a single partition.&lt;/a&gt;) &lt;br&gt;&lt;/p&gt;&lt;p&gt;In the "password hint" box, type a misleading hint.&lt;/p&gt;&lt;p&gt;In "Help protect your computer and improve Windows automatically", choose "Ask me later."&lt;/p&gt;&lt;p&gt;Once I'm in, create a new limited user (not a member of the Administrators group) and use that as my primary account.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Control Panel | Hardware and Sound | Mouse&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pointers | Enable pointer shadow (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pointer Options&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enhance pointer precision (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hide pointer while typing (uncheck)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Right-click taskbar | Properties | Taskbar&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Use small icons (check)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Taskbar location on screen (change to "Right")&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Taskbar buttons (change to "Never combine")&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Notification area | Customize&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Turn system icons on or off&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Clock | Off (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Volume | Off (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Network | Off (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... turn everything off, except sometimes.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (for example, I might leave Power on for a laptop.)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Always show all icons and notifications on the taskbar (check)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Use Aero Peek to preview the desktop (uncheck)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Windows Explorer | Organize&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Layout | Details pane (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Folder and search options | View | Advanced settings&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Always show icons, never thumbnails (check)&lt;br&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Always show menus (check)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Display file icon on thumbnails (uncheck)&lt;br&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Display file size information in folder tips (uncheck)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Display the full path in the title bar (Classic theme only) (check)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Hidden files and folders | Show hidden files, folders, and drives (select)&lt;br&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Hide empty drives in the Computer folder (uncheck)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Hide extensions for known file types (uncheck)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; Hide protected operating system files (Recommended) (uncheck, Yes I'm sure)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Show pop-up description for folder and desktop items (uncheck)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Control Panel | System and Security | Windows Update | Change settings&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Download updates but let me choose whether to install them (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Allow all users to install updates on this computer (check)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Elevated command prompt | gpedit.msc | Local Computer Policy&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; User Configuration | Administrative Templates | Windows Components&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Windows Explorer | Turn off numerical sorting in Windows Explorer (enable)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Computer Configuration | Administrative Templates&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Power Management | Video and Display Settings&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Turn Off Adaptive Display Timeout (Plugged In) (enable)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Turn Off Adaptive Display Timeout (On Battery) (enable)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Windows Components | Windows Update&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do not display 'Install Updates and Shut Down' ... (enable)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do not adjust default option to 'Install Updates and Shut Down' ... (enable)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Control Panel | View by: Small icons (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AutoPlay | Use AutoPlay for all media and devices (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Indexing Options | Modify | Show all locations&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Offline Files (uncheck)&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; C:\Users (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\ProgramData\Microsoft\Windows\Start Menu (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Troubleshooting | Change settings | Computer Maintenance | Off (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Windows Defender | Tools&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Automatic scanning | Automatically scan my computer (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Real-time protection | Use real-time protection (recommended) (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Administrator | Use this program (uncheck)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Right-click Start Menu | Properties&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Customize&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Computer | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Connect To (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Control Panel | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Default Programs (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Devices and Printers (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Documents | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enable context menus and dragging and dropping (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Games | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Help (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Highlight newly installed programs (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Music | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Open submenus when I pause on them with the mouse pointer (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Personal folder | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pictures | Don't display this item (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Search other files and libraries | Don't search (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Search programs and Control Panel (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Use large icons (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Number of recent programs to display (set to 20 to make the menu bigger)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Number of recent items to display in Jump Lists (set to 20 to make the menu bigger)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Store and display recently opened programs in the Start menu (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Store and display recently opened items in the Start menu and the taskbar (uncheck)&lt;/p&gt;&lt;p&gt;Right-click everything that is pinned to the taskbar&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Unpin this program from taskbar&lt;br&gt;&lt;/p&gt;&lt;p&gt;Right-click Recycle Bin | Properties&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For each hard drive in turn (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Don't move files to the Recycle Bin. Remove files immediately... (select)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Control Panel | Appearance and Personalization&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Personalization | Change desktop icons | Recycle Bin (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change desktop background&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Picture Location: Solid Colors (select, choose black)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Control Panel | User Accounts | Change your account picture&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Browse for more pictures&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/6831850/thumb.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/6831850/thumb.aspx" alt="http://blogs.msdn.com/photos/matthew_van_eerde/images/6831850/thumb.aspx"&gt;&lt;/p&gt;&lt;p&gt;Control Panel | Ease of access&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change how your mouse works&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mouse pointers | Regular Black (select)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prevent windows from being automatically arranged when moved to the edge of the screen (check)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change how your keyboard works&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set up Sticky Keys | Turn on Sticky Keys when SHIFT is pressed five times (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Optimize visual display&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Turn off all unnecessary animations (when possible) (check)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Make a folder on the desktop named "_"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Open the following folders simultaneously&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\ProgramData\Microsoft\Windows\Start Menu&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Users\&lt;i&gt;%username%&lt;/i&gt;\AppData\Roaming\Microsoft\Windows\Start Menu&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Copy various shortcuts from Start Menu over to _&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Notepad&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paint&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Command Prompt&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Calculator&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... whatever else strikes my fancy&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... as I install programs, consider adding them here if I use them a lot&lt;/p&gt;&lt;p&gt;Right-click the taskbar | Toolbars | New toolbar... | Desktop | _ (Select Folder)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Right-click the taskbar | Lock the taskbar (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drag the thumb of the _ toolbar to the top of the taskbar&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Right-click _&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Show Text (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Show title (uncheck)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; View | Small Icons (check)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drag the taskbar to be a tiny bit wider so three small icons fit side-by-side&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drag the view-active-tasks part of the taskbar to be big&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Right-click the taskbar | Lock the taskbar (check)&lt;/p&gt;&lt;p&gt;Make a 1-pixel-by-1-pixel black .jpg and &lt;a href="http://weblogs.asp.net/sergeyzwezdin/archive/2009/06/09/change-of-the-background-image-on-the-logon-screen-in-windows-7.aspx" mce_href="http://weblogs.asp.net/sergeyzwezdin/archive/2009/06/09/change-of-the-background-image-on-the-logon-screen-in-windows-7.aspx"&gt;set it as the LogonUI background&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;I'm sure I'm forgetting some other things.&amp;nbsp; I'll add them later when I run into them.&lt;/p&gt;&lt;p&gt;I could probably make a series out of this.&amp;nbsp; Possible candidates for future posts: "Tweaks I make every time I install Office", "Tweaks I make every time I install Firefox"... &lt;/p&gt;&lt;p&gt;Command Prompt | Alt-Space | Defaults | QuickEdit Mode (check) &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9877550" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Win32" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Win32/default.aspx" /><category term="Philosophy" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Philosophy/default.aspx" /></entry><entry><title>How to calculate a sine sweep - the right way</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/07/how-to-calculate-a-sine-sweep-the-right-way.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/07/how-to-calculate-a-sine-sweep-the-right-way.aspx</id><published>2009-08-08T01:12:00Z</published><updated>2009-08-08T01:12:00Z</updated><content type="html">&lt;p&gt;Three quarters are better than a dollar because they make noise!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- Lilly, &lt;i&gt;Lilly's Purple Plastic Purse&lt;/i&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Last time I talked about &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/03/how-to-calculate-a-sine-sweep-the-wrong-way.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/03/how-to-calculate-a-sine-sweep-the-wrong-way.aspx"&gt;how to calculate a sine sweep mathematically&lt;/a&gt;.&amp;nbsp; There's a closed-form solution which is quite elegant but, alas, useless in a practical computer implementation due to the very big numbers that are being fed to the sin(...) function.&lt;/p&gt;
&lt;p&gt;A computer implementation will care only about the discrete samples that need to be generated.&amp;nbsp; The integral in the previous post turns out to be counterproductive - we're much more interested in the infinite sequence of &lt;i&gt;φ&lt;/i&gt;&lt;sub&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sub&gt;, and more particularly in their residue mod 2π.&lt;/p&gt;
&lt;p&gt;Here are Matlab scripts that implement a sine sweep both ways:&lt;/p&gt;
&lt;p&gt;First, the naïve mathematical solution that just calculates the exponential:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;function signal = sinesweep_nostate( ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; start, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finish, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sample_rate, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; amplitude, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; initial_phase, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dc ...&lt;br&gt;)&lt;br&gt;% sinesweep_nostate returns a single-channel sine logarithmic sweep&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO NOT USE THIS FUNCTION IN PRODUCTION&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THIS IS A PEDAGOGICAL EXERCISE ONLY&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THE SIGNAL THIS PRODUCES GRADUALLY DISTORTS&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INSTEAD USE sinesweep&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start: starting frequency in Hz&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; finish: ending frequency in Hz&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds: duration of sweep in seconds&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; samplerate: samples per second&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amplitude: amplitude&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initial_phase: starting phase&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dc: dc&lt;br&gt;&lt;br&gt;% echo these interesting intermediate values to the console&lt;br&gt;R = (finish / start) ^ (1 / seconds)&lt;br&gt;B = 2 * pi * start / log(R)&lt;br&gt;A = initial_phase - B&lt;br&gt;&lt;br&gt;time = 0 : 1 / sample_rate : seconds;&lt;br&gt;phase = A + B * R .^ time;&lt;br&gt;signal = amplitude * sin(phase) + dc;&lt;br&gt;&lt;br&gt;end % sinesweep_nostate&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now, the iterative version that adds up the little Δ&lt;i&gt;φ&lt;/i&gt;s to calculate &lt;i&gt;φ&lt;/i&gt;&lt;sub&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sub&gt; iteratively:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;function signal = sinesweep( ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; start, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finish, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sample_rate, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; amplitude, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; initial_phase, ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dc ...&lt;br&gt;)&lt;br&gt;% sinesweep returns a single-channel sine logarithmic sweep&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start: starting frequency in Hz&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; finish: ending frequency in Hz&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds: duration of sweep in seconds&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; samplerate: samples per second&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amplitude: amplitude&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initial_phase: starting phase&lt;br&gt;%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dc: dc&lt;br&gt;&lt;br&gt;time = 0 : 1 / sample_rate : seconds;&lt;br&gt;frequency = exp( ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log(start) * (1 - time / seconds) + ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; log(finish) * (time / seconds) ...&lt;br&gt;);&lt;br&gt;&lt;br&gt;phase = 0 * time;&lt;br&gt;phase(1) = initial_phase;&lt;br&gt;for i = 2:length(phase)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; phase(i) = ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod(phase(i - 1) + 2 * pi * frequency(i) / sample_rate, 2 * pi);&lt;br&gt;end&lt;br&gt;&lt;br&gt;signal = amplitude * sin(phase) + dc;&lt;br&gt;&lt;br&gt;end % sinesweep&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If anything, one would expect the first to be more accurate, since it is mathematically precise, and the second is only an approximation.&amp;nbsp; But let's see how the signal produced by each of them holds up.&lt;/p&gt;&lt;p&gt;I calculate, and plot, the same sweep both ways, with a slight dc offset to facilitate seeing the different sweeps on the same plot.&amp;nbsp; In particular this is a logarithmic sweep from 20 kHz to 21 kHz, over 30 seconds, using 44100 samples per second, an amplitude of 0.2, an initial phase of π, and a dc of 0.25 for one and 0.26 for the other:&lt;br&gt;&lt;/p&gt;&lt;p&gt;plot(...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x, sinesweep(20000, 21000, 30, 44100, 0.2, pi, 0.2&lt;b&gt;5&lt;/b&gt;), 'd', ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x, sinesweep_nostate(20000, 21000, 30, 44100, 0.2, pi, 0.2&lt;b&gt;6&lt;/b&gt;), 's' ...&lt;br&gt;)&lt;/p&gt;&lt;p&gt;(x is just 1:30*44100 - necessary to allow a single plot statement.)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Note that the approximate method is plotted in diamonds, and will be 0.01 &lt;i&gt;lower&lt;/i&gt; on the resulting graph than the "exact" method, plotted in squares.&lt;/p&gt;&lt;p&gt;(This takes a while to plot because there are a heckuva lot of points...)&lt;/p&gt;&lt;p&gt;Ah, a nice solid mass of green and blue.&amp;nbsp; I won't show it here.&lt;/p&gt;&lt;p&gt;OK, let's zoom in to a very early chunk of the signal - I expect these to match up closely, with only the dc offset separating the points:&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9860730/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9860730/original.aspx" height="391" width="473"&gt;&lt;/p&gt;&lt;p&gt;Yup.&amp;nbsp; Looks pretty good - give or take a pixel (quantization error in the display.)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Now let's see what happens to the signal towards the end of the 30 seconds.&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9860731/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9860731/original.aspx" height="389" width="470"&gt;&lt;/p&gt;&lt;p&gt;Ick.&amp;nbsp; Something's rotten in the state of Denmark.&amp;nbsp; This distortion is so bad that it's &lt;i&gt;visible&lt;/i&gt; - you don't even have to take an FFT to see it.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Exercise:&lt;/i&gt; take an FFT and look at the distortion.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Advanced Exercise:&lt;/i&gt; demonstrate that the distortion is, in fact, in the "exact" method and not in the iterative method... that is to say, show which clock is right.&lt;/p&gt;&lt;p&gt;EDIT: On second glance it looks like the second picture is just showing a horizontal shift between the two signals, which is expected.&amp;nbsp; I'll need to dig deeper if I'm to prove my assertion that the iterative method produces less distortion than the "exact" method. &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9860732" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Math" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Math/default.aspx" /><category term="Audio" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Audio/default.aspx" /></entry><entry><title>Bad Perl: locker problem</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/05/bad-perl-locker-problem.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/05/bad-perl-locker-problem.aspx</id><published>2009-08-05T19:16:00Z</published><updated>2009-08-05T19:16:00Z</updated><content type="html">
&lt;p&gt;&lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx"&gt;Bad Perl&lt;/a&gt; solution to the "&lt;a href="http://thedailywtf.com/Comments/Nerds,-Jocks,-and-Lockers.aspx" mce_href="http://thedailywtf.com/Comments/Nerds,-Jocks,-and-Lockers.aspx"&gt;print the open lockers&lt;/a&gt;" problem:&lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e"print join', ',map{$_*$_}1..sqrt pop" 100&lt;/p&gt;

&lt;p&gt;54 characters.&amp;nbsp; I prefer this to the 53-character solution obtained by omitting the space after the first comma.&lt;/p&gt;

&lt;p&gt;EDIT: 49 characters:&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e"print map{$_*$_,' '}1..sqrt pop" 100&lt;/p&gt;

&lt;p&gt;EDIT: 48:&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e"print map{$_*$_.$/}1..sqrt pop" 100&lt;/p&gt;

&lt;p&gt;EDIT: 47:&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e"map{print$/.$_*$_}1..sqrt pop" 100&lt;/p&gt;

&lt;p&gt;I still think "say" is cheating but it does afford this very short solution:&lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -E"map{say$_*$_}1..sqrt pop" 100&lt;/p&gt;

&lt;p&gt;EDIT: Apparently I need to learn how to count.  Counts above are off.  Anyway, 41:&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e"print$_*$_,$/for 1..sqrt pop" 100&lt;/p&gt;

&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9858182" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Perl" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Perl/default.aspx" /></entry><entry><title>How to calculate a sine sweep - the wrong way</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/03/how-to-calculate-a-sine-sweep-the-wrong-way.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/08/03/how-to-calculate-a-sine-sweep-the-wrong-way.aspx</id><published>2009-08-04T00:07:00Z</published><updated>2009-08-04T00:07:00Z</updated><content type="html">&lt;p&gt;Suppose you want to generate a continuous sine-sweep from time &lt;i&gt;t&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; to time &lt;i&gt;t&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;.  You want the starting frequency to be &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt;, and the ending frequency to be &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;; you want the sweep to be logarithmic, so that octaves are swept out in equal times.  (The alternative would be to sweep linearly, but usually logarithmic sweeping is what you want.)  For today we're going to have continuous time and sample values, so sample rate and bit depth will not be part of this discussion; in particular, the units of &lt;i&gt;t&lt;/i&gt; will be seconds, and our sample values will go from -1 to 1.

&lt;/p&gt;&lt;p&gt;Here's a picture of want we want to end up with:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856518/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856518/original.aspx" height="447" width="454"&gt;

&lt;/p&gt;&lt;p&gt;Without loss of generality, set &lt;i&gt;t&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; = 0.  This simplifies some of the math.
&lt;/p&gt;&lt;p&gt;Let &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) be the "instantaneous frequency" at time &lt;i&gt;t&lt;/i&gt;.  &lt;i&gt;Advanced Exercise:&lt;/i&gt; Define "instantaneous frequency" mathematically.
&lt;/p&gt;&lt;p&gt;Sweeping &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) logarithmically means that log &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) is swept &lt;i&gt;linearly&lt;/i&gt; from log &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; to log &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;.  So
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856509/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856509/original.aspx" height="332" width="457"&gt;
&lt;/p&gt;&lt;p&gt;Quick check: &lt;i&gt;ω&lt;/i&gt;(0) = &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt;, &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;) = &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;.  Yup.
&lt;/p&gt;&lt;p&gt;Let's define &lt;i&gt;R&lt;/i&gt; (the rate of change of the frequency) as (&lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt; / &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt;)&lt;sup&gt;1 / &lt;i&gt;t&lt;/i&gt;&lt;sub&gt;end&lt;/sub&gt;&lt;/sup&gt;.  This formula reduces to
&lt;/p&gt;&lt;p&gt;&lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; &lt;i&gt;R&lt;/i&gt;&lt;sup&gt;&lt;i&gt;t&lt;/i&gt;&lt;/sup&gt;
&lt;/p&gt;&lt;p&gt;Next step is to look at phase.  For a sine wave of &lt;i&gt;constant&lt;/i&gt; frequency &lt;i&gt;ω&lt;/i&gt;, phase progresses linearly with &lt;i&gt;t&lt;/i&gt; on the circular interval [0, 2π):&lt;br&gt;
&lt;i&gt;φ&lt;/i&gt; = &lt;i&gt;k&lt;/i&gt; &lt;i&gt;ω&lt;/i&gt; &lt;i&gt;t&lt;/i&gt;&lt;br&gt;
for some constant &lt;i&gt;k&lt;/i&gt;.  If the frequency of a sine wave was 1 cycle per second, the phase would go from 0 to 2π in a single second - this reveals that the correct value of &lt;i&gt;k&lt;/i&gt; is 2π:&lt;br&gt;
&lt;i&gt;φ&lt;/i&gt; = 2π &lt;i&gt;ω&lt;/i&gt; &lt;i&gt;t&lt;/i&gt;
&lt;/p&gt;&lt;p&gt;What happens with a variable frequency?  A little calculus provides the answer.  Consider a small change Δ&lt;i&gt;t&lt;/i&gt;, small enough so that &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) is almost constant over the interval:&lt;br&gt;
Δ&lt;i&gt;φ&lt;/i&gt; ≈ 2π &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) Δ&lt;i&gt;t&lt;/i&gt;&lt;br&gt;
because over that interval the sine sweep function is well approximated by a sine wave of &lt;i&gt;constant&lt;/i&gt; frequency &lt;i&gt;ω&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;).
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856519/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856519/original.aspx" height="447" width="454"&gt;
&lt;/p&gt;&lt;p&gt;Starting from an initial phase &lt;i&gt;φ&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt;, let Δ&lt;i&gt;t&lt;/i&gt; → 0, and:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856511/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856511/original.aspx" height="127" width="238"&gt;
&lt;/p&gt;&lt;p&gt;
Substitute:&lt;br&gt;
&lt;i&gt;u&lt;/i&gt; = &lt;i&gt;τ&lt;/i&gt; log &lt;i&gt;R&lt;/i&gt;&lt;br&gt;
&lt;i&gt;τ&lt;/i&gt; = &lt;i&gt;u&lt;/i&gt; / log &lt;i&gt;R&lt;/i&gt;&lt;br&gt;
&lt;i&gt;dτ&lt;/i&gt; = &lt;i&gt;du&lt;/i&gt; / log &lt;i&gt;R&lt;/i&gt;&lt;br&gt;
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856513/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856513/original.aspx" height="328" width="346"&gt;
&lt;/p&gt;&lt;p&gt;Define:&lt;br&gt;
&lt;i&gt;B&lt;/i&gt; = 2π &lt;i&gt;ω&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; / log &lt;i&gt;R&lt;/i&gt;&lt;br&gt;
&lt;i&gt;A&lt;/i&gt; = &lt;i&gt;φ&lt;/i&gt;&lt;sub&gt;start&lt;/sub&gt; - &lt;i&gt;B&lt;/i&gt;&lt;br&gt;
and we have:
&lt;/p&gt;&lt;p&gt;&lt;i&gt;φ&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = &lt;i&gt;A&lt;/i&gt; + &lt;i&gt;B&lt;/i&gt;&lt;i&gt;R&lt;/i&gt;&lt;sup&gt;&lt;i&gt;t&lt;/i&gt;&lt;/sup&gt;
&lt;/p&gt;&lt;p&gt;Just for fun, here's the explicit solution without intermediate values:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856514/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856514/original.aspx" height="133" width="495"&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Now, the payoff: the signal is just the sine of the phase, so our sine sweep is:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856515/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856515/original.aspx" height="38" width="335"&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;or, more explicitly:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856516/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9856516/original.aspx" height="178" width="581"&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Ah, beautiful mathematically.
&lt;/p&gt;&lt;p&gt;But useless practically.
&lt;/p&gt;&lt;p&gt;Why useless?
&lt;/p&gt;&lt;p&gt;Well, note that our equation for phase is an exponential.  That expression inside the sin(...) gets very big, very quickly.  &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/01/18/generating-a-sine-wave-with-phase.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/01/18/generating-a-sine-wave-with-phase.aspx"&gt;Any practical implementation of sin(...) is going to be utterly useless once its argument gets beyond a certain threshold&lt;/a&gt; - you'll get ugly chunky steps before you're halfway into the sweep.
&lt;/p&gt;&lt;p&gt;Nonetheless, there is a practical way to generate (pretty good) sine sweeps.  More on that next time.&lt;/p&gt;&lt;p&gt;EDIT: all logs are base &lt;i&gt;e&lt;/i&gt;. &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9856522" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Math" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Math/default.aspx" /><category term="Audio" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Audio/default.aspx" /></entry><entry><title>Bad Perl: Josephus problem</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/07/29/bad-perl-josephus-problem.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/07/29/bad-perl-josephus-problem.aspx</id><published>2009-07-29T20:14:00Z</published><updated>2009-07-29T20:14:00Z</updated><content type="html">
&lt;p&gt;&lt;a href="http://thedailywtf.com/Comments/Programming-Praxis-Josephus-Circle.aspx" mce_href="http://thedailywtf.com/Comments/Programming-Praxis-Josephus-Circle.aspx"&gt;Another programming contest&lt;/a&gt; asks to solve &lt;a href="http://en.wikipedia.org/wiki/Josephus_problem" mce_href="http://en.wikipedia.org/wiki/Josephus_problem"&gt;the Josephus problem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx"&gt;Bad Perl&lt;/a&gt; solution (83 characters... so close...)&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;&amp;gt;perl -e"&lt;b&gt;@_=(1..$ARGV[0]);++$c%$ARGV[1]?$i++:splice@_,$i%=@_,1while$#_;print@_&lt;/b&gt;" 40 3&lt;br&gt;28&lt;/p&gt;

&lt;p&gt;EDIT: got it down to 80.&lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;&amp;gt;perl -e"&lt;b&gt;@_=(1..shift);++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_&lt;/b&gt;" 40 3&lt;br&gt;28&lt;/p&gt;

&lt;p&gt;EDIT2: 78 dropping the parentheses. &lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;&amp;gt;perl -e"&lt;b&gt;@_=1..shift;++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_&lt;/b&gt;" 40 3&lt;br&gt;28&lt;/p&gt;

&lt;p&gt;EDIT3: 66, shamelessly cannibalizing others' ideas from the contest (though I refuse to use "say")&lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;&amp;gt;perl -e"&lt;b&gt;$k=pop;@_=1..pop;@_=grep{++$i%$k}@_ while$#_;print@_&lt;/b&gt;" 40 3&lt;br&gt;28 &lt;br&gt;&lt;/p&gt;

&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9852326" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Perl" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Perl/default.aspx" /></entry><entry><title>Bad Perl: Russian Peasant multiplication algorithm</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/07/23/bad-perl-russian-peasant-multiplication-algorithm.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/07/23/bad-perl-russian-peasant-multiplication-algorithm.aspx</id><published>2009-07-24T01:36:00Z</published><updated>2009-07-24T01:36:00Z</updated><content type="html">&lt;p&gt;I found &lt;a href="http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx" mce_href="http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx"&gt;this programming contest&lt;/a&gt; interesting: here's what I've got.&lt;br&gt;&lt;/p&gt;

&lt;p style="font-family: monospace;"&gt;perl -e "&lt;b&gt;($a,$b)=@ARGV;map{$c+=$_*$b}grep{$a&amp;amp;$_}map{1&amp;lt;&amp;lt;$_}(0..log($a)/log 2);print$c&lt;/b&gt;" 7 19&lt;/p&gt;

&lt;p&gt;I'm calling this a one-liner because the part between the quotes is less than 80 characters (75, to be exact.)&amp;nbsp; The full command line goes over :-(&lt;/p&gt;

&lt;p&gt;Requires the inputs to be positive whole numbers.&lt;/p&gt;

&lt;p&gt;Perfect example of &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2008/12/02/good-perl-bad-perl.aspx"&gt;Bad Perl&lt;/a&gt;.&amp;nbsp; Exercise: rewrite in Good Perl.&lt;/p&gt;
&lt;p&gt;EDIT: got the whole thing down to 80 characters (with single-digit multiplicands.) &lt;br&gt;&lt;/p&gt;
&lt;p style="font-family: monospace;"&gt;perl -e "&lt;b&gt;($a,$b)=@ARGV;map{$c+=$b&amp;lt;&amp;lt;$_ if$a&amp;gt;&amp;gt;$_&amp;amp;1}(0..log($a)/log 2);print$c&lt;/b&gt;" 8 7 &lt;br&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9846859" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Perl" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Perl/default.aspx" /></entry><entry><title>Bug - jack detection on Windows 7 hdaudio.sys mixed capture</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/06/22/bug-jack-detection-on-windows-7-hdaudio-sys-mixed-capture.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/06/22/bug-jack-detection-on-windows-7-hdaudio-sys-mixed-capture.aspx</id><published>2009-06-23T00:47:00Z</published><updated>2009-06-23T00:47:00Z</updated><content type="html">&lt;p&gt;There's a bug that got away from me in Windows 7's HD Audio class driver (hdaudio.sys.)&lt;/p&gt;

&lt;p&gt;Before I explain the bug, a few caveats:&lt;/p&gt;

&lt;p&gt;If you're using Vista, there's no problem.&amp;nbsp; This only affects Windows 7.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;If you use the third-party audio driver, there's no problem.&amp;nbsp; This only affects the Microsoft HD Audio class driver (hdaudio.sys.)&lt;/p&gt;

&lt;p&gt;If your recording devices (mic and line in) are independent (can capture from both at the same time) or muxed (can capture from one or the other but not from their sum) then you're fine; this only affects mixed capture (can capture from one, from the other, or from their sum, but not from both sides of the mix independently.)&lt;/p&gt;

&lt;p&gt;If either of your recording devices doesn't support jack presence detection then you're fine; this only affects mixed capture where both sides of the mix support jack presence detection.&lt;/p&gt;

&lt;p&gt;Here's the bug.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There are various ways to "reset" the system and bring the OS recording device state into synchronization with the hardware state&lt;/li&gt;

&lt;ul&gt;
&lt;li&gt;reboot&lt;/li&gt;

&lt;li&gt;reset the HD Audio controller&lt;/li&gt;

&lt;li&gt;reinstall the audio driver&lt;/li&gt;

&lt;li&gt;restart the AudioEndpointBuilder service&lt;/li&gt;

&lt;li&gt;unplug all recording devices in the mix&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;li&gt;The first state change (plug or unplug) after a reset works&lt;/li&gt;

&lt;li&gt;The second and further state changes are not recognized by the OS until a reset.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a sample state diagram assuming a mixed Mic and Line In (click to view full-size:)&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/photos/matthew_van_eerde/images/9798381/original.aspx" target="_blank" mce_href="http://blogs.msdn.com/photos/matthew_van_eerde/images/9798381/original.aspx"&gt; &lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9798381/640x464.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9798381/640x464.aspx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Workarounds:&lt;/p&gt;

&lt;p&gt;Install the third-party audio driver instead of the HD Audio class driver.&lt;/p&gt;

&lt;p&gt;Use audio extension cables to fool the jack presence detection hardware into thinking something is always plugged in. &lt;br&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9798386" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Audio" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Audio/default.aspx" /></entry><entry><title>Minimal unsatisfiable regular expression, XPath query</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/06/01/minimal-unsatisfiable-regular-expression-xpath-query.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/06/01/minimal-unsatisfiable-regular-expression-xpath-query.aspx</id><published>2009-06-01T21:08:00Z</published><updated>2009-06-01T21:08:00Z</updated><content type="html">&lt;p&gt;Regular expressions are a tool for matching generic text.&amp;nbsp; XPath queries are a tool for matching chunks of XML.&amp;nbsp; Both are search technologies.&lt;/p&gt;&lt;p&gt;When using search technologies it is occasionally quite useful to have a query that will never match anything - for SQL, this would be something like "SELECT 1 WHERE 1 = 0".&lt;/p&gt;&lt;p&gt;My candidates for minimal unsatisfiable regular expression:&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;/a\bc/&lt;br&gt;\&lt;b&gt;b&lt;/b&gt; is a zero-width assertion that matches a &lt;b&gt;b&lt;/b&gt;oundary at the beginning or end of a word - specifically, it is true between a word-ish character (\w) and a non-wordish character (\W).&amp;nbsp; Since literal "a" and "c" are both wordish characters, this will never match.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Or, if you allow Perl extensions:&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;/(?!)/&lt;br&gt;This is a negative lookahead for an empty string.&amp;nbsp; Since the empty string always matches everywhere, this will never match.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;My candidate for minimal unsatisfiable XPath query:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;/parent::*&lt;br&gt;This matches everything at or under the parent of the root element.&amp;nbsp; Since, by definition, the root element has no parent, this will never match.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9679669" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Win32" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Win32/default.aspx" /></entry><entry><title>Why square waves have ears: Gibbs' phenomenon (Wilbraham's phenomenon)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/05/07/why-square-waves-have-ears-gibbs-phenomenon-wilbraham-s-phenomenon.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/05/07/why-square-waves-have-ears-gibbs-phenomenon-wilbraham-s-phenomenon.aspx</id><published>2009-05-07T22:30:00Z</published><updated>2009-05-07T22:30:00Z</updated><content type="html">&lt;p&gt;In &lt;a href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/04/07/why-a-full-scale-sine-wave-has-an-intensity-of-3-db-fs.aspx" mce_href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/04/07/why-a-full-scale-sine-wave-has-an-intensity-of-3-db-fs.aspx"&gt;a recent post&lt;/a&gt; I sung the praises of square waves as a way to get a heckuva lot of power (3 dB more power than a sine wave) into a sample-range-limited signal.&amp;nbsp; It's time to take them down a notch now.&lt;/p&gt;

&lt;p&gt;A problem with square waves is they're impossible to generate in the analog domain.&amp;nbsp; In fact, you can't even get close.&lt;/p&gt;

&lt;p&gt;Signals generated in the analog domain are subject to physical laws regarding continuity (no teleportation) and whatnot. A common way to model these is to express (periodic) analog signals using a basis of sine waves with integral periods.&amp;nbsp; Suppose I want to generate the square wave:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td rowspan="3" style=""&gt;&lt;i&gt;f&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;) = &lt;/td&gt;

&lt;td&gt;1, -π &amp;lt; &lt;i&gt;x&lt;/i&gt; &amp;lt; 0&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;-1, 0 &amp;lt; &lt;i&gt;x&lt;/i&gt; &amp;lt; π&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Graphed below are some approximations of this function using sine waves as a basis.&amp;nbsp; Note that only odd values of &lt;i&gt;n&lt;/i&gt; are used in the sums of sin(&lt;i&gt;nx&lt;/i&gt;).&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9594637/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9594637/original.aspx" height="392" width="479"&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;The sums converge to +/-1 quite well, but there are definite "ears" at &lt;i&gt;x&lt;/i&gt; near 0 where there's overshoot.&amp;nbsp; This doesn't appear to die down.&amp;nbsp; A closeup of one of the "ears":&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9594787/original.aspx" mce_src="http://blogs.msdn.com/photos/matthew_van_eerde/images/9594787/original.aspx" height="382" width="475"&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;If anything, rather than dying down, the "ears" converge to max(&lt;i&gt;f&lt;sub&gt;n&lt;/sub&gt;&lt;/i&gt;) → about 1.18, or about 9% of the "jump" from -1 to 1.&amp;nbsp; (Dym and McKean, in their 1972 book &lt;a href="http://www.ams.org/mathscinet/search/publdoc.html?pg1=INDI&amp;amp;s1=61225&amp;amp;vfpref=html&amp;amp;r=109&amp;amp;mx-pid=442564" mce_href="http://www.ams.org/mathscinet/search/publdoc.html?pg1=INDI&amp;amp;s1=61225&amp;amp;vfpref=html&amp;amp;r=109&amp;amp;mx-pid=442564"&gt;Fourier Series and Integrals&lt;/a&gt;, get the 9% right but incorrectly assert that the convergence is to 1.09.)&lt;/p&gt;

&lt;p&gt;This mathematical phenomenon - &lt;a href="http://en.wikipedia.org/wiki/Gibbs_phenomenon" mce_href="http://en.wikipedia.org/wiki/Gibbs_phenomenon"&gt;Gibbs' phenomenon&lt;/a&gt; - is a good illustration of the difference between &lt;i&gt;convergence&lt;/i&gt; of a series of functions and &lt;i&gt;uniform convergence&lt;/i&gt;.&lt;/p&gt;

&lt;p&gt;In this case, the series of partial sums &lt;i&gt;pointwise converge&lt;/i&gt; to the square wave... for any given point &lt;i&gt;x&lt;/i&gt; &amp;gt; 0 and ε &amp;gt; 0, the ear will eventually move to the left, and I can choose an &lt;i&gt;N&lt;/i&gt; such that &lt;i&gt;f&lt;sub&gt;n&lt;/sub&gt;&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;) is within of ε of 1 for all &lt;i&gt;n&lt;/i&gt; &amp;gt; &lt;i&gt;N...&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;... but the series does not &lt;i&gt;uniformly&lt;/i&gt; converge to the square wave.&amp;nbsp; The following assertion is &lt;i&gt;false:&lt;/i&gt; "for any given ε &amp;gt; 0, I can pick an &lt;i&gt;N&lt;/i&gt; such that &lt;i&gt;f&lt;sub&gt;n&lt;/sub&gt;&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;) is within of ε of 1 for all &lt;i&gt;n&lt;/i&gt; &amp;gt; &lt;i&gt;N&lt;/i&gt; and all &lt;i&gt;x&lt;/i&gt; &amp;gt; 0."&amp;nbsp; This can be demonstrated by picking ε = 0.17, say.&amp;nbsp; For any &lt;i&gt;n&lt;/i&gt;, even, say, &lt;i&gt;n&lt;/i&gt; = 10&lt;sup&gt;100&lt;/sup&gt;, there is an &lt;i&gt;x&lt;/i&gt; close to 0 where &lt;i&gt;f&lt;/i&gt;&lt;sub&gt;1e100&lt;/sub&gt;(&lt;i&gt;x&lt;/i&gt;) &amp;gt; 1.17.
&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9594775" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Math" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Math/default.aspx" /><category term="Audio" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Audio/default.aspx" /></entry><entry><title>Daylight Saving Time and Benjamin Franklin</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/05/06/daylight-saving-time-and-benjamin-franklin.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/05/06/daylight-saving-time-and-benjamin-franklin.aspx</id><published>2009-05-06T19:15:00Z</published><updated>2009-05-06T19:15:00Z</updated><content type="html">&lt;p&gt;Daylight Saving Time is a thorn in my side.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Politician: What time is it?&lt;br&gt;Scientist: What time would you like it to be?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It is my firm belief that&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Daylight Saving Time doesn't do any real good.&lt;/li&gt;&lt;li&gt;Daylight Saving Time does real harm.&lt;/li&gt;&lt;li&gt;Politicians love Daylight Saving Time because it's easy and at least it &lt;i&gt;looks&lt;/i&gt; good.&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;One of the points that my congresswoman brought up is that Daylight Saving Time was originally proposed by a founding father of the US, and that therefore it must be a good idea.&amp;nbsp; (&lt;i&gt;Exercise:&lt;/i&gt; what logical fallacy is this?)&lt;br&gt;&lt;p&gt;Today I decided to actually look up the original proposal and found it quite enlightening. &lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.webexhibits.org/daylightsaving/franklin3.html" mce_href="http://www.webexhibits.org/daylightsaving/franklin3.html"&gt;Benjamin Franklin's 1784 letter to the &lt;i&gt;Journal de Paris&lt;/i&gt; (English translation)&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The full article is well worth reading, but this quote will illustrate my point:&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;I believe all who have common sense, as soon as they have learnt... that it is daylight when the sun rises, will contrive to rise with him; and, to compel the rest, I would propose the following regulations...&lt;/p&gt;&lt;p&gt;let a tax be laid... on every window that is provided with shutters...&lt;/p&gt;&lt;p&gt;[let] no family be permitted to be supplied with more than one pound of candles per week...&lt;/p&gt;&lt;p&gt;Let guards also be posted to stop all the coaches, &amp;amp;c. that would pass the streets after sunset...&lt;/p&gt;&lt;p&gt;Every morning, as soon as the sun rises, let all the bells in every church be set ringing; and if that is not sufficient?, let cannon be fired in every street, to wake the sluggards effectually, and make them open their eyes to see their true interest.&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Yes, Benjamin Franklin was the first to propose a law encouraging people to get up early.&lt;/p&gt;&lt;p&gt;But he was &lt;i&gt;joking&lt;/i&gt;. &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9591569" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author></entry><entry><title>Second cousins, cousins once removed; relationships by generations to common ancestor</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/matthew_van_eerde/archive/2009/04/27/second-cousins-cousins-once-removed-relationships-by-generations-to-common-ancestor.aspx" /><id>http://blogs.msdn.com/matthew_van_eerde/archive/2009/04/27/second-cousins-cousins-once-removed-relationships-by-generations-to-common-ancestor.aspx</id><published>2009-04-27T21:04:00Z</published><updated>2009-04-27T21:04:00Z</updated><content type="html">
&lt;p&gt;Raymond Chen explains some common terms for blood relatives of varying distance across cultures in his blog post "&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2009/04/27/9570320.aspx" mce_href="http://blogs.msdn.com/oldnewthing/archive/2009/04/27/9570320.aspx"&gt;What kind of uncle am I?&lt;/a&gt;" &lt;/p&gt;

&lt;p&gt;He links to &lt;a href="http://www.genealogy.com/16_cousn.html" mce_href="http://www.genealogy.com/16_cousn.html"&gt;a diagram on genealogy.com&lt;/a&gt; that I felt was lacking something... so here's my version, with consanguinary colors.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Red means "marriage is almost certainly legally prohibited."&lt;/p&gt;

&lt;p&gt;Yellow means "marriage may be legally prohibited - check your region's laws."&lt;/p&gt;

&lt;p&gt;Green means "marriage is amost certainly legal."&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;/p&gt;

&lt;table style="z-index: 1; background-color: white;" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="text-align: center; font-weight: bold;" colspan="8"&gt;Relationship by generations to common ancestor&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="font-weight: bold; text-align: center;"&gt;
	
&lt;td&gt;#&lt;/td&gt;
	
&lt;td&gt;0&lt;/td&gt;
	
&lt;td&gt;1&lt;/td&gt;
	
&lt;td&gt;2&lt;/td&gt;
	
&lt;td&gt;3&lt;/td&gt;
	
&lt;td&gt;4&lt;/td&gt;
	
&lt;td&gt;...&lt;/td&gt;
	
&lt;td&gt;&lt;i&gt;m&lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;0&lt;/td&gt;
	
&lt;td&gt;self&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;father/mother&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;grand&lt;br&gt;(father/mother)&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;great‑&lt;br&gt;grand&lt;br&gt;(father/mother)&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;(great‑)&lt;sup&gt;2&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(father/mother)&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;(great-)&lt;sup&gt;&lt;i&gt;m&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;2&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(father/mother)&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;1&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;son/daughter&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;brother/sister&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;aunt/uncle&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;grand&lt;br&gt;(aunt/uncle)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;great‑&lt;br&gt;grand&lt;br&gt;(aunt/uncle)&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;(great‑)&lt;sup&gt;&lt;i&gt;m&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;3&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(aunt/uncle)&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;2&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;grand&lt;br&gt;(son/daughter)&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;niece/nephew&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;(first) cousin&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;once removed&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;twice removed&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;(&lt;i&gt;m&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;2) times removed&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;3&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;great‑&lt;br&gt;grand&lt;br&gt;(son/daughter)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;grand&lt;br&gt;(niece/nephew)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;once removed&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;second cousin&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;second cousin,&lt;br&gt;once removed&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;second cousin,&lt;br&gt;(&lt;i&gt;m&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;3) times removed&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;4&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;(great‑)&lt;sup&gt;2&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(son/daughter)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;great-&lt;br&gt;grand&lt;br&gt;(niece/nephew)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;twice removed&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;second cousin,&lt;br&gt;once removed&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;third cousin&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;third cousin,&lt;br&gt;(&lt;i&gt;m&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;4) times removed&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;...&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="vertical-align: top;"&gt;
	
&lt;td style="font-weight: bold; text-align: center;"&gt;&lt;i&gt;n&lt;/i&gt;&lt;/td&gt;
	
&lt;td style="background-color: rgb(255, 204, 204);"&gt;(great‑)&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;2&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(son/daughter)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;(great‑)&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;3&lt;/sup&gt;&lt;br&gt;grand&lt;br&gt;(niece/nephew)&lt;/td&gt;
	
&lt;td style="background-color: yellow;"&gt;first cousin,&lt;br&gt;(&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;2) times removed&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;second cousin,&lt;br&gt;(&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;3) times removed&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;third cousin,&lt;br&gt;(&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;4) times removed&lt;/td&gt;
	
&lt;td&gt;&lt;br&gt;&lt;/td&gt;
	
&lt;td style="background-color: rgb(204, 255, 204);"&gt;(&lt;i&gt;n&lt;/i&gt; == &lt;i&gt;m&lt;/i&gt;) ?&lt;br&gt;
		((&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;1)th cousin) :&lt;br&gt;
		((min(&lt;i&gt;n&lt;/i&gt;, &lt;i&gt;m&lt;/i&gt;)&amp;nbsp;‑&amp;nbsp;1)th cousin, |&lt;i&gt;n&lt;/i&gt;&amp;nbsp;‑&amp;nbsp;&lt;i&gt;m&lt;/i&gt;| times removed)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9571659" width="1" height="1"&gt;</content><author><name>Maurits</name><uri>http://blogs.msdn.com/members/Maurits.aspx</uri></author><category term="Math" scheme="http://blogs.msdn.com/matthew_van_eerde/archive/tags/Math/default.aspx" /></entry></feed>