Monthly Archives: July 2011

wireless ubuntu basic and fundamental commands.

This an example of connecting a linux laptop to an access point that uses WPA2. The example below will use an Dell Inspiron 9300 laptop running Kubuntu 7.10. The laptop uses a built in Intel PRO/Wireless 2200BG (Centrino) Network Connection mini PCI adapter. Kubuntu had the wireless card working on install (wireless driver is called ipw2200) but no setup for WPA2 that I could find.

The access point I’m going to connect to is a Linksys WRT54GL. It is running dd-wrt firmware version 23 sp2. The access point security is set to “wpa2 pre-shared key mixed” with the WPA algorithm set to “AES”. The SSID will be set to “wpatest” for this example.

The program we will need to connect to the access point is called wpa_supplicant. Supplicant is the IEEE 802.1X/WPA component that is used in the client machines. It implements key negotiation with a WPA Authenticator and it controls the roaming and IEEE 802.11 authentication/association of the wlan driver. Wpa_supplicant only supports certain drivers so if your having problems with this check the wpa_supplicant page (google it) to make sure your driver works with it. Kubuntu 7.10 comes with wpa_supplicant and other wireless tools installed.

First we need to generate a WPA PSK from an passphrase for a SSID so we can try to protect the network. We do this with the wpa_passphrase program using the “wpatest” SSID name I noted above with nice long passphrase. Your pass phrase should have some numbers and special characters in it if you can.

wpa_passphrase wpatest thisisanicelongpassphraseitisniceandlongforareason

This will output a long block of characters that your going to need to put in the /etc/wpa_supplicant.conf file. Keep it handy. Now open the file /etc/wpa_supplicant/wpa_supplicant.conf in your favorite editor. Remember to sudo when opening the file. Now paste the code below into it.

ctrl_interface=/var/run/wpa_supplicant
#ap_scan=2

network= {
  ssid="wpatest"
  scan_ssid=1
  proto=WPA RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk=
}

In the above config you will see the field “ssid=”. Put your ssid for your network in there. Mine is “wpatest” above. Next, where you see the line “psk=” after the = sign you have to put the output from the wpa_passphrase we generated above. It would look something like

psk=a6e6af3e3d77b4c7dd6a3c292ecde36839a1f2d921″

Save that file and exit your editor. Now we need to setup the wireless interface. Use the comand “dmesg” to check for your wireless cards inteface. Look for eth0, eth1, wlan0, or something like that in the output. Your wired connections might look like this also so make sure it’s your wireless interface. You could also try the command “ifconfig” to see if you see your wireless interface there. Kubuntu is pretty good about finding the wireless card. Once you know what it is lets bring it up. Mine is eth1 so the command would be the following.

sudo ifconfig eth1 up

Now we can scan for networks. This is good if you want to see information about the networks in the area. You might already know your access points info but if you don’t just scan.

sudo iwlist scan

It will give the list of access points, Ad-Hoc cells in range, channels, and a lot more info. My access point was listed and showed it’s name “wpatest” on channel 7. So lets configure the wireless interface for that.

sudo iwconfig eth1 essid “wpatest” channel 7

Now we need to start wpa_supplicant. You might need to modify command line switches -i and -D to work with your own setup. -D is the driver to use. My Intel card can use the wext driver which is the Linux wireless extensions (generic). Try that one first. If it does not work look at the man page for wpa_supplicant for other driver types. Also, -i is the interface for your wireless card. Mine is eth1. Yours will be what you found in the earlier step. The line we need to run is the following.

sudo wpa_supplicant -B -Dwext -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf

If wpa_supplicant started successfully then you can make your dhcp request over the network to get an ip address with dhclient. I use eth1 because again it’s my wireless cards interface.

sudo dhclient eth1

After this you should have an ip and be on the network. Below is the shell script I use to start my wireless interface. If you know the settings of your access point just change to fit your needs.

#!/bin/sh
sudo pkill wpa_supplicant
sudo ifconfig eth1 down
sudo ifconfig eth1 up
sudo iwconfig eth1 essid "wpatest" channel 7
sudo wpa_supplicant -B -Dwext -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient eth1

 

Matlab gaussian distribution function.

There is a convenient gaussian function in Matlab.

It can’t cover multi-dimentional gaussian model but worth to know.

Have a look and give it try.

 

gaussmf -Gaussian curve built-in membership function

Syntax

y = gaussmf(x,[sig c])

Description

The symmetric Gaussian function depends on two parameters  and c as given by

The parameters for gaussmf represent the parameters  and c listed in order in the vector [sig c].

Examples

x=0:0.1:10;
y=gaussmf(x,[2 5]);
plot(x,y)
xlabel('gaussmf, P=[2 5]')

 

