Recursion : Tower of Hanoi in C++

Tower of Hanoi by recursion

#include <iostream>
using namespace std;
int main()
{

C++ implementation of Circular Queue

C++ implementation of Circular Queue

#include <iostream.h>
#include <conio.h>
#define size 10

class queue
{

C++ implementation of front end fix and rear end vary queue

C++ implementation of front end fix and rear end vary queue

#include <iostream.h>
#include <conio.h>
#define size 10

class queue
{

C++ implementation of front and rear end varying queue

C++ implementation of front and rear end varying queue

#include <iostream.h>
#include <conio.h>
#define size 10

class queue
{

C++ implementation of top varying stack

C++ implementation of top varying stack

#include <iostream.h>
#include <conio.h>
#define size 10
using namespace std;
class stack
{

C++ implementation of fixed top stack

C++ implementation of fixed top stack

#include<iostream.h>
#include<conio.h>
#definesize 10
class stack
{
    int tos;
    int item[size];
    int pos;

List of good references for Speech / Speaker Recognition Project

Here is list of good references , that we followed for our final project. These  are also included in reference section of final report. 
After we decided to do final project on joint speech and speaker recognition, we did a lot of research and downloaded almost 2 GB of articles, lecture notes and etc. But, these article(around 30 MB) were really useful to us.
All of them are available on Web for free. Just google it.


  1. Assignment 3: GMM Based Speaker Identification EN2300 Speech Signal Processing, [ www.kth.se/polopoly_fs/1.41342!assignment_03.pdf]
  2. Conrad Sanderson, Automatic Person Verification Using Speech and Face Information - A Dissertation Presented to The School of Microelectronic Engineering Faculty of Engineering and Information Technology, Griffith University, August 2002, [revised February 2003].
  3. Douglas A Reynolds and Richard C Rose, Robust text-independent speaker identification using Gaussian mixture speaker models. IEEE Transactions on Speech and Audio Processing, 3(1):72–83, 1995.
  4. G. Saha, Sandipan Chakroborty, Suman Senapati , A New Silence Removal and Endpoint Detection Algorithm for Speech and Speaker Recognition Applications, Department of Electronics and Electrical Communication Engineering, Indian Institute of Technology, Khragpur, Kharagpur, India.
  5. J P Campbell, Jr. Speaker recognition: A tutorial. Proc. IEEE, 85(9):1437–1462, 1997.
  6. K.R. Aida–Zade, C. Ardil and S.S. Rustamov, Investigation of Combined use of MFCC and LPC Features in Speech Recognition Systems, World Academy of Science, Engineering and Technology, 2006
  7. L. R. Rabiner, “A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition”, vol-77, no. 2, pp. 257-286, 1989.
  8. Lasse L Mølgaard, Kasper W Jørgensen, Speaker Recognition: Special Course; IMM-DTU; 2005
  9. Mohamed Faouzi  BenZeghibaa , Joint Speech and Speaker Recognition,IDIAP  Research  Report, 2005.
  10. Robin Teo Choon Guan @ Myo Thant, Majority Rule- Based Non-Intrusive User Authentication by Speech: Part 2 (Speaker Verification), Thesis, School of Science and Technology, Sim University,2009.
  11. Shi-Huang Chen and Yu-Ren Luo , Speaker Verification Using MFCC and Support Vector Machine, Proceedings of the International Multi Conference of Engineers and Computer Scientists 2009, vol – I, IMECS 2009.
  12. Tomi Kinnunen , Spectral Features for Automatic Text-Independent Speaker Recognition- Licentiate’s Thesis, University of Joensuu, Department of Computer Science, Finland, 2003.
  13. Waleed H. Abdulla and Nikola K. Kasabov, The Concepts of Hidden Markov Model in Speech Recognition, Knowledge Engineering Lab, Department of Information Science, University of Otago,New Zealand, 1999.

save an Android application's state and restore

The savedInstanceState way for saving state associated with a current instance of an Activity, for example - current navigation, selections, unsaved text.. etc, so that if Android destroys and recreates an Activity, it can come back as it was before.

We should override onSaveInstanceState(Bundle savedInstanceState) and write the application state values you want to change to the Bundle parameter like this:

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
  // Save UI state changes to the savedInstanceState.
  // This bundle will be passed to onCreate if the process is
  // killed and restarted.
  savedInstanceState.putBoolean("MyBoolean", true);
  savedInstanceState.putDouble("myDouble", 1.9);
  savedInstanceState.putInt("MyInt", 1);
  savedInstanceState.putString("MyString", "Welcome back to Android");
  // etc.
  super.onSaveInstanceState(savedInstanceState);
}

This stores the values into  Bundle in a NVP ("Name-Value Pair") map, and it will get passed in to onCreate and also onRestoreInstanceState.

Extract the values stored:

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  // Restore UI state from the savedInstanceState.
  // This bundle has also been passed to onCreate.
  boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
  double myDouble = savedInstanceState.getDouble("myDouble");
  int myInt = savedInstanceState.getInt("MyInt");
  String myString = savedInstanceState.getString("MyString");
}

Silence Removal and End Point Detection JAVA Code

For the purpose of silence removal of captured sound, we used the algorithm  in our final year project. In this post, I am publishing the endpoint detection and silence removal code ( implementation of this algorithm in JAVA).

These links might be useful to you as well.
The constructor of following java class EndPointDetection takes two parameters
  1. array of original signal's amplitude data : float[] originalSignal
  2. sampling rate of original signal in Hz : int samplingRate
The Java Code :
package org.ioe.tprsa.audio.preProcessings;

declare global variable in android- example code

To declare global variable in android, you need to 
1) create your own subclass of android.app.Application
2) and then specify that class in the application tag in your manifest. 
Android will automatically create an instance of that class and make it available for your entire application. You can access it from any context using the Context.getApplicationContext() method (Activity also provides a method getApplication() which has the exact same effect):
  • Sub Class of Application :
     public class MyApp extends Application {
           String foo;
      }
  • In the AndroidManifest.xml add android:name
 <application 
     android:icon="@drawable/icon" 
     android:label="@string/app_name" 
     android:name="com.company.MyApp">
  </application>

Full Example :

What's the difference between a primary key and a unique key?

Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where unique creates a non-clustered index by default. Another major difference is that, primary key does not allow NULLs, but unique key allows one NULL only.

What is de-normalization and when would you go for it?

As the name indicates, de-normalization is the reverse process of normalization. It is the controlled introduction of redundancy in to the database design. It helps improve the query performance as the number of joins could be reduced.

What are clustered index and non clustered index


With a clustered index the rows are stored physically on the disk in the same order as the index. There can therefore be only one clustered index.
With a non clustered index there is a second list that has pointers to the physical rows. You can have many non clustered indexes, although each new index will increase the time it takes to write new records.
It is generally faster to read from a clustered index if you want to get back all the columns. You do not have to go first to the index and then to the table.
Writing to a table with a clustered index can be slower, if there is a need to rearrange the data.
In other words,
A clustered index means you are telling the database to store close values actually close to one another on the disk. This has the benefit of rapid scan / retrieval of records falling into some range of clustered index values.


From Wikipedia :
database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of slower writes and increased storage space

Silence Removal and End Point Detection MATLAB Code

Visit http://ganeshtiwaridotcomdotnp.blogspot.com/2011/06/final-report-text-prompted-remote.html for more detail about our project.
For the purpose of silence removal of captured sound, we used the algorithm specified in
"A New Silence Removal and Endpoint Detection Algorithm for Speech and Speaker Recognition Applications"
Our actual system was in JAVA but we verified the performance of this algorithm in MATLAB.

Inputs and Output
Before silence removal
After automatic silence removal
Here is the Matlab code : 
It first records sound for 5 seconds and removes the silence and then plays back.

Logic Design of Digital Clock, assignment on logic circuits

Logic Design of Digital Clock, assignment on logic circuits

Logic Design of Exhibition hall visitor density counter

Logic Design of Exhibition hall visitor density counter

History of UNIX like OS : Assignment Article

History of UNIX Like OS Assignment

Logic Design of 8-bit arithmetic microprocessor : an assignment on CAD

Logic Design of 8-Bit Arithmetic Microprocessor

BlueChess : Two Player Chess Game in J2ME, My minor project @ IOE

Here is the download link for BlueChess : Two Player Chess Game

http://www.4shared.com/file/JWiI8Cce/BlueChess_Bluetooth_two_player.html

XML parsing using SaxParser with complete code

SAX parser use callback function (org.xml.sax.helpers.DefaultHandler) to informs clients of the XML document structure. You should extend DefaultHandler and override few methods to achieve xml parsing.
The methods to override are
  • startDocument() and endDocument() – Method called at the start and end of an XML document. 
  • startElement() and endElement() – Method called at the start and end of a document element.  
  • characters() – Method called with the text contents in between the start and end tags of an XML document element.

The following example demonstrates the uses of DefaultHandler to parse and XML document. It performs mapping of xml to model class and generate list of objects.

Android hide soft keyboard code

Working code for hiding the soft keyboard in Android :

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This can be used to suppress the keyboard until the user actually touched the edittext view.

Java-Open/Launching any file with its default handler with start utility in windows

Java-Open/Launching any file with its default handler with start utility in windows
String cmd = "cmd.exe /c start ";
String file = "c:\\version.txt";
Runtime.getRuntime().exec(cmd + file); 

Android Code: Latitude and Longitude of the mobiledevice


We should use the LocationManager.
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
The call to getLastKnownLocation() doesn't block - which means it will return null if no position is currently available - so you probably want to have a look at passing a LocationListener to therequestLocationUpdates() method instead, which will give you asynchronous updates of your location.
private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        longitude = location.getLongitude();
        latitude = location.getLatitude();
    }
}

