Jawad's Blog

Think different!!!

CISCO Router Commands May 17, 2011

Filed under: Computer Networks — Jawad Rehman @ 12:12 pm

Set the time on a Cisco router manually

Setting the internal clock in a Cisco router allows timestamping of logging information
which makes troubleshooting much easier. If you do not have an NTP server running, you
can set the time manually with a simple command.
To set the time, use this command in enable mode (not configuration mode):
Router# clock set 22:55:05 June 19 2006
The time is in 24 hour mode. To see the information about the clock settings, use:
Router# show clock detail
22:56:07.136 PDT Mon Jun 19 2006

Enable and password protect telnet logins to Cisco routers
The ability to telnet to a Cisco router makes administration easier. This simple configuration enables telnet
logins to the router and protects them with a password. 
To enable telnet logins with the password PaSsWoRd:
The ability to telnet to a Cisco router makes administration easier. This simple configuration enables
telnet logins to the router and protects them with a password.
To enable telnet logins with the password PaSsWoRd:
conf t
line vty 0 4
login
password PaSsWoRd
 


 

Wav File Format February 9, 2011

Filed under: C programming — Jawad Rehman @ 10:10 am

What is Wave File?
Wav file is a common type of audio file. The wav format is based on RIFF (Resource interchange format) which store audio files in chunks and sub chunks.
Wav file digitize sound 100% to the original source because it is lossless format.

File Format
The following figure shows the file format of the Wave file;

Figure 1: File Format of Wav file

Example
The following file shows the example of the Wav file.

Figure 2: Bytes of Wav file

 

Figure 3: Example of Wav File

 

 

 

Audio Programming February 9, 2011

Filed under: C programming — Jawad Rehman @ 7:41 am

What is OSS?

OSS is set of drivers that provide API across all major UNIX architecture. It can be used on Sound Blaster or Windows Sound System Sound Cards.
OSS can be used for MIDI and electronic music.

Code Help
The following file contains some helping code.
Code

 

USB HID(Gadget Driver) December 13, 2010

Filed under: C programming — Jawad Rehman @ 6:48 am

Gadget Driver
A device driver is a software program that implements at the operating system kernel’s mode and communities between the hardware devices attached to the host platform and applications that wish to access the device. A USB gadget driver is a device driver for devices that are connected to the gadget platform via USB and support data transfer on this bus. The following figure shows the general architecture of the USB gadget driver on embedded platform;

Figure: General Architecture of USB HID Class Gadget Driver

USB Device Controller Hardware

The USB controller driver handle low level operation on the USB device to select the speed of communication and configuration of control, interrupt and data pipes and also provide gadget API(s) and data structure to the upper layer for various operations .
USB gadget driver for HID class

This layer will provide to communicate descriptors with the host . The layer will enable pipes for various operations.  The character driver will also be implemented on this layer. The character driver will enable the user application to communicate reports between host and device.
Operating system Native wrapper

The layer provides various API(s) and data structures to different layers of HID class gadget driver

Software Architecture of USB Gadget Driver

The following figure shows the software level architecture design of the USB HID class driver;

Figure 2: Software level architecture design


 

USB HID Class(Case Study) November 13, 2010

Filed under: C programming — Jawad Rehman @ 11:35 am

USB HID Class
The HID class consists of devices that are used by humans to control the operation of systems e.g. Keyboard, Mouse, Trackballs and Joy Sticks. HID classes are identified by a device as belonging to one of a finite number of classes (HID Class). A USB/HID class device uses a corresponding HID class to retrieve and route all the data. The routing and retrieval of data is accomplished by examining the descriptors of the device and that it provides which is depicted in the following figure;

The HID class device descriptors identify which other HID class descriptors are present and indicate their sizes e.g. Report and Physical descriptors. The HID does not have a human interface. The device just needs to be able to function within the limits of major abilities and limits of HID class devices

All data exchanged resides in fixed length structure called reports. The host sends and receives data by sending and requesting reports in a control or interrupts transfers. The report format is flexible and can handle just about any type of data.

A HID must have interrupt IN end point for sending input reports

A HID can have at most one interrupt IN endpoint and one interrupt out endpoint. A device that requires more interrupt endpoints can be a composite device with multiple HID interfaces.The Interrupt IN end point enables the HID to send information to the host at unpredictable time’s e.g There is no way for the host computer to know when a user will press a key on the board.

