Posts

Showing posts from 2014

How to create your own Thread Library or Package ?

Image
Hello friends.. 🙂 This special post is for those who want to create thread library/package of their own and don’t know from where to start. So lets begin, and see from where you should start. Threads  often provided in the form of  thread package . Such package contains operations to create and destroy threads as well as operations on synchronization variables such as  mutex  and  condition   variables . There are basically two approaches to implement thread package/library. To create a thread library that is executed entirely in user mode. To create a thread library that is executed in user mode as well as in kernel mode/ using  LWP   (Let the kernel aware of threads and schedule them) Advantages   of   building  user-level thread library : First, it is cheap to create and destroy threads. Because all thread administration is kept in the user’s address space, the price of creating a thread is primarily determined by the cost for allocating memory to set up a thread stack. Analogousl

For storing billions of images, Filesystem or Database ?

If you are thinking about to store million of images and unable to decide which side to go, either store them into database systems such as MySql or on the file system ? Then probably this post will help you. The answer to this question is depend upon the size of images  you   want     to store. If the average size of the images you want to store is less than 10 kb (usually thumbnails only), then its good to go with   database   systems only, most of the database systems with latest updates are useful for this purpose, but if the average size of images is more than that,   then  I  will personally recommend you to use file system for storing images and using database systems for storing paths of those images.Why not to use Database system  for storage and Why to use for storing paths ? Because most of the database systems such as MySql takes more time to process and deliver such data, and you also need to write lots of code for storing and retrieving images to and from the database, wh

NVIDIA Shield a powerful gaming device

Image
           If you want a powerful handheld gaming device (like the PS VITA or Nintendo DS), check out the NVIDIA Shield. It’s like an Xbox Controller with a 5inch, 720 pixels touch screen display fused to it, and it runs on a 1.9GHz Tegra 4 SoC – one of the fastest in market this year and it supports streaming games for your PC. Android games runs spectacularly, even if it lacks a comprehensive game library for now, and shield touted positively for its battery life.   [AMAZONPRODUCTS asin=”B00E3667XQ”]  

8086 program code for drawing star image on screen

; image drawing; demo; * * * * * * * * * *org 0x100icon_width = 16screen_width = 320screen_height = 200jmp startthank_you db ' Thank you! ', 0star_x dw 144star_y dw 84star_colour db 2; * * * * * * * * * *start proc farmov ax, csmov ds, axmov es, axmov ah, 0mov al, 13hint 10hdraw_star:mov bx, star_xmov dx, star_ymov si, starcall puticoninc star_colourmov cx, 10mov dx, 0mov ah, 86hint 15hjmp draw_star; * * * * * * * * * *retstart endp; * * * * * * * * * *; * input: bx = x; * dx = y; * si = imageputicon procmov ax, 0A000hmov es, axmov ax, screen_widthmul dxadd bx, axjnc no_carryinc dxno_carry:mov cx, icon_widthnext_y:push cxmov cx, icon_widthnext_x:mov di, bxmov al, [si]cmp al, 0je transparentmov al, star_colourmov es:[di], altransparent:inc siadd bx, 1jnc no_car_xinc dxno_car_x:loop next_xpop cxadd bx, screen_width-icon_widthjnc no_car_yinc dxno_car_y:loop next_yretputicon endp; * * * * * * * * * *star:db 0,0,0,0,0,0,0,

