Archive for the ‘Register’ Category

Finding the area under a curve with a spreadsheet program (Excel, Libreoffice Calc) or QtiPlot

Tuesday, October 28th, 2014

For performing elemental analysis by x-ray photoelectron spectroscopy, I needed to integrate and find the area under the peaks in some spectra. One approach is to fit each peak with a Gaussian function and use the area of the Gaussian. For some convoluted peaks, I wanted something simpler. I wanted to get the total area under each peak without fitting it in any way.

I use QtiPlot almost exclusively for plotting and fitting (fityk is my other go-to program) and one of the menu options for plots is Analysis->Integrate. That option brings up a tiny dialog where you can select the curve and range over which to integrate.

Screenshot - 10282014 - 09:13:32 PM

In the results log, an area is printed for the integrated curve. I wasn’t sure what QtiPlot was doing so I did an experiment with a simple set of data. I now know conclusively the algorithm used by QtiPlot and am able to replicate it in a spreadsheet program. I use LibreOffice Calc, but the instructions here should work in Excel as well.

Given a set of n points, P1 through Pn, a curve is generated by connecting each point with straight lines.qtiplot-integration-plot1

The area under the curve between two points, (x1, y1) and (x2, y2), is a trapezoid with area A = 1/2 |x1 – x2| (y1 + y2).qtiplot-integration-plot2

To find the area under the curve defined by a set of points, QtiPlot iterates through the points from P0 to Pn-1. For each point Pi, it calculates the area using Pi as (x1, y1) and Pi+1 as (x2, y2) and sums all of the trapezoid areas.

The above process is easy to replicate in LibreOffice Calc (or Excel) with the x,y data that define the curve. Assuming the x coordinates are in column A starting at row 1 and the y coordinates are in column B starting row 1, the areas of the individual trapezoids can be generated in column C. The formula in the first row is: “=0.5*abs(A1-A2)*(B1+B2)”. That formula is then copied down column C in all of the rows but the last. Finally, the areas are summed to give the total area under the curve.

Screenshot - 10282014 - 09:48:15 PM

Will that motorcycle pay for itself really?

Friday, October 10th, 2014

In deciding whether or not purchasing a motorcycle is a prudent decision, cost plays a significant factor. Motorcycles often get much higher gas mileage (fuel efficiency) than cars. A common belief is that because of this fact, a motorcycle might pay for itself. I wanted to believe this is true, but after running the numbers, this belief is a myth and is only true in extreme circumstances. I’m recording the relevant equations here so that next time I get the impulse to by a motorcycle, I won’t use cost savings as a justification.

In my situation, my everyday car, the Edscort, gets about 34 mpg highway, 30 mpg city. I don’t think I’ve ever seen less than 30 mpg so I’m going to use that figure as the Edscort’s fuel efficiency. The motorcycles in which I’ve been interested have been around $1500 in cost and achieve about 60 mpg. For simplicity’s sake, I will ignore the cost of insurance, maintenance, and accessories.

The cost, c, to drive a vehicle m miles is given by:

eqn1

where f is the fuel efficiency of the vehicle in mpg and r is the cost of gasoline in $/gal. The cost savings Δc is the difference in the cost of driving those miles with the motorcycle (bike) vs. the Edscort (car). A negative value for Δc corresponds to money saved.

eqn2

In order for the motorcycle to pay for itself, the cost savings must be at least as much as the purchase price of said motorcycle, P. That is, -Δc = P, where the negative sign makes a negative cost differential equal to a positive purchase price. The number of miles that must be driven before the bike pays for itself is therefore:

eqn3

In my case, where the Edscort gets 30 mpg, the motorcycle gets 60 mpg, gas is $3/gal (as of this writing, it’s $2.99/gal down the road) and the motorcycle purchase price is $1500, I would need to drive the motorcycle 30,000 miles to break even. And note, these trips on the motorcycle must be in place of rides in the Edscort, not in addition to my usual driving.

To point out how impractical this is, consider that I’m currently averaging about 10,000 miles per year driven. If I can substitute the motorcycle for 20% of those miles, I’ll put 2,000 miles on the bike per year and it will pay for itself in only 15 years. I could cut that to 6 years if I substitute the bike for 1/2 of my normal driving. Ideally, I’d want the bike to pay for itself in 2 or 3 years, but that’s obviously not going to happen.

New bikes are considerably more expensive and I’ve not considered other ownership costs in which case things get even worse. Of course, reducing the wear and tear on the Edscort might stave off a significant repair bill, but there’s no guarantee that’s the case. Nor is there a guarantee that the bike won’t need a major repair itself.

