Monday, February 3, 2014

Microprocessor 8085

Microprocessors 8085 is one of the earliest microprocessor with wide use in practical applications, though only for learning purposes now. I wish to talk about it's interrupts. It has a total of five interrupts,
i) INTR
ii) RST 5.5
iii) RST 6.5
iv) RST 7.5
v) TRAP

Now there are two fundamentals to be remembered, the interrupts can be disabled and they can be masked there is a difference between the two. When you disable interrupts using the "DI" command ,well they are disabled.
But when you mask any interrupt what basically happens is that the interrupt input is passed through a NAND gate before going to individual flip-flops for each interrupt input. When you mask any interrupt a '0' is passed to NAND thus effectively rendering the output of NAND to '1' when most of the interrupt are edge-triggered or low-level initiated. The masking is done using SIM command. which takes the accumulator value and to set various masks. Every bit in the 8-bit input given to SIM corresponds to masking of a specific interrupt.

One other example I would like to discuss with 8085 is generation of some complex waveform like the sine wave. Unfortunately, calculating each point in the 8085 is cumbersome and roundabout way to precalculate the points and store them in the memory then write a simple program which iterated through the values and displays them.

Hope this helped you learn something more.

Sunday, June 16, 2013

Global Silhouette Matlab

Whenever we cluster we should check the cluster quality but how can we do this ? One of the way to do that is to calculate it's Global Silhouette. It works pretty well for most clustering algorithms.

The basic idea behind global silhouette is what is the quality of separation between the points in one cluster to another cluster's points.

Below is the matlab code for it which uses silhouette() function from matlab .


If you need the code for silhouette or how to calculate s(i) for each data point e-mail me.

Tuesday, May 28, 2013

Matlab Examples

Here is a code for averaging a set of signals, note that my input is taken from a .wav file and thus is of different making it a little more code. This is for who got stuck and can't find a way out.Using the saved .jpeg files you can see how it works visually.



Friday, May 24, 2013

Douglas-Peucker Algorithm

An algorithm for smoothing a 2-d plot . You can read a good explanation of it at wikipedia Wiki Link . Following is the matlab code that I wrote for it:

Wednesday, February 27, 2013

SPOJ:Insertion Sort

The problem asks us to find the number of swaps an insertion sorts does, which in a way is a measure of efficiency of the sort.

The basic logic is answer is the sum of ( for each element the number of elements greater than itself occuring before it .)

One way to implement it is Employ merge sort on it and during each merge operations if you are copying an element from the right array (swaps +=no. of elements in the left array) .

A novice mistake which I made what that I dynamically allocating and de-allocating a temporary array during each merge operation, BEWARE this is a very costly operation and should not be used. Allocate memory once and pass that array .

Saturday, September 1, 2012

Modular Exponentiation

For performing exponentiation we can take the linear route or we can take the binary route. What is the main idea behind it

Suppose you are to calculate ( x^p) mod n

You can do this in a linear fashion and using the following property of modular operations
(a*b) mod n = (a mod n * b mod n) mod n
 but that is O(n) time complexity and we can do better. 

Observe the following
exponential(x,p) = exponential(x,p/2)<<2           // if p is even
                               x*exponential(x,(p-1)/2)<<2 // if p is odd

Now the number of times the functions is called is log2(b), which is a definite improvement over the linear case. But we can still do better by expressing the power in its binary form. Read the following wikipedia article for understanding
right to left binary method

following is C++ code for modular exponentiation .

Here is problem on SPOJ using the above concept http://www.spoj.com/problems/ZSUM/ . 

Comments are welcome.