lm.requestLocationUpdates(LocationManager.GPS, 2000, 10, locationListener);
Required Permission :
You'll need to give your application the ACCESS_FINE_LOCATION permission if you want to use GPS.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
You may also want to add the ACCESS_COARSE_LOCATION permission for when GPS isn't available and select your location provider with the getBestProvider() method.

My first Android project in Eclipse: Multiplication Table Generator App using TextWatcher and OnClickListener

After removing the configuration errors that came during running the auto generated Hello World project, I decided to write a Multiplication Table Generator App on Android platform. This is my first android app other than HelloWorld. In this article, I am going to explain how I created the App. It describes the use of TextWatcher and OnClickListener interfaces for event handling.

Multiplication Table Generator contains the EditText-ipNumberTxt component for reading user input – a number. It contains two Buttons '+' and '–' to increment/decrement the number in EditText. The generated output is displayed in TextView-outputTXT. The multiplication table is generated on afterTextChanged event of EditText field.

The download link for complete project is given at end of article.

Error Free Android Hello World Project on Eclipse

Removal of two common errors that may arise when running the android project on eclipse.
[ PANIC: Could not open: C:\Users\gTiwari\.android/avd/MyAndAVD.ini ]
and
[ invalid command-line parameter: Files ]

Today I tried to setup the essentials and test a demo project on Eclipse.I installed required tools (Android SDK, ADT, etc) and created a empty project successfully.