XML data type in postgreSQL

       The XML data type can be used to store XML data. Its advantage over storing XML data in a text field is that it checks the input values for well-formedness, and there are support functions to perform type-safe operations on it. Use of this data type requires the installation to have been built with  configure –with-libxml .      The xml type can store well-formed “documents”, as defined by the XML standard, as well as “content” fragments, which are defined by the production  XMLDecl ? content in the XML standard. Roughly, this means that content fragments can have more than one top-level element or character node. The expression xmlvalue  IS DOCUMENT  can be used to evaluate whether a particular xml value is a full document or only a content fragment. Creating XML Values To produce a value of type xml from character data, use the function  xmlparse : XMLPARSE ( { DOCUMENT | CONTENT } value ) Examples: XMLPARSE (DOCUMENT ‘<?xml version=”1.0″?><book><title>Manu

Tools for Querying and Transformation on XML data/files

Increasing numbers of applications that use XML to exchange, mediate, and store data, tools for effective management of XML data are becoming increasingly important nowadays. Which leads to increase in demand for tools which provide easier querying and transformation for XML data. In particular, tools for querying and transformation of XML data are essential to extract information from large bodies of XML data, and to convert data between different representations (schemas) in XML. Just as the output of a relational query is a relation, the output of an XML query can be an XML document. As a result, querying and transformation can be combined into a single tool. Following mentioned are some tools/languages which provide facilities for transforming and querying XML data.   Xpath: XPath is a language for path expressions, and is actually a building block for the remaining two query languages. A path expression in XPath is a sequence of location steps separated by “/” (instead of the “.”

TCS code vita questions

I had participated in TCS codevita 2014 and cracked the first round successfully but I was unable to crack 2nd round ,so drop out from the the contest. Following is one of the question asked in TCS CodeVita 2014 , sharing with you. Problem Statement: An ISBN (International Standard Book Number) is a ten digit code that uniquely identifies a book. The first 9 digits are used to represent the book and the 10th digit is used to ensure that the ISBN is correct. To validate the ISBN number, calculate a sum that is 10 times the first digit plus 9 times the second digit plus 8 times the third digit … all the way until you add 1 times the last digit. If the sum is divisible by 11, then the 10 digit code is a valid ISBN number. For example 1111456291 is a valid ISBN, because 10*1 + 9*1 + 8*1 + 7*1 + 6*4 + 5*5 + 4*6 + 3*2 + 2*9 + 1*1 = 132 which is divisible by 11. Each of the first nine digits can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten. This

Basic things that every TCS CodeVita participant must know

Rules You know that c odevita is a team contest with team size 2. As a team you get 6 hrs to solve the problems. If both team members’ login at same time they will get 6 hrs each. Submissions CodeVita will consider team scores. You should choose a strategy that will maximize your chances of solving maximum problems. You know that you have a chance to make unlimited submissions in any of the 7 languages that the system supports. Supported languages are C, C++, C#, Java, Perl, Python and Ruby . You can attempt a single problem in any number of languages as you wish. So lets say you started solving a problem in C and a few submissions later you feel that this problem is better solved in Java, you can do that. Your target should be to get your submission in “Accepted” state.   Compilers and IDEs  : You know that you have to write code on your machine and submit the code file as a File Upload to the CodeVita web application. You know that CodeVita uses the following language versions  

Introduction to WEKA tool

    WEKA (Waikato Environment for Knowledge Analysis) is a collection of machine learning algorithms for data mining tasks. The algorithms can either be applied directly to a dataset or called from Java code. WEKA contains tools for data pre-processing, classification, regression, clustering, association rules, and visualization. It is also well-suited for developing new machine learning schemes. The name WEKA is derived from a flightless bird with an inquisitive nature. WEKA is open source software issued under the GNU General Public License. WEKA tool can also be use for with Big Data analysis. Since WEKA is freely available for download and offers many powerful features (sometimes not found in commercial data mining software), it has become one of the most widely used data mining systems. Nowadays WEKA also became one of the favorite vehicles for data mining research and helped to advance it by making many powerful features available to all. In data and web mining following are the

Code to print sin, cos, tan and square wave is scilab software using subplot function

Image
a=input(“Enter amplitude”); t=0:0.001:1; y=a*cos(2*%pi*10*t); subplot(4,1,1); plot(t,y);p=a*sin(2*%pi*10*t); subplot(4,1,2); plot(t,p); d=a*squarewave(2*%pi*10*t); subplot(4,1,3) plot(t,d); f=a*tan(2*%pi*10*t); subplot(4,1,4); plot(t,f); Click Here For More Information About Scilab

What happens when executing program tries to change its text section ?

 If a process mistakenly attempts to overwrite its text space, it incurs a protection fault that typically results in termination of the process. For example, the program in shown below assigns the pointer ip to the address of the function f() and then arranges to catch all signals. If the program is compiled so that text and data are in separate regions, the process executing the program incurs a protection fault when it attempts to write the contents of ip , because it is writing write-protected text region. The kernel sends a SIGBUS signal to the process on an AT&T 3820 computer, although other implementations may send other signals. The process catches the signal and exits without executing the print statement in main. However, if the program were compiled so that the program text and data were part of one region (the data region), the kernel would not realize that a process was overwriting the address of the function f. The address off contains the value 1! The process execu

Cross database queries in pgAdmin–III

pgAdmin do not provide direct support for cross database queries, but we can achieve results similar to such queries by using two extensions provided with pgAdmin (9.3.*)    1. Dblink    2. Foreign data wrapper (FDW) I found FDW easy to use as compared to Dblink, so we will be discussing FDW extension here, consider following Example: Suppose that we have table employee with schema employee ( eid, name, location, salary,dob, dept) Say for security reasons salary information for employees needs to be maintained at Company Headquarter Server located in Mumbai. Now to solve the above problem statement we need to write cross database queries on server located at Mumbai and after that once we found main table employee to be accessible on the Mumbai’s server then we can create materialized view, which will be containing only salary attribute of main employee table.Following are the queries and steps to solve above problem 1. Creating FDW extension with CREATE EXTENSION postgres_fdw; 2. Crea

Mono-alphabetic Cipher Implementation - C Tutorial

A mono-alphabetic cipher is a type of simple substitution cipher. In this cipher technique each letter of the plaintext is replaced by another letter in the cipher-text. An example of a mono-alphabetic cipher key follows:   Plain Text   >>>   a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z Cipher Text >>>  z  w  x  y  o  p  r  q  a  h  c  b  e  s  u  t  v  f  g  j  l  k  m  n  d  i   This key means that any ‘a’ in the plaintext will be replaced by a ‘z’ in the cipher-text, any ‘z’ in the plaintext will be replaced by a ‘i’ in the cipher-text, and so on. The following program shows the simple implementation of mono-alphabetic cipher technique in c language for encrypting and decrypting file   [crayon ] #include <stdio.h> #include <string.h> #define FILE_NAME_MAX 30 extern char alpha[26][2]={ {‘a’,’z’},{‘b’,’w’},{‘c’,’x’},{‘d’,’y’},{‘e’,’o’} ,{‘f’,’p’},{‘g’,’r’},{‘h’,’q’},{‘i’,’a’},{‘j’,’h’}, {‘k’,’c’},{‘l’,’b’},{‘m’,’e’},{‘n’,’s

Prime number program code in Scilab

x=input("Enter any number ");flag=0;for i = 2:(x-1) if(modulo(x,i)==0) then flag=1; break; end;endif(flag==1) then disp("not prime number");else disp("prime number");end;

Code for checking Palindrome string in Scilab

x=input("Enter a string ",["string"]);y=strrev(x);if (x==y) thendisp("Palindrome string");else disp("Not palindrome string");end;

Changing routing table entries on windows operating system

To change the routing table entries on windows operating system we need to use “route” command. In windows operating system, “route” is a command-line utility used to view and manipulate the TCP/IP routing tables. Manual manipulation of the routing table is characteristic of static routing i.e., if we are manipulating routing tables using “route” command then we are doing static routing not dynamic routing. To see details about “route” command simply type “route” on cmd as shown below: C:\Users\Dell>route This will display following information: ROUTE [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC metric] [IF interface] -f Clears the routing tables of all gateway entries. If this is used in conjunction with one of the commands, the tables are cleared prior to running the command. -p When used with the ADD command, makes a route persistent across boots of the system. By default, routes are not preserved when the system is restarted. Igno

How much memory does a namenode need?

    A namenode can eat up memory, since a reference to every block of every file is maintained in memory. It’s difficult to give a precise formula, since memory usage depends on the number of blocks per file, the filename length, and the number of directories in the filesystem; plus it can change from one Hadoop release to another. The default of 1,000 MB of namenode memory is normally enough for a few million files, but as a rule of thumb for sizing purposes you can conservatively allow 1,000 MB per million blocks of storage.    You can increase the namenode’s memory without changing the memory allocated to other Hadoop daemons by setting HADOOP_NAMENODE_OPTS in hadoop-env.sh to include a JVM option for setting the memory size. HADOOP_NAMENODE_OPTS allows you to pass extra options to the namenode’s JVM. So, for example, if using a Sun JVM, -Xmx2000m would specify that 2,000 MB of memory should be allocated to the namenode.    If you change the namenode’s memory allocation, don’t forge

What Constitutes Progress in MapReduce?

     Progress is not always measurable, but nevertheless it tells Hadoop that a task is doing something. For example, a task writing output records is making progress, even though it cannot be expressed as a percentage of the total number that will be written, since the latter figure may not be known, even by the task producing the output. Progress reporting is important, as it means Hadoop will not fail a task that’s making progress. All of the following operations constitute progress: Reading an input record (in a mapper or reducer) Writing an output record (in a mapper or reducer) Setting the status description on a reporter (using Reporter’s setStatus() method) Incrementing a counter (using Reporter’s incrCounter() method) Calling Reporter’s progress() method

Setting User Identity (Hadoop)

    The user identity that Hadoop uses for permissions in HDFS is determined by running the whoami command on the client system. Similarly, the group names are derived from the output of running groups.     If, however, your Hadoop user identity is different from the name of your user account on your client machine, then you can explicitly set your Hadoop username and group names by setting the hadoop.job.ugi property. The username and group names are specified as a comma-separated list of strings.     You can set the user identity that the HDFS web interface runs as by setting dfs.web.ugi using the same syntax. By default, it is webuser,webgroup, which is not a super user, so system files are not accessible through the web interface. Notice that, by default, there is no authentication with this system.

Which Compression Format Should I Use for HDFS?

     Which compression format you should use depends on your application. Do you want to maximize the speed of your application or are you more concerned about keeping storage costs down? In general, you should try different strategies for your application, and benchmark them with representative data-sets to find the best approach. For large, unbounded files, like log files, the options are: Store the files uncompressed. Use a compression format that supports splitting, like bzip2 (although bzip2 is fairly slow), or one that can be indexed to support splitting, like LZO. Split the file into chunks in the application and compress each chunk separately using any supported compression format. In this case, you should choose the chunk size so that the compressed chunks are approximately the size of an HDFS block. Use Sequence File, which supports compression and splitting. Use an Avro data file, which supports compression and splitting, just like Sequence File, but has the added advantage

Compilers vs. Interpreters

       There are two general methods by which a program can be executed. It can be compiled, or it can be interpreted. Although programs written in any computer language can be compiled or interpreted, some languages are designed more for one form of execution than the other. For example, Java was designed to be interpreted, and C was designed to be compiled. However, in the case of C, it is important to understand that it was specifically optimized as a compiled language. Although C interpreters have been written and are available in some environments, C was developed with compilation in mind. Therefore, you will almost certainly be using a C compiler and not a C interpreter when developing your C programs.      Since the difference between a compiler and interpreter may not be clear to all readers, the following brief description will clarify matters. In its simplest form, an interpreter reads the source code of your program one line at a time, performing the specific instructions co

Preventing Brute Force Attack

A brute force attack is an attempt to log into a secure system by making lots of attempts in the hopes of eventual success.Brute force is also a algorithm design approach/technique in Computer Science. It’s not a sophisticated type of attack, hence the name “brute force.” For example, if you have a login process that requires a username and password, there is a limit as to the possible number of username/password combinations. That limit may be in the billions or trillions, but still, it’s a finite number.    Using algorithms and automated processes, a brute force attack repeatedly tries combinations until they succeed. The best way to prevent brute force attacks from succeeding is requiring users to register with good, hard-to-guess passwords: containing letters, numbers, and punctuation; both upper and lowercase; words not in the dictionary; at least eight characters long, etc. Also, don’t give indications as to why a login failed: saying that a username and password combination isn

Auto proxy changer application code in VB .Net

Image
The code given here is for making simple app in VB .Net which will read a proxy address from file specified in path field and then automatically change the proxy settings of PC to next proxy address from file after specified time amount. Note that file contains list of proxy addresses with port number in format as given below 0.0.0.0:80 1.1.1.1:8080 …………… ……………. i.e., ip address and port number. Form1.vb ----------------------------------------------------------------------------------Imports SystemImports System.Runtime.InteropServicesImports System.IOImports Microsoft.VisualBasicImports System.TimersPublic Class Form1    Dim FILE_NAME As String = "C:UsersDellDocuments12.txt"    Dim label As String    Public proxy(2000) As String    Public index As Integer = 0    Public max_proxys As Integer=0    Dim a As String    Dim start_check As Integer = 0    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load           End Sub    Priv

Code for setting webview in android

/*WebViewActivity.java*/package com.shubham.webviewclientdemo;import android.app.Activity;import android.graphics.Bitmap;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.ProgressBar;/* * Demo of creating an application to open any URL inside the application and clicking on any link from that URlshould not open Native browser but  that URL should open in the same screen.- Load WebView with progress bar */public class WebViewClientDemoActivity extends Activity {    /** Called when the activity is first created. */       WebView web;    ProgressBar progressBar;    StartAppAd startAppAd;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        web = (WebView) findViewById(R.id.webview01);        progressBar = (ProgressBar) findViewById(R.id.progressBar1);        web.setWebViewCl

Matlab code to convert image to binary numbers and convert back to original

% Reading image fileim=imread('C:UsersDellPictures17.jpg');   % converting image to binary numbersc=dec2bin(im,8);% saving result to filefid = fopen('magic5.txt', 'w+');fwrite(fid,c); fclose(fid);disp(c);%converting image back to decimal and displaying it.d=reshape(uint8(bin2dec(c)),size(im) );image(d); [AMAZONPRODUCTS asin=”0470767855″]

PHP code to delete all files in folder

<?php$files = glob('images/*'); // get all file namesforeach($files as $file){ // iterate files  if(is_file($file))    unlink($file); // delete file}?>  

Code for handling exceptions in C++

#include <iostream>using namespace std;double division(int a, int b){   if( b == 0 )   {      throw "Division by zero condition!";   }   return (a/b);}int main (){int x,y;double z;cout<<"Enter value of x and yn";cin>>x>>y;   try    {     z = division(x, y);     cout << z<<"n";    }catch (const char* msg){     cout << msg << endl;   }   return 0;}    

Program code demonstrating use of abstract class in C++

#include<iostream>using namespace std;class abstractinterface {   public:   virtual void numbers()=0;   void input();   int a, b; };void abstractinterface::input()  {    cout<< "Enter the numbersn";    cin>>a>>b;  }class add : public abstractinterface {  public:  void numbers()   {     int sum;     sum=a+b;     cout<<"sum is "<<sum<<"n";   } };class sub : public abstractinterface {   public:   void numbers()    {     int diff;     diff=a-b;     cout<<"diff is "<<diff<<"n";    } };int main() {  add obj1;  obj1.input();  obj1.numbers();  sub obj2;  obj2.input();  obj2.numbers();return 0; }  

Simple visitor counter in php

<?php    $file = file_get_contents("count.txt");    $visitors = $file;    $visitorsnew = $visitors+1;    $filenew=fopen("count.txt","w");    fwrite ($filenew,$visitorsnew);    echo "you've had $visitorsnew visitors.";    ?>  

PHP code for handling file uploads

<?php//properties of the uploaded file$name= $_FILES["myfile"]["name"];$type= $_FILES["myfile"]["type"];$size= $_FILES["myfile"]["size"];$temp= $_FILES["myfile"]["temp_name"];$error= $_FILES["myfile"]["error"];if ($error > 0)    die("Error uploading file! code $error.");else   {    if($type=="image/png" || $size > 2000000)//condition for the file    {    die("Format  not allowed or file size too big!");    }    else    {     move_uploaded_file($temp, "uploaded/" .$name);     echo "Upload complete!";     }}?>  

Simple user registration code in php using md5 encryption for password encryption.

  <?php       echo "<h1> Register</h1>";    $submit = $_POST['submit'];    //form data    $fullname = strip_tags($_POST['fullname']);    $username = strtolowe(strip_tags($_POST['username ']));    $password = strip_tags($_POST['password ']);    $repeatpassword =strip_tags($_POST['repeatpassword ']);    $date = date("y-m-d");          if($submit)    {        $connect = mysql_connect ("localhost","root","");        mysql_select_db("phplogin");        $namecheck = mysql_query("SELECT username FROM users WHERE username ='$username'");           $count = mysql_num_rows($namecheck);               if($count!=0)            {            die("Username already taken!");            }     // check for existance               if($fullname && $username && $password && $repeatpassword)        {                       if($password == $repea

C program demonstrating use of pipe system call in linux (sending message from child process to parent process)

#include <sys/wait.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>intmain(int argc, char *argv[]){int pipefd[2];pid_t cpid;char buf[30];if (pipe(pipefd) == -1) {printf("pipe error");exit(EXIT_FAILURE);}cpid = fork();if (cpid == -1) {printf("fork error");exit(EXIT_FAILURE);}if (cpid == 0) { /* Child reads from pipe */char buffer2[30]="message from child";printf("nnNow in child processn");close(pipefd[0]); /* Close unused write end */write(pipefd[1], buffer2, sizeof(buffer2));close(pipefd[1]);_exit(EXIT_SUCCESS);} else {printf("nnNow in parent process n");wait(NULL);close(pipefd[1]); /* Close unused read end */read(pipefd[0], buf, sizeof(buf));printf("nnNow again in parent process n");printf("nn%snn",buf);close(pipefd[0]);/* Wait for child */exit(EXIT_SUCCESS);}}   Output : dell@linuxmint ~ $ gcc pipe.c dell@linuxmint ~ $ ./a.out Now in parent process Now in c

C program to demonstrate use of fork and wait system call in linux

/*Here we read a number from parent process send it to the child process and then child process calculates factorial of that number and returns to the parent process which then prints the final answer*/#include <sys/wait.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>main( ){int num;int fact=1;int pid, w=1;int status;printf("Enter any number....nn");scanf("%d",&num);printf("n");pid = fork();if (pid == -1) {printf("nError Occured in Forking a Process..n");exit(0);}if (pid==0) { /* Code executed by child */printf("nnChild PID is %ldnn", (long) getpid());/* Wait for signals */int i=0;if(num==0||num==1){fact=1;exit(fact);}else{for(i=1;i<=num;i++){fact = fact * i;//printf("fact= %d",fact);}printf("n Child Execution Completed...n");exit(fact);}}else {/* Code executed by parent */wait(&w);printf("n W= %d",w);int f=WEXITSTATUS(w);printf("nNow in parentnn");pri

C program demonstrating use of signal and alarm system call and signal handler function

#include<stdio.h>#include<signal.h>#include<stdlib.h>typedef void (*sighandler_t)(int);void signal_handler(int signum){printf("nn Sorry Time Outnn");exit(0);}int main(){char uname[20],passwd[20];signal(SIGALRM, signal_handler);printf("nEnter your Username and Password");alarm(10);scanf("%s %s",uname,passwd);printf("nnUsername: %s n Password:%s n You Have Logged In Successfully.. ",uname,passwd);return 0;}  

C program demonstrating use of stat system call

#include<stdio.h>#include <sys/types.h>#include <dirent.h>#include <sys/stat.h>#include <unistd.h>#include <string.h>#include <time.h>#include <stdlib.h>#define DIR1 "test/"const char dir[20]="test/";/* struct dirent {ino_t d_ino; // inode numberoff_t d_off; // offset to the next direntunsigned short d_reclen; // length of this recordunsigned char d_type; // type of file; not supportedby all file system typeschar d_name[256]; // filename};   struct stat {dev_t st_dev; // ID of device containing fileino_t st_ino; // inode numbermode_t st_mode; // protectionnlink_t st_nlink; // number of hard linksuid_t st_uid; // user ID of ownergid_t st_gid; // group ID of ownerdev_t st_rdev; // device ID (if special file)off_t st_size; // total size, in bytesblksize_t st_blksize; // blocksize for file system I/Oblkcnt_t st_blocks; // number of 512B blocks allocatedtime_t st_atime; // time of last accesstime_t st_mtime; // time of last

MATLAB code for Circular Convolution using Matrix method

Image
% circular convolution using matrix method %clc;x=[1,2,3,1];h=[4,3,2,2];H=zeros(0);h_index=1;N=length(x);y=zeros(0);disp('x(n)=');disp(x);disp('h(n)=');disp(h);subplot(4,1,1);stem(x);title('Signal One : x(n) ');subplot(4,1,2);stem(h);title('Signal Two : h(n)');temp=0;for i=1:NH(i,1)=h(i);end;for i=2:N    h=circshift(h, [0,1]);    for j=1:N     H(j,i)= h(j);   end;end;disp('H =>>');disp(H);for i=1:N    for j=1:N        temp=temp+H(i,j)*x(j);    end;    y(i)=temp;    temp=0;end;disp('Circular Convolution : y(m)==>');disp(y);subplot(4,1,3);stem(y);title('Circular Convolution: y(m)');   Output:

Circular Convolution using DFT and IDFT ( W4 Matrix )

Image
% W4 circular_convolution_using_dft_idft clc; x1=[1,2,3,4]; x2=[1,1,1,0]; N=4;   disp('x1(n)='); disp(x1); disp('x2(n)='); disp(x2);     % finding dft of x1 % x1k=zeros(); w4=zeros(); for i=0:N-1 for j=0:N-1 w4(i+1,j+1) = exp(complex(0,(-2*pi*i*j)/4)); end; end;   fprintf('W %d Matrix =',N); disp(w4); temp=zeros(); for i=1:N for j=1:N temp=temp+(w4(i,j).*x1(j)); end;   x1k(i)=temp; temp=0; end; disp('x1(k) = ') disp(x1k);       % finding dft of x2 % x2k=zeros(); temp=zeros(); for i=1:N for j=1:N temp=temp+(w4(i,j).*x2(j)); end;   x2k(i)=temp; temp=0; end; disp('x2(k) ='); disp(x2k);     % multiplying obtained DFT outputs X1(K)*X2(K) % Y_K=zeros(); for i=1:N Y_K(i)=x1k(i)*x2k(i); end; disp('Y(K) ='); disp(Y_K);     %finding IDFT Y(K) that is output of %circular conv.   %computing complex conjugate of w8 w4=conj(w4); disp('complex conjugate of w4'); disp(w4); y_m=zeros(); temp=zeros(); for i=1:N for j=1:N temp=temp+(1/4*(w4(i,j).*Y_

Circular convolution using IDFT and DFT ( using W8 matrix )

Image
% W8 circular_convolution_using_dft_idft%clc;x1=[1,1,1,0,0,0,0,0];x2=[0,1,2,2,1,0,0,0];N=8; % finding dft of x1 %x1k=zeros();w8=zeros(); for i=0:N-1for j=0:N-1w8(i+1,j+1) = exp(complex(0,(-2*pi*i*j)/N));end;end;fprintf('W %d Matrix =',N);disp(w8);  temp=zeros();for i=1:Nfor j=1:Ntemp=temp+(w8(i,j)*x1(j));end;x1k(i)=temp;temp=0;end; disp('x1(k) = ')disp(x1k);  % finding dft of x2 %x2k=zeros();temp=zeros();for i=1:Nfor j=1:Ntemp=temp+(w8(i,j)*x2(j));end;x2k(i)=temp;temp=0;end;disp('x2(k) =');disp(x2k);   % multiplying obtained DFT outputs X1(K)*X2(K) %Y_K=zeros();for i=1:NY_K(i)=x1k(i)*x2k(i);end;disp('Y(K) =');disp(Y_K);   %finding IDFT Y(K) that is output of circular conv.% %computing complex conjugate of w8w8=conj(w8);  disp('complex conjugate of w8');disp(w8);  y_m=zeros();temp=zeros();for i=1:Nfor j=1:Ntemp=temp+((1/N)*(w8(i,j)*Y_K(j)));end; y_m(i)=temp;temp=0;end;disp('y_m=');disp(y_m);  %plottingsubplot(3,2,1);stem(x1);title('x1(

MATLAB code for making simple calculator with GUI

function varargout = gui(varargin) % GUI M-file for gui.fig% GUI, by itself, creates a new GUI or raises the existing% singleton*. % H = GUI returns the handle to a new GUI or the handle to% the existing singleton*. % GUI('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in GUI.M with the given input arguments. % GUI('Property','Value',...) creates a new GUI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before gui_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to gui_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help gui % Last Modified by GUIDE v2.5 21-Apr-2014 11:36:48 % Begin initialization code - DO NOT EDIT  g

How incore inodes are allocated ?

Hello friends I am beginning this discussion by assuming that you knows the few basics of OS (UNIX) especially about kernel and its working, so let’s start the discussion. The kernel identifies particular inodes by their file system and inode number and allocated incore inode at the request of higher level algorithms, here higher level algorithms means we are considering some abstract levels so higher level means above the current abstract level. The OS kernel uses algorithm  iget  to allocate incore copy of inode, the kernel maps device number and inode number into hash queue and searches the queue for the inode if it cannot find the inode, it allocates one from the free list and locks it. After that kernel prepares, read the disk copy of the newly accessed inode into incore copy. It already knows the inode number and logical device and computes the logical disk block that contains the inode according to how many disk inodes that fits into the disk block. The computation is followed b