The rate of data exchange is limited. A low speed interrupt end point, a maximum data transfer rate of 800 bytes/sec.  For full speed points, the maximum is 64 KB/s. High Speed endpoints support faster rates.The USB specification allows for the connection of maximum of 127 peripheral devices to the system either on the same port or on different ports.
Descriptors
The following  is the detail of descriptors used in USB HID class;
Device Descriptor
Describes the number of configurations supported by the device and specifies vendor information and device class.
Configuration Descriptor
Specify one/ more interface and define certain attributes associated with this configuration.
Interface Descriptor
Defines the number of endpoints related to the interface along with information needed by host software to determine how end points should be accessed.
String Descriptor
Optional descriptors consisting of a Unicode string that provide human readable information which can be displayed on host side device.
HID Class Descriptor
The HID class descriptors identify additional descriptors for HID communication. The class description has seven or more fields depending on the number of additional descriptors.
Report Descriptor
A report descriptor defines the format and use of the data in the HID reports. If the device is a mouse; the data reports mouse movements and button clicks. If the device is a relay controller, the data specifies which relay to open and close. The descriptor format is flexible enough for use with the devices with varied functions.

Case Study(USB Mouse)
The following is the details of descriptors used for USB mouse as Case Study;
Device Descriptor

 


Configuration Descriptor

Interface Descriptor

HID Descriptor

End Point Descriptor

Report Descriptor

 

 

ALSA Audio Driver November 11, 2010

Filed under: C programming — Jawad Rehman @ 12:13 pm

ALSA Audio Driver
The below figure shows audio connection on a PC compatible system; the audio controller on the south bridge, together with an external codec, interfaces with analog audio circuitry.

Figure: Audio in a PC environment

An audio codec converts digital audio data to analog sound signals for playing via speakers and performs the reverse operation for recording via a microphone. Other common audio inputs and outputs that interface with a codec include headsets, earphone, hand free, line in and line Out. A codec offers mixer functionality that connects it to a combination of these audio outputs and inputs and controls the volume gain associated with audio signal.

Digital data is obtained by sampling audio analog signals at specific bit rates using a technique called pulse code modulation (PCM). CD quality is for example sound sampled at 44.1 KHz, using 16 bits to hold each sample. A codec is responsible for recording audio by sampling at supported PCM bit rates and for playing audio originally sampled at different bit rates.

Linux Sound Sub System
Advanced Linux Sound Architecture (ALSA) is the sound sub system in 2.6 Kernel. Open Sound System (OSS), the sound layer in the 2.4 layer is now obsolete and depreciated.
The following figure shows the Linux sound sub system;

Figure: Linux Sound Sub System (ALSA)