Symbolic Math in Matlab

http://www.cs.utah.edu/~germain/PPS/Topics/Matlab/symbolic_math.html

Matlab has a powerful symbolic math ability. Rather than making calculations on knownnumbers, we can make calculations on symbolic expressions. For example, what is the limit as x approaches inf of 1 + 1/2^1 + 1/2^2 + 1/2^3…+1/2^n ? Matlab can tell us. What is the integral of x^3 for any x? Matlab can tell us.

Symbolic Math in Matlab

Matlab allows you to create symbolic math expressions. This is useful when you don’t want to immediately compute an answer, or when you have a math “formula” to work on but don’t know how to “process” it.

Matlab allows symbolic operations several areas including:

  • Calculus
  • Linear Algebra
  • Algebraic and Differential Equations
  • Transforms (Fourier, Laplace, etc)

The key function in Matlab to create a symbolic representation of data is: sym() or syms if you have multiple symbols to make.

Below is an example of creating some symbolic fractions and square roots:

	<code> 
         
        &gt;&gt; sqrt(2) 
        ans = 
          1.4142 
 
        &gt;&gt; sqrt( sym(2) ) 
        ans = 
        2^(1/2) 
 
        &gt;&gt; 2 / 5 
        ans = 
          0.4 
 
        &gt;&gt; 2/5 + 1/3 
        ans = 
 
        0.7333 
 
        &gt;&gt; sym(2) / sym(5) 
        ans = 
        2/5 
 
        &gt;&gt; sym(2) / sym(5) + sym(1) / sym(3) 
        ans = 
        11/15 
    </code>

Defining Symbolic Expressions

We can define symbolic functions using the sym command and syms command. Here is an example of creating a symbolic function for (a*X^2) + (b*x) + c:

	<code> 
        &gt;&gt; syms a b c x % define symbolic math variables 
 
        &gt;&gt; f = sym('a*x^2 + b*x + c'); 
    </code>

From now on we can use the f symbol to represent the given function.


Evaluation of Symbolic Expressions

The keyfunction subs (which stands for substitute) is used to replace symbolic variables with either new symbolic variables or with acutal values. The syntax for the function is: subs( symbolic_function, list_of_symbols, list_of_values). Here is an example:

        <code> 
         
        &gt;&gt; f = sym('a*x^2 + b*x + c'); 
 
        &gt;&gt; subs(f,x,5) 
  
        ans = 
        25 * a + 5 * b + c 
 
        &gt;&gt; subs(f,[x a b c],[5 1 2 3]) 
        ans = 
           38 
        </code>

Plotting Symbolic Function

In Matlab, we can plot a symbolic function over one variable by using the ezplot function. Here is an example:

	<code> 
&gt;&gt; y = sin(x) 
  
y = 
  
sin(x) 
  
&gt;&gt; ezplot(y) 
    </code>

If you want to see something cool, try:

        <code> 
&gt;&gt; f = sin(x); 
&gt;&gt; ezsurf(f); 
        </code>

Now try:

        <code> 
&gt;&gt; f = sin(x); 
&gt;&gt; g = cos(y); 
&gt;&gt; ezsurf(f+g); 
        </code>

Or really cool!

        <code> 
&gt;&gt; ezsurf( 'real(atan(x+i*y))' ); 
        </code>

To set the bounding values of the variables, you can use:

        <code> 
 