The bottom line is that cost savings cannot be used to justify the purchase of a motorcycle. The decision to buy one is not a practical decision. Face it.

How to align the red-green-blue (RGB) LCD panels (adjust convergence) of a Sharp XG-P10XU Projector

Thursday, July 17th, 2014

Projectors based on 3LCD technology work by splitting the white light from the lamp into 3 beams colored red, green, and blue, passing each beam through one of three LCD panels, combining the 3 beams back into one through a prism, and finally focusing the combined beam onto a wall or screen. In this process, the positions of the three individual LCD panels must be carefully controlled to ensure proper convergence. If a panel becomes misaligned, the corresponding color will be offset from the other colors in the image a condition known as misconvergence.

Small misalignments by a pixel or less are usually tolerable when displaying videos and motion pictures. When text is displayed however, even a misalignment of only one pixel can lead to blurry text that is hard to read. The problem is worst for small fonts whose characters may only be one to two pixels wide.

To fix the problem the convergence must be adjusted by realigning the LCD panels. Advanced projectors offer this option through the projector’s software interface but cheaper models lack any control over convergence. The Sharp NoteVision XG-P10XU is one such projector. The convergence is set at the factory and the unit sealed so that the user is forced to accept any misalignment in the purchased unit or that may develop over time. This post shows how to adjust the convergence of the Sharp NoteVision XG-P10XU 3 LCD projector by opening the case and accessing the optical bench inside. The process should be analogous for any 3LCD based projector.

The first step is to remove the external screws and top cover.  There are 15 screws total to remove and all can be removed with a philips screw driver. The screw positions are:

  • 2 screws on the left side of the unit
  • 2 screws on the right side of the unit
  • 1 screw on the front below the lens (secures the lens collar)
  • 6 large screws around the perimeter of the back side
  • 4 small screws on the back among all of the ports and connectors

projector left view projector lens collar screw projector rear view projector right view

 

The back cover should come off easily now. The blue lens collar on the front should be pulled off. It has small plastic tabs holding it in place. A knife can be used to pry the collar off.

projector rear cover off projector removing lens collar

Only after the back panel and lens collar are removed can the top cover by taken off. Once again, small plastic tabs make this slightly challenging but a knife inserted in the crevice between the top and bottom covers and bent up and down works well to separate the two. At the front two corners are small plastic pieces that will fall away. Be careful not to lose them down inside the projector. The top cover can only be pulled a few inches up from the unit because there are wires running to the speakers mounted on the cover as well as a ribbon cable running to the control panel. It is only necessary to unplug the speaker wires from the projector. Set the top cover off to the side a bit with the ribbon cable still attached. Later you will operate the projector in this state and it will be necessary to use the control panel.

projector opening case front projector opening case rear  projector under lid

That completes disassembly. You should now have access to the optical bench in the center of projector just behind the lens. You will see three ribbon cables that lead to each of the three LCD panels. The panels are mounted vertically and are hard to see clearly buried beneath all of the circuit boards. The square area between them holds the prism that recombines the beams and reflects them into the lens.

projector open not running

When standing at the rear of the projector so that it is pointed away from you, the left most panel is for the blue component, the center panel is green, and the right panel is red. If you look closely on the circuit boards near the ribbon cables that run to the panels will be the codes BP, GP, and RP for blue panel, green panel, and red panel, respectively. If you are attempting to adjust the panels on a different model and aren’t sure which is which, do not fret. Once the projector is turned on it will be obvious which panel is which.

WARNING! There are serious risks to operating the projector with the cover off. You are exposing yourself to dangerous voltages. DO NOT TOUCH ANY OF THE EXPOSED CIRCUITS OR WIRES. For maximum safety, wear latex or nitrile gloves. Be extremely careful not to short any of the circuits on the exposed PCB’s. Do not drop screws or metal tools onto the boards or into the unit. Try to have only one tool in your hand at a time and grasp it securely. Watch out for the cooling fans. Don’t stick anything in them, especially not your fingers. If you proceed to any of the following steps you do so at your own risk. I am not liable if you hurt yourself, the projector, or your surroundings.

To adjust the panels it will be necessary to operate the projector with the cover off. Plug in a video source and the unit’s power cable. Turn the projector on and focus it onto a white wall or screen in a dimly lit or dark room. It’s best. to connect a computer and have open a graphics-editing application. To gauge the alignment, I recommend long horizontal and vertical bars drawn in white on a black background. Make sure the bars are not anti-aliased. The pencil tools in MS Paint and GIMP work well for this. You may find that inverting the colors helps as well, especially to gauge the alignment of the blue panel. Test patterns can also be found online and displayed.