I was following these articles :
Installing Android SDK and ADT in eclipse.
Android First HelloWorld App in Eclipse.
But I  got the few errors when I tried run the Hello World project that eclipse created for me.

In this Blog, I am  describing the errors and how I solved them that may be useful for Android beginners like you.

[My System Details : Windows 7(64-bit). Eclipse 3.7 (Indigo).The MyFirstEmul is the name of emulator I created.]

Error #1
When i created a hello world project and tried to run it. I got the following error.
[2011-08-27 18:05:22 - Emulator] PANIC: Could not open: C:\Users\gTiwari\.android/avd/MyAndAVD.ini
Cause : 
The emulator could not found in location "C:\Users\gTiwari\". I searched over my HDD for the emulator I created earlier. And I found it in the  E:\ .android folder. This might be due to I had moved my system folders such as Documents, Desktop, Downloads to E:\.
Solution :
I simply moved the E:\.android folder to C:\Users\gTiwari\ and solved it.

Error #2
After I solved the Error #1, and tried to run the project, I got the following error :
[2011-08-27 18:24:39 - Emulator] invalid command-line parameter: Files.
[2011-08-27 18:24:39 - Emulator] Hint: use '@foo' to launch a virtual device named 'foo'.
[2011-08-27 18:24:39 - Emulator] please use -help for more information
Cause : 
The default installation location is: C:\Programme Files(x86)\Android\android-sdk.  But the  SDK location cannot contain any spaces.
Solution : 
Should I reinstall the Android SDK to new location with no space in folder names ?
Well, that may be a solution. But i found easy solution for this.
I make use of mklink command line utility of NTFS in Windows 7 (in previous versions of the command may be different). I pointed C:\AndroidSDK to the actual C:\Program Files (x86)\Android\android-sdk by using following command.
     MKLINK  /J  C:\AndroidSDK "C:\Program Files (x86)\Android\android-sdk\"