&gt;&gt; ezplot(y, [ -5, 10 ]);  % from -5 &lt; x &lt; 10 
&gt;&gt; ezsurf(z,[[1 2] [5 7]); % x from 1 to 2, y from 5 to 7 
 
        </code>

Or plotting a polynomial equation:

	<code> 
         
        &gt;&gt; f = sym('a*x^2 + b*x + c'); 
 
        &gt;&gt; ezplot(subs(f,[a b c],[1 2 3])); 
    </code>

Integration and Derivation

Matlab can also compute many integrals and derivatives that you might find in Calculus or many advanced engineering courses.

The key functions are int for integration and diff for derivation.

Differentiation

	<code> 
        &gt;&gt; syms x; 
        f = sin(5*x) 
  
        &gt;&gt; f = 
        sin(5*x) 
  
        &gt;&gt;diff(f) 
  
        ans = 
        5*cos(5*x) 
    </code>

2nd Derivative

To take the 2nd (or greater) derivative of an equation, we use:

	<code> 
 
&gt;&gt; f = x^3 
  
f = 
  
x^3 
  
  
&gt;&gt; diff(f) % 1st derivative 
  
ans = 
  
3*x^2 
  
  
&gt;&gt; diff(f,2) % 2nd derivative 
  
ans = 
  
6*x 
  
  
&gt;&gt; diff(f,3) % 3rd derivative 
  
ans = 
  
6 
 
&gt;&gt; diff(f,4) % 4th derivative 
  
ans = 
  
0 
    </code>

Partial Differential Equations

Sometimes you have multiple variables in an expression. If we want to compute the derivative of the function with respect to one variable we can use a second parameter to the diff function:

	<code> 
        &gt;&gt; syms x t; 
        f = sin( x * t ) 
  
        &gt;&gt;diff(f,t)  % derivative of f with respect to t 
  
        ans = 
        cos(x*t)*t 
    </code>

Integration

By using the “int” function, in the same way we use the diff function, we can ask Matlab to do symbolic integration for us.

Warning: Do not confuse the int function in Matlab with the integer (int) data type in C or the int8, int16, int32 data types in Matlab.

	<code> 
        &gt;&gt; syms x t; 
        f =  x * x ; 
  
        &gt;&gt;int(f) 
  
        ans = 
        1/3*x^3 
    </code>

Definite Integrals

As you (should) know, a definite integral represents the area under a curve from a given start point to a given end point. What if we want to know how much area is under the curve f(x) = x^3; from 0 to 10, from -10 to 10, from -10 to 0?

	<code> 
  
&gt;&gt; int(x^3,0,10) 
  
ans = 
  
2500 
  
  
&gt;&gt; int(x^3,-10,10) 
  
ans = 
  
0 
  
  
&gt;&gt; int(x^3,-10,0) 
  
ans = 
  
-2500 
    </code>

Summations

You can use Matlab to tell you the sum of a series of equations, such as:

1 + 1/2^2 + 1/3^2 + 1/4^2 + … + 1/N^2

From N = 1 to inf (or from value1 to value2)

	<code> 
         
&gt;&gt; syms x k 
&gt;&gt; s1 = symsum(1/k^2,1,inf) 
 
s1 = 
  
1/6*pi^2 
 
 
&gt;&gt; s2 = symsum(x^k,k,0,inf) 
 
s2 = 
  
-1/(x-1) 
    </code>

Mathematical Limits

Every wonder what happens if you divide infinity by infinity? Well depending on how those values were created, you can get some interesting results. For example, what is the limit of x/ x*x as X approaches infinity?

        <code> 
&gt;&gt; limit( 1 / x )  % with no params, by definition, as x approaches 0 
  
ans = 
  
NaN 
 
&gt;&gt; limit(x / x^2, inf) % as x approaches inf 
  
ans = 
  
0 
 
&gt;&gt; limit(sin(x) / x) % as x approaches 0 
  
ans = 
  
???? 
  
        </code>

Expand Function

The expand function will “expand” a formula by doing basic symbolic math where possible.

	<code> 
      syms x; 
 
      &gt;&gt; f1 = (x+5)*(x+5); 
  
      f1 = 
  
      (x+5)^2 
  
  
      &gt;&gt;  expand(f1) 
  
      ans = 
  
      x^2+10*x+25 
 
    </code>

Simplify Function

When you have a complex evaluated symbolicexpression, such as: (sin(x)^2 + cos(x)^2), you can use the simplifyfunction to ask matlab to try and simplify it to a less complex term:

	<code> 
 
        simplify(sin(x)^2 + cos(x)^2) 
        ans = 
           1 
    </code>

“Pretty” Printing Symbolic Functions

When you want to print a symbolic function to make it easier for the user of the program to read, you can use the “pretty” function. Here is an example:

	<code> 
 
        f = sin(x)^2 + cos(x)^2; 
 
        pretty( f ) 
  
                                     2         2 
                               sin(x)  + cos(x) 
    </code>

“Taylor” Command

If you would like to create a taylor series, you can use the “taylor” function.

	<code> 
     &gt;&gt; f = taylor(log(1+x)) 
   
     f = 
  
     x-1/2*x^2+1/3*x^3-1/4*x^4+1/5*x^5 
    </code>

Known Bad Variable Names

A few years ago Matlab “upgraded” their symbolic library. When they did so they, “broke” the ability to use any arbitrary variable name. For example, the symbol D (capitol D) is invalid in some cases. For example:

	<code> 
int('A*x^3+B*x^2+C*x+D') 
Warning: Explicit integral could not be found.   
  
ans = 
  
int(C*x + A*x^3 + B*x^2 + D, x) 
 
% BUT 
 
syms A B C D x 
int(A*x^3+B*x^2+C*x+D) 
  
ans = 
  
(A*x^4)/4 + (B*x^3)/3 + (C*x^2)/2 + D*x 
  
    </code>

To fix this problem, append an _ (underscore) to the variable

The following symbols are know