<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Signal and noise - Microscopy</title><link href="http://www.pmonta.com/" rel="alternate"/><link href="http://www.pmonta.com/feeds/microscopy.atom.xml" rel="self"/><id>http://www.pmonta.com/</id><updated>2023-01-14T02:30:00-05:00</updated><subtitle>Peter Monta's projects</subtitle><entry><title>Compact Disc microscopy, part 2</title><link href="http://www.pmonta.com/compact-disc-microscopy-part-2.html" rel="alternate"/><published>2023-01-14T02:30:00-05:00</published><updated>2023-01-14T02:30:00-05:00</updated><author><name>Peter Monta</name></author><id>tag:www.pmonta.com,2023-01-14:/compact-disc-microscopy-part-2.html</id><summary type="html">&lt;p&gt;See part 1 &lt;a class="reference external" href="compact-disc-microscopy.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In order to capture and decode more bits from the CD's surface, multiple images are needed.  Below are 125 images forming a short arc (roughly following the CD's tracks) stitched with &lt;a class="reference external" href="https://hugin.sourceforge.io/"&gt;Hugin&lt;/a&gt;.  (Other stitching tools include &lt;a class="reference external" href="https://github.com/usnistgov/MIST"&gt;MIST&lt;/a&gt; and &lt;a class="reference external" href="https://labsyspharm.github.io/ashlar/"&gt;Ashlar&lt;/a&gt;, though MIST assumes a regular grid structure …&lt;/p&gt;</summary><content type="html">&lt;p&gt;See part 1 &lt;a class="reference external" href="compact-disc-microscopy.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In order to capture and decode more bits from the CD's surface, multiple images are needed.  Below are 125 images forming a short arc (roughly following the CD's tracks) stitched with &lt;a class="reference external" href="https://hugin.sourceforge.io/"&gt;Hugin&lt;/a&gt;.  (Other stitching tools include &lt;a class="reference external" href="https://github.com/usnistgov/MIST"&gt;MIST&lt;/a&gt; and &lt;a class="reference external" href="https://labsyspharm.github.io/ashlar/"&gt;Ashlar&lt;/a&gt;, though MIST assumes a regular grid structure, so it's not suitable for this case.)  The images are spaced by 60 microns, about 40% of the microscope objective's usable field of view.  The positioning is not perfectly regular due to the limited precision of the stage.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2023/01/cd-stitched-diagram.jpg"&gt;&lt;img alt="cd-stitched-diagram" src="http://www.pmonta.com/uploads/2023/01/cd-stitched-diagram.jpg" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here's a zoomable image.  The original image and the associated processing code are linked below.&lt;/p&gt;
&lt;p&gt;
&lt;div id="map"&gt;&lt;/div&gt;
&lt;/p&gt;&lt;p&gt;The stitching does quite well, achieving about 0.02 pixels RMS of mismatch between corresponding features in overlapping images.  (Hugin works with discrete features rather than image cross-correlation.)  This is low enough to not induce significant jitter in the bit clock across the image boundaries.&lt;/p&gt;
&lt;p&gt;Once we have the complete image, we can extract a single track for demodulation.  As it happens, sampling along a circle is sufficiently accurate (the circle's center and radius were arrived at by trial and error).  For larger images, an adaptive tracking scheme will be needed to stay on track, but that's a refinement for another day.  This would be analogous to the track servo used in an actual CD player.  (The other servo, for focus, is already handled by the microscope's image-acquisition script.)&lt;/p&gt;
&lt;p&gt;To acquire and maintain bit sync, the image below is useful.  It consists of the track waveform sliced into individual 588-bit frames, then stacked row-by-row into a waterfall plot.  The 24-bit frame-sync word, 111111111110000000000011 (or its inverse), is clearly apparent.  Any clock error is visible as drift in the bit transitions.  In this case, as a quick hack, I assembled a quadratic-spline approximation to the drift by picking a few points by hand in an image editor, then folding this correction into the resampling.  Again, for a longer capture, adaptive clock recovery would be needed.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2023/01/cd-frame-waterfall.jpg"&gt;&lt;img alt="cd-frame-waterfall" src="http://www.pmonta.com/uploads/2023/01/cd-frame-waterfall.jpg" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So finally we have about 40 frames, or 20000 channel bits, and this time we have sufficiently many bits to acquire frame sync and decode the inner RS code.  (Unfortunately the outer RS code is separated from the inner by about 100 frames of interleaving, so we still can't quite get to final decoded audio samples.)&lt;/p&gt;
&lt;p&gt;Below is the sequence of 40 frames in hexadecimal.  The first column is the control/data byte (and indeed the pair of sync EFM symbols, S0 and S1, can be seen, although S0 is corrupted with a channel defect), and the other column groups are as follows:  12 bytes of audio, 4 bytes of outer RS parity, 12 more bytes of audio, and 4 bytes of inner RS parity.  The red splotches show erasures from invalid EFM codewords.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2023/01/cd-frame-data.png"&gt;&lt;img alt="cd-frame-data" src="http://www.pmonta.com/uploads/2023/01/cd-frame-data.png" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After decoding the inner RS code (called the C1 code in the specification), the first few codewords are:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
01 a7 fc 8b f9 f2 ff 9c 05 3f fe 4c     b0 77 d7 e7     ff ae fb c6 03 62 03 db fb c8 04 ff     39 0d bc 53
fe a1 fe b9 fc c1 00 be 01 ea 03 d3     67 7d 2f 56     01 78 f6 67 01 91 03 41 fa 7c 09 93     98 c4 16 af
ff 4b 00 a1 fd 45 00 db 00 03 05 c7     81 10 c2 4e     01 64 f8 f8 02 4f 02 f8 f9 ff 05 67     75 88 49 a8
00 b8 02 95 fe c3 fe 28 ff b6 02 f9     8e 9e 3c af     01 61 f9 4b ff 26 05 6c f6 4f 03 8f     09 d5 1a 64
fa f1 04 d2 fd f5 fc f2 fd 4f 04 47     07 a7 db 9f     02 48 f5 30 ff 0f 02 65 f4 3e 03 93     b2 09 f0 c7
fb 06 03 15 fd 43 ff c5 fe 59 05 af     57 85 8d b1     06 8a f6 bd fc 17 ff 23 f9 b1 04 46     77 9b 66 fc
fc 6f 03 58 fb a8 02 cc ff ac 04 51     a3 8d b9 3a     06 e5 fa df fc ca 00 37 ff 2c fe 83     70 0d 1e f4
fc 27 04 c7 fc 7f fe c7 00 8e 06 85     4b 0a 8b 65     03 cd fc 04 fa 10 03 e4 00 76 fa 74     0d dc a6 b4
fb 55 00 fb fd 7a f8 94 ff d6 04 80     a7 10 b5 86     00 cb fe da f9 81 00 bc 04 4e fb 50     76 11 f9 c3
fa 52 fd cc fe 3b f9 34 01 e9 01 04     b6 5b eb 93     ff a2 02 a2 f7 4b 01 2b 02 1c f9 73     c6 43 37 a4
&lt;/pre&gt;
&lt;p&gt;Code for all this can be found in my &lt;a class="reference external" href="https://github.com/pmonta/CD-decoder"&gt;github repository&lt;/a&gt;.  The repository's Makefile downloads the full stitched image and runs the processing pipeline.  The full stitched image is also available here: &lt;a class="reference external" href="http://www.pmonta.com/data/cd/cd-stitched.png"&gt;cd-stitched.png&lt;/a&gt; (42k by 12k pixels, 36 MB).&lt;/p&gt;
&lt;p&gt;The next step (sigh) is to go all the way around the disc.  This will allow a long, continuous spiral to be extracted, and we can finally hear some audio.&lt;/p&gt;
</content><category term="Microscopy"/></entry><entry><title>Compact Disc microscopy</title><link href="http://www.pmonta.com/compact-disc-microscopy.html" rel="alternate"/><published>2022-12-22T11:48:00-05:00</published><updated>2022-12-22T11:48:00-05:00</updated><author><name>Peter Monta</name></author><id>tag:www.pmonta.com,2022-12-22:/compact-disc-microscopy.html</id><summary type="html">&lt;p&gt;While refining my CNC microscope setup, I thought I'd have a look at some CD surfaces.  Unfortunately CDs are not especially useful as calibration artifacts, since the track pitch and channel-bit length can be varied over ~15% ranges and still be in spec (manufacturers played with these parameters to pack …&lt;/p&gt;</summary><content type="html">&lt;p&gt;While refining my CNC microscope setup, I thought I'd have a look at some CD surfaces.  Unfortunately CDs are not especially useful as calibration artifacts, since the track pitch and channel-bit length can be varied over ~15% ranges and still be in spec (manufacturers played with these parameters to pack more audio onto the disc).  Still, it got me interested in the possibility of reading the data using these optical images.&lt;/p&gt;
&lt;p&gt;The image below was taken with a Nikon 20x M Plan objective (NA=0.4, 210/0, LWD), a Logitech C270 webcam, and a 3D-printed epi illuminator with microscope-slide beamsplitter, all attached to the carriage of a Lulzbot Taz 4 3D printer:&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2022/12/cd-raw.jpg"&gt;&lt;img alt="image-raw" src="http://www.pmonta.com/uploads/2022/12/cd-raw.jpg" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some spherical aberration is present.  In fact it's a great deal worse if you image through the polycarbonate---a 1.2 mm slab of n=1.55 material is enough to seriously blur the image at this NA.  I'd like to find some sort of SA compensator that I could hang on the end of the objective (there is plenty of working distance, ~5 mm). Perhaps just a (spherical) achromat would suffice---I don't want to pay $400 for an Edmund Optics &lt;a class="reference external" href="https://www.edmundoptics.com/f/spherical-aberration-compensation-plates/14001/"&gt;asphere plate&lt;/a&gt;.  This image is taken from the CD's label side, and there's still ~0.1 mm of polymer acting as a &amp;quot;cover slip&amp;quot;.  The objective is optimized for an air medium and no cover slip, so this is still suboptimal.&lt;/p&gt;
&lt;p&gt;Anyway, here's a section through the image plotted as a waveform.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2022/12/cd-track.jpg"&gt;&lt;img alt="image-track" src="http://www.pmonta.com/uploads/2022/12/cd-track.jpg" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2022/12/cd-waveform.png"&gt;&lt;img alt="waveform-plot" src="http://www.pmonta.com/uploads/2022/12/cd-waveform.png" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external image-reference" href="http://www.pmonta.com/uploads/2022/12/cd-eye-diagram.png"&gt;&lt;img alt="eye-diagram" src="http://www.pmonta.com/uploads/2022/12/cd-eye-diagram.png" style="width: 100%;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The eye is open, so slicing detects the following symbols:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
0001111100001111100011110001111000001111111000000011000000111111
1100000111000001110000000011111111110000011111110000011110000011
1111110000011110001111000011111000001110000011110000111110000111
0001110001110001110000011111000001111000111000001111100011111100
0001111110000000001110000011100001111000000111111110001110001111
0000011100011100011111110000011110000001110000111111111000011111
0000000001111111000000111100001111000001110000011111111100001110
000011110011110000011100011100001111000000
&lt;/pre&gt;
&lt;p&gt;Decoding the NRZI line code (transition is a &amp;quot;1&amp;quot;, no transition is a &amp;quot;0&amp;quot;), the channel bits are:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
0010000100010000100100010010001000010000001000000101000001000000
0100001001000010010000000100000000010000100000010000100010000100
0000010000100010010001000100001000010010000100010001000010001001
0010010010010010010000100001000010001001001000010000100100000100
0010000010000000010010000100100010001000001000000010010010010001
0000100100100100100000010000100010000010010001000000001000100001
0000000010000001000001000100010001000010010000100000000100010010
00010001010001000010010010010001000100000
&lt;/pre&gt;
&lt;p&gt;No frame-sync pattern in this short segment (in either direction).  I'll have to take several images and stitch them.&lt;/p&gt;
&lt;p&gt;A specification for the CD physical format, channel coding, ECC, framing, and metadata is available here:&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://archive.org/details/RedBookAudioRecordingCompactDiscDigitalAudioSystemIEC60908SecondEdition199902ISBN2831846382"&gt;https://archive.org/details/RedBookAudioRecordingCompactDiscDigitalAudioSystemIEC60908SecondEdition199902ISBN2831846382&lt;/a&gt;&lt;/p&gt;
</content><category term="Microscopy"/></entry></feed>