projector open and running

Inspect the displayed image and try to determine which colors are misaligned. The green panel in this projector is fixed as in most 3LCD projectors. You will be adjusting the red and blue. In the case of red and for the white line drawn on black, along the outer edge of the white line look for red pixels. If the panel is too far to the right, the outer right edge will be lined with red pixels and consequently the inner left edge will be lined with bluish-green pixels. For blue you’re looking for extra light blue pixels on the outer edge and yellow pixels on the inner edge.

Choose a panel to adjust first. You must loosen the retaining (locking) screws of the panel so that it can be adjusted. In this model, these are the two small black hex screws that run horizontally. Do not remove them, just loosen them a bit. You will need a hex wrench here. Now the panel can be adjusted by turning the hex bolts near the top of the panel. There is a bolt for vertical and a bolt for horizontal position. Some units will have screws instead of hex bolts and some may have a tilt adjustment as well. A pair of pliers may be needed to turn the adjustment bolts.

projector adjustment knobs locations

Adjustments should be in small increments. If you make a large adjustment, the beams will become severely misaligned. This might be a good way to determine which adjustment bolt moves what direction. Keep adjusting the bolts until you can no longer see extra colored pixels offset from the white bars (or black if on a white background). Go slowly and be patient. Sometimes, the best you can do is about +/- 1/2 pixel. When you feel satisfied with the adjustment, re-tighten the retaining screws (hex screws). Make sure they’re tight enough that bumps and heat won’t displace the panels again.

projector adjusting convergence

Repeat for the other panel and you’re finished. Turn off and unplug the projector. Then reverse the disassembly steps to replace the top cover, back cover, and lens collar. Don’t forget to plug the speakers back in. I recommend to tape the front plastic corner pieces in place until the unit is fully reassembled. Here’s hoping all went well.

 projector replacing cover taping corners

Numbers one can call to test phone reception quality

Wednesday, June 25th, 2014

I’ve recently cut one of my phone lines from AT&T and transferred it to Republic Wireless. The phone is configured to make calls and send messages over wifi and use the Sprint network (Verizon roaming) when no wifi is available. $10/month buys me unlimited everything on wifi and unlimited voice and text on cellular (no cellular data). So far, I’ve been pleased with the service (once I figured out how to white-list wifi networks).

Enough of the shameless promoting. When I received my new phone and service, I naturally wanted to test the reception quality of both the voip calls and cellular calls as well as the phone’s ability to switch seamlessly between the wifi and cellular networks. But who to call?

What I needed was somewhere I could call and listen to hold music or something similar. Actually, in those first days I called my cable company and let them put me on hold for a long time. I had to hang up before someone answered, of course. The solution that I’ve since found is provided by a service called AudioNow.

AudioNow broadcasts different audio feeds directly to certain telephone numbers. Usually these are amateurish radio stations. One can call the number and listen to the broadcast on their cell phone for as long as they’d like, from what I can tell. This is a great way to test your cellular or voip reception without having to harass your cable company.