This command created special junction folder C:\AndroidSDK helped me in  redirection.

And I configured this new path(C:\AndroidSDK) to AndroidSDK in Eclipse IDE settings - from
                      Windows -> Preferences -> Android
And run the Hello World project successfully.

See my other posts on  android from : http://ganeshtiwaridotcomdotnp.blogspot.com/search/label/Android 



android get current screen orientation

The current configuration ( orientation as well) can be available from the Resources' Configuration object as:
The return parameter may be one of ORIENTATION_LANDSCAPEORIENTATION_PORTRAIT, or ORIENTATION_SQUARE.



public static int getScreenOrientation(){    
    return getResources().getConfiguration().orientation;
}

check http://developer.android.com/reference/android/content/res/Configuration.html#orientation for details

java android write to sd card

You can access to sd card by File sdCard = Environment.getExternalStorageDirectory();
Note : Hard coding the /sdcard/ folder is not good.


Write to sd card

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdcard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");
FileOutputStream f = new FileOutputStream(file);
...

And read/write to file   by using FileOutputStream f .

Mouse Gesture Recognition with Hidden Markov Model.

Understanding gestures can be posed as a pattern recognition problem. These patterns(gestures) are variable but distinct and have an associated meaning.  Since gesture consists of continuous motion in sequential time, an HMM is an effective recognition tool.

My work is a demonstration of a mouse motion gesture recognition system using Dynamic HMM. It is developed in Java.

Code  Available @ : https://github.com/gtiwari333/mouse-gesture-recognition-java-hidden-markov-model

Main References were : 
DEMO VIDEO 


Redirecting JAVA IO to GUI by Redirecting IO Streams

Here is a small utility program for fun (but useful). It is written in Java  by redirecting IO Streams to GUI.
Its features are:
  • Reading console input from GUI --> No need of Black Screen.
  • Displaying console output (including exceptions) to GUI.
  • Easy to use.
  • Useful for Java Beginners
First lets see the code of test application.

Java Map Comparison- hashmap, linkedhashmap, treemap


Java Map Comparison :
  • HashMap is the fastest map with O(1) search and insertion times.
  • LinkedHashMap is a little slower for inserts, but maintains the insertion order.
  • TreeMap is the slowest map, but lets you iterate over the keys in a sorted order.

Android : Activity and View Understanding

What are Activity and View in Android:
Dissecting HelloAndroid.java - Activity and View

FirstSee this example:

Android: Application Project Structure in Eclipse

The Android project (under Eclipse ADT) consists of several folders:
Android - Project folder structure

  • src: Java Source codes. The Java classes must be kept in a proper package with at least two levels of identifiers (e.g., com.example...).

Android : AndroidManifest.xml description

What is and usage/purpose of androidmanifest.xml file
Android Application Descriptor File - AndroidManifest.xml
Each Android application has a manifest file named AndroidManifest.xml in the project's root directory. It descibes the application components.