Friday, May 17, 2013

Basic Euclidean vector operations in C++

Euclidean vectors are very important quantity in mathematics, applied mathematics, physics, engineering etc. Formally vectors are those quantity which have both magnitude and direction. For example velocity. Velocity has both magnitude (Speed, like 2 Km/Hr) and direction (e.g. east). In programmer’s perspective, there are many situation where you need to compute different vector operations. For example consider a moving ball. To simulate the motion of ball, you must calculate the velocity of the ball. The ball has both magnitude (i.e rate of translation of  position of center of the ball) and direction (e.g. axis x or y or z). This is just one example but there are various examples where vector operations are essential.
Now in this article, I will show you how to compute different vector operations like, sum of two vectors, multiplication by scalar, dot product, cross product, normalization etc in C++. I choose C++ instead of C because it is object oriented. The vector can be represented by an object. The components of vector along x, y and z axis will be the data member of the object. The data members are attributes of the object. Similarly different operations will be the member functions of the object. Now the vector object can completely represent the vector quantity.

Tuesday, May 14, 2013

Calculation of Discrete Fourier Transform(DFT) in C/C++ using Naive and Fast Fourier Transform (FFT) method

Discrete Fourier Transform has great importance on Digital Signal Processing (DSP). There are many situations where analyzing the signal in frequency domain is better than that in time domain. The Fourier Transform actually converts the function in time domain to frequency domain,  some processing is done in frequency domain, and finally inverse Fourier transform converts the signal back into time domain. The term discrete means the signal is not continuous rather it is sampled by some sampling frequency i.e. only some samples are taken in certain interval (also called period). The sampling frequency depends upon the frequency of original signal and this must satisfy Nyquist criteria. A simple example of Fourier transform is applying filters in frequency domain of digital image processing. Before looking into the implementation of DFT, I recommend you to first read in detail about the Discrete Fourier Transform in Wikipedia. If you are already familiar with it, then you can see the implementation directly.  The 1 dimensional DFT can be calculated by using the following formula
dfte 

Monday, May 6, 2013

Pascal’s Triangle using C program

Printing Pascal’s Triangle is famous problem in C. You may be familiar with the Pascal triangle from the Math class when you learnt Permutation and Combination or Binomial Coefficients or other class. If you are not familiar then don't worry, just look at Wikipedia to get inside of the Pascal Triangle and see the code below.

There are various methods to generate Pascal’s Triangle in C program. Among them most popular one is by using Combination. Since elements of the triangle represent the Binomial Coefficients of a polynomial and Binomial Coefficient can be calculated using the Combination, I decided to generate Pascal’s Triangle using Combination method. Here is the source code

Tuesday, March 12, 2013

Setting up FTP server vsftpd in Fedora 16


The file transfer protocol (FTP) can be used to transfer files across different systems. In this article, I set up a secure ftp server vsftpd in my fedora machine and access the files on this server from my friend Niroj Karki’s client computer. To set up the file server on fedora you need to first install the ftp server using following command

$su
$password:
$yum –y install vsftpd.x86_64

Open the file /etc/vsftpd/vsftpd.conf and uncomment/add the following line

Setting up SSH server in Fedora 16 : Theory and Configuration Details

rlogin and ssh are used to login to remote server. They are very useful tool to login to the remote machine and access the resources available. Rlogin and ssh both are used for this purpose. The only difference between them is in security aspect. In rlogin, all information, including passwords, is transmitted unencrypted (making it vulnerable to interception). So now-a-days ssh (secured shell) is used most often.

The original Berkeley package which provides rlogin also features rcp (remote-copy, allowing files to be copied over the network) and rsh (remote-shell, allowing commands to be run on a remote machine without the user logging into it). These share the hosts.equiv and .rhosts access-control scheme (although they connect to a different daemon, rshd), and as such suffer from the same security problems. The ssh suite contains suitable replacements for both: scp replaces rcp, and ssh itself replaces both rlogin and rsh.


Steps needed to configure SSH server in Fedora 16

Monday, March 4, 2013

Sobel and Prewitt edge detector in C++: Image Processing

Sobel and Prewitt are used extensively for detecting edges in image processing.

Sobel Operator

The operator calculates the gradient of the image intensity at each point, giving the direction of the largest possible increase from light to dark and the rate of change in that direction. The result therefore shows how "abruptly" or "smoothly" the image changes at that point, and therefore how likely it is that part of the image represents an edge, as well as how that edge is likely to be oriented. The Sobel kernels are given by

Here the kernel hx is sensitive to changes in the x direction, i.e., edges that

Saturday, March 2, 2013

Gaussian blurring using separable kernel in C++

Gaussian blurring is used to reduce the noise and details of the image. It reduces the image's high frequency components and thus it is type of low pass filter. Gaussian blurring is obtained by convolving the image with Gaussian function. For more information about Gaussian function see the Wikipedia page.  Since 2D Gaussian function can be obtained by multiplying two 1D Gaussian functions, the blurring can be obtained by using separable kernel.

Use of Separable Kernel

Thursday, February 28, 2013

Loading large data into Oracle database using SQL* Loader

SQL * Loader is very useful when loading large data, which are very tedious and time consuming task, to the database. Suppose you have a 10000 rows in .csv file and you have to load all the rows to the database. Now what would you do? Would you enter each and every row individually and spends years to do it? obviously not. For this task there is a very useful tool SQL *Loader which load large data file into database in very short time. Here I will give an small example of loading the data which are in .csv file to the ORACLE database located in remote host (same steps can be used to load into local machine).