Wednesday 6 May 2015

Installing Debian on an HP Stream 11/13

The HP stream 11/13 is a great little low-cost linux machine. here are some instructions for installing debian linux on your new laptop.

Preliminaries

Create a restore disk from windows. Go to the control panel and search for 'restore'. Then choose the create restore disk option and insert an SD card larger than 8GB.

Modify BIOS Settings

Spam the ESC key on bootup, and choose the F10 option to edit BIOS settings. Switch to Legacy Boot mode. Save your BIOS settings (using F10).

Get your install media

As the WiFi requires a non-free firmware module, you should download the unofficial debian installer image with non-free firmware linked to from this page. This file is 280 MB in size.
Then install a USB memory stick (won't work on SD card), and insert it. Use the 'dmesg' command to find out the device number for your usb stick. In my case it was /dev/sdb.
# sudo cp firmware-8.0.0-amd64-netinst.iso /dev/sdX
# sync
where /dev/dsX is your USB memory stick device.

Base Debian Install

Insert your usb stick and spam the ESC key during bootup. Choose F9 and choose your USB stick (in legacy mode). Your system should now boot from the debian install.
Install as usual for a debian system, I chose all the default options. However when you get to the final step, deselect all the options when you get to tasksel because we will upgrade the WiFi before continuing.
Reboot your system. It should give you a root prompt.

Connect to WiFi

Find the name of your network device. It should be wlan0
  # ip a
  # iwconfig
  # ip link set wlan0 up
Scan for available networks and get network details:
  # iwlist scan
Find the key and append it to the /etc/network/interfaces file
  # wpa_passphrase myssid my_very_secret_passphrase >> /etc/network/interfaces
Now edit the file /etc/network/interfaces to remove the unnecessary parts and your file should look something like
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid [ESSID]
    wpa-psk ccb290fd4fe6449e050edd02ad44627b16ce0151668f5f53c01b
You can now bring your interface up and down with the usual ifup and ifdown commands. If you added auto wlan0 as in the example above, the interface should be brought up automatically during boot up.

Update the Wireless Drivers

The WiFi drivers are not very reliable. To fix this, download a new driver
# apt-get install linux-headers-amd64 linux-kbuild-3.16 gcc make
# wget https://github.com/lwfinger/rtlwifi_new/archive/master.zip
unzip master.zip
cd rtlwifi_new-master/
make
sudo make install
Reboot your system

Update for Kernel 4.2 and Later...

I get WiFi freeze on the wireless card. The symptoms are that the network just hangs after a few minutes. This first appeared when upgrading to kernel 4.x.

This can be fixed by adding a file /etc/modprobe.d/rtl8723be.conf, with the following contents:

#Prevent  WiFi card from automatically sleeping

# and halting connection
options rtl8723be fwlps=0 swlps=0
Then reboot

Installing a Desktop Environment

Bring your wireless up using
# ifup wlan0
Now run tasksel,
# tasksel
and choose your desktop environment. I choose KDE, and the laptop packages.

Installing ZRam

Linux can slightly increase the CPU load and compress your RAM. This is worth it on a machine like the stream that has 2GB of RAM.
Follow the instructions here.

Sunday 3 May 2015

Modeling antennas in Python with NEC2++

Introduction to Modelling antennas with python-necpp


Nec2++ is a program for simulating antennas. It is a rewrite in C++ of an old FORTRAN code called NEC2 and has some nice features. In particular it provides a library and an API so that simulations can be done in other languages. A python module (python-necpp) has just been developed that allows you to simulate antennas using nec2++.

Installation

Installation is easy with the python pip installer.  Install python-necpp with

    pip install necpp

This will download and compile the python-necpp package.

A Simple Antenna

NEC2 was based on punch cards and an antenna model was described as a series of Cards. These are well documented. Nec2++ replaces these cards with function calls each function call the equivalent of an nec2 card -- here's an example.

We'll model a vertical monopole (like a whip antenna on an old radio).

from necpp import *
import math

def handle_nec(result):
  if (result != 0):
    print nec_error_message()

def monopole_impedance(freq, base, length):
  wavelength = 3e8/(1e6*freq)
  n_seg = int(math.ceil(50*length/wavelength))
  nec = nec_create()
  handle_nec(nec_wire(nec, 1, n_seg, 0, 0, base, 0, 0, base+length, 0.002, 1.0, 1.0))
  handle_nec(nec_geometry_complete(nec, 1, 0))
  handle_nec(nec_fr_card(nec, 0, 1, freq, 0))
  handle_nec(nec_ex_card(nec, 0, 0, n_seg/3, 0, 1.0, 0, 0, 0, 0, 0)) 
  handle_nec(nec_xq_card(nec, 0)) # Execute simulation
  # Results
  z = complex(nec_impedance_real(nec,0), nec_impedance_imag(nec,0))
  # Cleanup
  nec_delete(nec)
 return z

z = monopole_impedance(freq=134.5, base=0.1, length=4.0)
print "f=134.5 z = (%6.1f,%+6.1fI) Ohms" % (z.real, z.imag)

When you run this code, it will print out the impedance of the antenna:

$ python quarter_wave.py
f=134.5 z = ( 141.0,-416.2I) Ohms

Impedance Mismatch

Radio recevers and transmitters are designed to operate with antennas of a specific impedance (z0). If the antenna has a different impedance (z), this impedance mismatch causes loss of signal. The reflection coefficient measures how much signal is reflected at the junction between the antenna and the radio.  The reflection coefficient (Gamma) is given by
def reflection_coefficient(z, z0):
  return np.abs((z - z0) / (z + z0))
The transmission coefficient is (1.0 - Gamma) and represents how much of the original signal makes it through this junction.

Searching for an optimum antenna

Imagine the antenna is fixed 0.5 meters above the ground and we are connecting the signal to the antenna one-third of the way along its length. How long should the wire be for optimum performance?

If we minimize the reflection coefficient, this is a relatively easy optimization. We can use matplotlib to plot the reflection coefficient as a function of length, with the base_height of the antenna fixed.
import numpy as np
import pylab as plt

lengths = np.linspace(0.2, 5.0, 270)
reflections = []
z0 = 50

for l in lengths:
  z = monopole_impedance(freq=134.5, base=0.5, length=l)
  reflections.append(reflection_coefficient(z, z0))
 
plt.plot(lengths, reflections)
plt.xlabel("Antenna length (m)")
plt.ylabel("Reflection coefficient")
plt.title("Reflection coefficient vs length (base_height=0.5m)")
plt.grid(True)
plt.show()
The reflection coefficient has several minima when the base height is 0.5m. The first occurs when the antenna length is just over 1m.
This shows that for short lengths, less than 10 percent of the signal makes it through. There is a local minimum (of approximately 0.3) that occurs around 1.1m for which around 70 percent of the signal makes it through.

Next Steps

In another post I'll show how to use python-necpp and matplotlib to automatically design a vehicle antenna.

Links


Wednesday 8 May 2013

Installing Android SDK tools on Debian Wheezy

Since debian has moved to multiarch, the process for installing the android SDK on debian has become easier, but the old way (install ia32-libs) does not work anymore.

The Problem

When running tools (like the android virtual device manager) error messages appear:


sdk/build-tools/android-4.2.2/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
   
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory


Install Step 1. Download the android SDK

You may already have done this bit, however here are full install instructions.

Download the android SDK into somewhere convenient and unzip the archive. No system permissions are required.

    unzip adt-bundle-linux-x86_64-20130219.zip

Now launch the eclipse IDE

    cd adt-bundle-linux-x86_64-20130219/
    ./eclipse/eclipse

Installing ia32-libs will no longer work as debian as moved to multiarch support.

Solution. Use Multiarch

Multiarch support makes installing libraries from the i386 distribution easy...

    sudo dpkg --add-architecture i386
    sudo aptitude update
    sudo aptitude install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386


Now launch eclipse, and everything should now work just fine.