The AudioNow website (http://www.audionow.com/featured-access-numbers/?lang=en) has a list of a few featured numbers (VOA, UN, CSPAN, BBC, etc.) and a google search of AudioNow will turn up more. The AudioNow twitter feed (https://twitter.com/AudioNowUS) also lists new additions to its customers. For example, here are numbers one can call to listen to the BBC:

World 712.432.5335
Somali 712.432.2888
Arabic 712.432.7877

The above numbers have an Iowa area code and as far as I can see, all of the 10 digit numbers are US based, so if you’re in the US, they shouldn’t cost you as international calls. For persons outside of the US, the AudioNow service operates numbers in other countries as well, though I haven’t found or tested any.

 

Update apt public keys in Debian to fix package authentication errors

Thursday, May 29th, 2014

The apt program for Debian uses public and private keys to validate packages downloaded from the repositories. You can learn all about it at https://wiki.debian.org/SecureApt. Public keys are stored in /etc/apt/trusted.gpg. If keys are missing, outdated, corrupted, etc. apt will complain when trying to install packages with an error like “The following signatures couldn’t be verified because the public key is not available”. You can choose to ignore the error. If so, when it reoccurs in the future you will see warnings like “WARNING: The following packages cannot be authenticated!”.

The solution to this problem is to update your public keys for the Debian repositories. These keys are installed via the package debian-archive-keyring. A simple “apt-get install debian-archive-keyring” is probably enough to update the keys are remove the errors/warnings during package installs.

Accessing status and diagnostic information for a Motorola Surfboard cable modem

Wednesday, May 28th, 2014

My ISP (to protect its identity, let’s call it Flomflast) drops my internet connection frequently. During the latest occurrence, I noticed from my router’s status page that the WAN address had been assigned to 192.168.100.11. I was surprised to see this since I believed there was no connection to the ISP via the cable line. How could the ISP DHCP server assigned an ip address to the router? And why the private network address?

I guessed that if the DHCP server was assigning addresses in the 192.168.100.x range then itself or another server (the gateway?) might be located at 192.168.100.1. I typed the address in the address bar of my favorite web browser and was greeted with a web page being served by my Motorola Surfboard cable modem.

Screenshot - 05282014 - 11:14:33 PM

On the configuration page I found information that the cable modem has a built-in DHCP server that takes over when the internet connection is dropped. As configured, it begins assigning addresses at 192.168.100.11. Since my router is the only device on that side of the network with the cable modem, it was assigned the first ip address in the range.

The status page for the cable modem is especially handy. From the comfort of my chair I can see that the internet connection is indeed lost without the usual process of several rounds of pinging followed by a walk to another room to check the modem lights. Even with the internet connected, the modem is still accessible at 192.168.100.1.

auth.log errors: pam_winbind.so missing

Thursday, May 1st, 2014

I had an authorization log (/var/lib/auth.log) was filling up with errors related to a missing pam_winbind.so library:

May  1 01:25:01 servername CRON[1906]: pam_unix(cron:session): session opened for user root by (uid=0)
May  1 01:25:01 servername CRON[1906]: pam_unix(cron:session): session closed for user root
May  1 01:25:16 servername auth: PAM unable to dlopen(/lib/security/pam_winbind.so): /lib/security/pam_winbind.so: cannot open shared object file: No such file or directory
May  1 01:25:16 servername auth: PAM adding faulty module: /lib/security/pam_winbind.so

…over and over. I tried upgrading winbind to the latest version in the Debian stable repositories. I installed libpam-winbind (2:3.6.6-6+deb7u3 for both). Neither of those actions fixed the problem. The library, pam_winbind.so, was not present in /lib/security.

After reading this thread:

https://lists.debian.org/debian-user/2012/07/msg00620.html

I found that the library was simply in the wrong location. It was the only file under /lib/powerpc-linux-gnu/security/. This machine is a powerpc. Other architectures will have a different architecture name in the /lib directory.

The simple solution was to make a symlink under at /lib/security/pam_winbind.so that points to the existing library at /lib/powerpc-linux-gnu/security/pam_winbind.so:

sudo ln -s /lib/powerpc-linux-gnu/security/pam_winbind.so /lib/security/pam_winbind.so

No more errors in the auth.log.

How libxi broke my system

Thursday, April 3rd, 2014

After some package updates I could no longer log into my Debian/XFCE system. The display manager (gdm3) would start to load but show only a black screen and rotating/spinning cursor. There was no login box – no way for me to get to a desktop. Digging through the logs I saw no errors in Xorg.0.log.  Dmesg and the kernel logs were no help either.  My first clue was found in the /var/log/gdm3/:0-greeter.log.* logs. Each of these logs had just one line:

*** Error in `/usr/bin/gnome-session’: malloc(): memory corruption: 0x000000000207c620 ***

A memtest run showed no errors. Reinstalling gnome-session didn’t fix things. Looking at ~/.xsession-errors I found lots of Gtk and GLib errors among strange things like “Discarding: 6 over 9″ and “** Message: applet now removed from the notification area”. Other errors that might have been related:

polkit-gnome-authentication-agent-1: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
wicd-client.py: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

orage: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
nm-applet: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

In some log (which I’ve forgotten now) I remember finding more “memory corruption” errors but for applications like nm_applet. I tried switching my display manager to lightdm but I got a similar result. Upon boot, I was greeted with a solid black screen. Logs showed that the x-session was started and the greeter as well. In /var/log/lightdm/x-0-greeter.log I found a familiar error:

*** Error in `/usr/sbin/lightdm-gtk-greeter’: malloc(): memory corruption: 0x00007fe0cd2bcd40 ***

I tried purging and resinstalling the x server but of course, it was working fine. From a console I was able to stop the display manager and invoke an x-session manually with “startx”. In the desktop environment, I noticed my wireless was not connecting automatically and the network manager (nm_applet) and orage icons were missing from by status tray.

I’d like to say I used these clues to determine that the problem was isolated to gtk apps (e.g. lightdm, gdm3, nm_applet, etc.) but I never noticed the connection. I was simply fortunate to stumble upon the solution in this post, courtesy of one dE_logics:

http://forums.gentoo.org/viewtopic-p-6873138.html

While the root cause isn’t described in detail, the simple statement at the end of the post provides the solution: “This’s a bug with libxi. Upgrading it…solves the problem.” I gave it a shot. I found libxi6 in synaptic and upgraded it to the highest version available in Debian’s stable repository. After a reboot, my display managers are working perfectly. My libxi6 version is now 2:1.6.1-1+deb7 according to synaptic.

Managing an iPod Shuffle (2nd gen.) in Linux

Monday, March 31st, 2014

I have an old second generation iPod Shuffle (model A1204). When I dug it out of storage it wouldn’t play any songs. I plugged it in to my mobile desktop running Debian and verified the file system could still be read. I transferred all of the existing songs off of the shuffle using Thunar and its handy renaming feature. In order to manage the tracks (i.e. add and remove songs) I needed a piece of Linux software with that capability. Unfortunately, the popular options, Banshee, Rhythmbox, and Amarok would all require that I update a significant amount of my system (mostly gnome and everything that depends on it). The best lite application I could find was gtkPod.

I first tried adding and removing tracks with gtkPod but kept getting errors. The process for adding songs was not straightforward and I couldn’t figure out how to fix those errors. Even when I got songs transferred to the device, it refused to play. It would only flash alternating green and orange indicating it couldn’t find any music. The database file wasn’t being written properly. So, gtkPod alone would not suffice (I may have an unsupported model, I couldn’t find it in the list of devices).

The solution relies on a python script “iPod shuffle database builder” which can be found on sourceforge. I used version 1.0-rc1. My process for adding tunes to the shuffle is now this (starting from scratch):

  1. Use file manager (Thunar) to permanently delete all files from the shuffle.
  2. Open gtkPod and use it to recreate the iPod Shuffle directories only.
  3. Use file manager to copy songs from desktop to Shuffle. Songs are stored in device root or under any arbitrary file hierarchy, just not in the normal /iPod_control/Music directory that iTunes uses.
  4. The python script mentioned above, named “rebuild_db.py” is copied to the root folder of the device.
  5. The python script is executed from the root folder of the device.

That’s it. Once the script rebuilds the Shuffle’s database it can be ejected and used as normal. Easy. Apple take notice.

How to change “about:home” to anything in Firefox (Icecat, Iceweasel)

Thursday, March 20th, 2014

Before reading, please note that I’ve written this post with respect to Icecat 17.0.1 which is a rebranded version of Firefox. I can’t guarantee that things will work the same with Firefox or Iceweasel (another rebrand) or other versions of any of these Mozilla browsers.

The concept of a home page is not well defined in Firefox. In Edit->Preferences there is a Home Page setting. When Firefox starts, this is the url that will be displayed. But it’s not the url displayed when a new tab is created or when visiting about:home. Those are two other, independent settings. The first is set from the about:config screen by changing the preference browser.newtab.url. It’s also necessary to set browser.newtabpage.enabled to false. The latter is not easily changed. There is no preference to change it.

The about:home page is a static page included in the Firefox distribution. In can be found in the file omni.jar (or omni.ja in my distribution). The exact location of this file will depend on the distribution, the operating system, and probably the Firefox version. It’s probably easiest to find it by doing a search of your file system. One my try entering “chrome://browser/content/findme” in the address bar of a Firefox tab. The resulting error message might indicate where omni.jar is to be found.

Once located, the omni.jar file can be opened and it’s contents browsed and edited. I use fileroller on my Debian based pc to browse the contents of the archive. Inside the archive, you need to find the aboutHome.xhtml file. In my version of Icecat (17.0.1) it is located within the archive at /chrome/browser/content/branding/. If you don’t have a rebranded version of Firefox, you might find it at /chrome/browser/content/browser/abouthome/.

Open this file for editing. Within the <head> element of the xhtml page, simply add the following script tag:

<script>
window.location.href = "https://www.startpage.com";
</script>

Whenever about:home is accessed, the page will be automatically redirected to whatever url is set in the quotation marks. You can test this by typing “about:home” in the address bar of a Firefox tag. This shouldn’t require that you restart Firefox in order to work.

Playing around with the omni.jar file turns out to be a lot of fun. With my current configuration, I am able to browse the contents of the jar file using Firefox itself by typing in the following in the address bar of a tab: “jar:file:///home/Files/Programs/icecat-17.0.1/omni.ja!/”.

It also seems possible to access some components directly. For example, entering “chrome://browser/content/browser.xul” in the address bar of a tab, appears to load another instance of Firefox within that Firefox tab. It’s like a new Firefox window all contained within a tab. Very cool.

Screenshot - 03202014 - 03:35:10 PM