1). The following /dev/snd/* device nodes are created and managed by the ALSA core. /dev/snd/controlC0 is a control node that application uses for controlling volume gain and such. /dev/snd/pcmC0D0P is a play back device. /dev/snd/pcmD0C is a recording device.
2). Audio controller drivers specific to the controller hardware . To drive the audio controller present in the intel ICH south bridge chipsets e.g. use the snd_intel8x0 driver.
3). Audio codec interface that assist communication between controllers and codecs for AC’ 97 codec used the snd_ac97_codec and ac97_bus modules.
4). The nodes /dev/adsp and /dev/mixer allow OSS application to run unchanged over ALSA. The OSS /dev/dsp node maps to ALSA nodes /dev/snd/pcmC0D0; /dev/adsp corresponds to /dev/snd/pcmC0D1* and /dev/mixer associates with /dev/snd/ControlC0.
5). Procfs and sysfc interface implementations for accessing info via /proc/aSound and /Sys/class/sound.

6). The user space ALSA library alsa-lib which provides the libSound.so object. The library passes the job of the ALSA application programming by offering several canned routines to access ALSA drivers.

Tools and Links
1). http://tldp.org/HOWTO/Sound-HOWTO/
Answers of FAQ pertaining to Linux
2). http://sourceforge.net/projects/mad/files
MadPlay is a software MP3 decoder and player that are both ALSA and OSS aware.
3). http://rawrec.sourceforge.net
It is used for basic playback and recording.

Data Structure and API
The figures show the list of data structure and API used in developing the ALSA driver.

Figure: Summary of data structures

Figure: Summary of ALSA driver API

 

 

USB in User Mode September 29, 2010

Filed under: C programming — Jawad Rehman @ 2:25 pm

USB in User Mode
LibUSB library is best option for developing a USB driver. It can work on both Windows and Linux machines. It can be downloaded from http://libusb.sourceforge.net/. The full list of USB access functions offered by this library is available under the doc/ directory of LibUSB sources.

Architecture on Linux
The following is the detail design of using lib USB library with the user application on Linux machine.

Figure: Detail design of Lib USB with user mode application

Architecture on Windows Machine
Following is the architecture of using libusb on windows platform;

Figure: Detail design of LibUSB on Windows machine

The following code implements a user space code for detecting a USB device according to its class and getting its different manufacturing information from descriptors like device descriptors and interface descriptors.

libusb_test

 

Smart Antenna? August 24, 2010

Filed under: Electronics and Communication — Jawad Rehman @ 12:20 pm

Smart Antenna?
Smart Antenna is an antenna array aided by some “smart” algorithm to combine the signals, designed to adapt to different signal environments. The antenna can automatically adjust to a dynamic signal Environment. The gain of the antenna for a given direction of arrival is adjustable. In truth, antennas are not smart, antenna systems are smart. Generally collocated with a base station, a smart antenna system combines an antenna array with a digital signal-processing capability to transmit and receive in an adaptive, spatially sensitive manner. In other words, such a system can automatically change the directionality of its radiation patterns in response to its signal environment. This can dramatically increase the performance characteristics (such as capacity) of a wireless system.

Types of Smart Antenna Systems

The following are distinctions between the two major categories of smart antennas regarding the choices in transmit strategy:

Switched Beam Antennas
In Switched Beam Smart antenna, there are a finite number of fixed, predefined patterns or combining strategies (sectors).
Switched beam antenna systems form multiple fixed beams with heightened sensitivity in particular directions. These antenna systems detect signal strength, choose from one of several predetermined, fixed beams, and switch from one beam to another as the mobile moves throughout the sector.  Instead of shaping the directional antenna pattern with the metallic properties and physical design of a single element (like a sectorized antenna), switched beam systems combine the outputs of multiple antennas in such a way as to form finely sectorized (directional) beams with more spatial selectivity than can be achieved with conventional, single-element approaches.
In the Switched Beam scheme, beams are created by choosing a particular set of antenna weights from a fixed “library” of beam weight vectors. The weight vector associated with maximum SNIR is chosen as the current weight vector. It follows that in order to continuously maintain maximum SNIR, the choice of weight vector must be continuously updated via ongoing SNIR measurements.Switched beam systems are simpler and less computationally intensive.

Figure: Switched Beam System Coverage Patterns (Sectors)

Adaptive Array Antennas
In Adaptive Array antenna there are an infinite number of patterns (scenario-based) that are adjusted in real time.
Adaptive antenna technology represents the most advanced smart antenna approach to date. Using a variety of new signal-processing algorithms, the adaptive system takes advantage of its ability to effectively locate and track various types of signals to dynamically minimize interference and maximize intended signal reception. Both systems attempt to increase gain according to the location of the user; however, only the adaptive system provides optimal gain while simultaneously identifying, tracking, and minimizing interfering signals.

Figure: Adaptive Array Coverage, A representative depiction of a Main Lobe extending toward a User with a Null directed toward a Co channel Interferer.

Beamforming Algorithms
In beamforming, both the amplitude and phase of each antenna element are controlled. Combined amplitude and phase control can be used to adjust side lobe levels and steer nulls better than can be achieved by phase control alone. The combined relative amplitude ak and phase shift qk for each antenna is called a “complex weight” and is represented by a complex constant wk (for the kth antenna). These weights are calculated using different algorithms.
Beamforming is the term used to describe the application of weights to the inputs of an array of antennas to focus the reception of the antenna array in a certain direction, called the look direction or the main lobe. More importantly, other signals of the same carrier frequency from other directions can be rejected. These effects are all achieved electronically and no physical movement of the receiving antennas is necessary. In addition, multiple beamformers focused in different directions can share a single antenna array; one set of antennas can service multiple calls of the same carrier.
In Beamforming, we discriminate between signals according to their angles of arrival (AOA). Beam pattern is controlled by the complex weights.

Least-Mean-Squares Algorithm
The LMS algorithm can be considered to be the most common adaptive algorithm for continues adaptation. It uses the steepest-descent method and recursively computes and updates the weight vector.

Figure: LMS Algorithm

Due to the steepest-descend the updated vector will propagate to the vector which causes the least mean square error (MSE) between the beamformer output and the reference signal. The following derivation for the LMS algorithm is found in . The MSE is defined by:

is the complex conjugate of the desired signal. The signal is the received signal from the antenna elements, and is the output of the beamform antenna and is the Hermetian operator. The expected value of both sides leads to:

In this relation the r and R are defined by:

R is referred to as the covariance matrix. If the gradient of the weight vector w is zero, the MSE is at its

minimum. This leads to:

This solution is called the Wiener-Hopf equation for the optimum Wiener solution:

The LMS algorithm converges to this optimum Wiener solution. The basic iteration is based on the

following simple recursive relation:

And combining above two equations, gives:

The measurement of the gradient vector is not possible, and therefore the instantaneous estimate is used.

The LMS algorithm can be written in its final form.

One of the issues on the use of the instantaneous error is concerned with the gradient vector, which is not the true error gradient. The gradient is stochastic and therefore the estimated vector will never be the optimum solution. The steady state solution is noisy; it will fluctuate around the optimum solution. By decreasing µ the precision will improve but it will decrease the adaptation rate. An adaptive µ could solve this issue by starting with a large µ and decrease the factor when the vector converges. When an array of 4 antennas is used, there is a maximum of 3 nulls that can eliminate the interferer. Figure 7 shows the convergence of the array for 2 interferers. The minimum error is a result of the extra ‘system’ noise that is added to all antennas. The interference signals are Gaussian white noise, zero mean with a sigma of 1. The extra system noise to all antennas is white noise with zero mean and a sigma of 0.1. The received signals are MSK signals with an oversampling of 4 and have an amplitude of 1 in the simulations. The true array output y(t) is converging to the desired signal d(t). After 40 samples the signal is at its minimum due to the system noise. The LMS cannot filter the system noise, as it is not correlated for all four antennas. The interferers are cancelled by placing nulls in the direction of the interferers. The received signal arrives at an angle of 25 degrees and the array response is 0 dB. The LMS algorithm clearly works sufficient as the strong interferers are reduced.

 

Digital Clock Simulation June 8, 2010

Filed under: Electronics and Communication — Jawad Rehman @ 10:00 pm

Digital Clock
In digital clock circuit, the 50 Hz, 220 volts ac main sinusoidal signal is shaped into a 50Hz, a 5 volt square wave signal. A divide by 50 counters divides the input 50 Hz signal to a 1 Hz signal. The seconds, divide by 60 counter counts up to 60 seconds (0 to 59). The minutes, divide by 60 counter also counts up to sixty minutes (0 to 59). The hours, decade counter counts from 0 to 9. The flip flop connected to the output of the decade counter is set to 0 or 1 to represent hours from 0 to 9and 10 to 12 respectively.

Simulation of Digital Clock
The following figure shows the simulation of the digital clock;

Figure: Digital Clock Simulation

 

 

Bridge Rectifier Simulation June 8, 2010

Filed under: Electronics and Communication — Jawad Rehman @ 4:17 am

Full Wave Bridge Rectifier
The bridge rectifier is the most commonly used full wave rectifier circuit for several reasons
(1) It does not require the use of center-tapped transformer, and therefore can be coupled directly to the ac power line, if desired.
(2)Using a transformer with the same secondary voltage produces a peak output voltage that is nearly double the voltage of the full wave center-tapped rectifier. This results in the higher dc voltage from the supply.

Figure: Bridge full wave rectifier

When D1 and D3 are on, D2 and D4 are off and vive versa. This circuit operation is illustrated in the fig.
The current direction will not change in the either condition.

Simulation

The follwing figure shows the simulation of full wave bridge rectifier;

Figure: Simulation of Full Wave Bridge Rectifier

 

 
Follow

Get every new post delivered to your Inbox.