Sunday, 11 August 2013

Music Player with Hand Gesture Control using Neural Network

Hello guys, I have already posted an article on hand gesture recognition using neural network,if you have not see it then please go through it first.Well,here is the Link 

So,using the previous implementation I am now going to show you how you can built a Music Player that will be controlled by hand gestures.That means there will be a separate predefined gesture for performing every individual task that will be performed on the player.

That means there will be an unique gesture for Play,another for pause and so on.


So here are the steps using which you can built it easily :

1. I hope you are all familiar with Matlab GUI,if not then please see this Link 

2. Now here I am not going to briefly explain how to play and pause music in matlab,here my main focus is to tell you how can you control this using hand gestures.

Still,if any one has any problem in building the music player he or she can tell his or her problem through comment,then I will post the code for that later.

3. For example lets assume we use the following gesture for play action.





Then we have to get at least 5-10 pic like this and save it into a folder.

4.  Now train the network with the sample picture,so that when ever any similar gesture is detected during testing,then system would perform some task.

For code reference,please visit this link below :

Gesture Recognition using Neural Network

5.Now the point is where to insert the code. Well for every recognition system we go for a threshold value to determine whether it is the desired result.In the previous Hand gesture recognition system post also I have done the same in the end.

So insert the desired music player action code within that MATCH_FOUND code block.
like this,

if(PLAY_IMG_MATCH_FOUND==TRUE)
{
  //Music player play code
}

Similarly if you want to perform any hard ware related task then just go to this link  and insert the code in the same block as I mentioned before.

Just for example,I have shown this one example PLAY action with this sample images and one gesture.

You can use different gestures for performing different task like PAUSE,STOP etc.

There are lot more things to do with this project...try it yourself, and please let me know about your new works...best of luck...thanks for visiting,have lots of fun :)

Sunday, 4 August 2013

Gesture Recognition using Neural Network in MATLAB Code Part 3

preprocess_gesture.m 

If you have not seen previous post then please go through it first then come back   go to Previous Part


Create a Menu

clc
F = MENU('Choose a database set','Test Set','Train Set'); 
if F==1
K = MENU('Choose a file','Test O');

FOR TESTING A DATASET

if K == 1
    loop=5 
    for i=1:loop 
       string = ['test\O\' num2str(i) '.tif']; 
       Rimages{i} = imread(string); 
    end 

 end 
 end 
end;

FOR TRAINING


if F==2 
    loop=3    %Set loop to 3. All train sets have 3 images 
    L = MENU('Choose a file','Train O'); 
if L == 1 

    for i=1:loop 
    string = ['train\O\' num2str(i) '.tif']; 
    Rimages{i} = imread(string); 
    end
end 
end 

Now do what I am doing here


T{i}=imresize(Timages{i},[150,140]); 

    x = [0 -1 1];                               
    y = [0 1 -1]';

dx{i} = convn(T{i},x,'same');
dy{i} = convn(T{i},y,'same');
gradient{i} = dy{i} ./dx{i};
theta{i} = atan(gradient{i});
cl{i}= im2col(theta{i},[1 1],'distinct');
 N{i} = (cl{i}*180)/3.14159265359; .
c1{i}=(N{i}>0)&(N{i}<10 div="" nbsp="">
    s1{i}=sum(c1{i}); 

    c2{i}=(N{i}>10.0001)&(N{i}<20 div="" nbsp="">
    s2{i}=sum(c2{i}); 

    c3{i}=(N{i}>20.0001)&(N{i}<30 div="" nbsp="">
    sum(c3{i}); 
    s3{i}=sum(c3{i}); 

    c4{i}=(N{i}>30.0001)&(N{i}<40 div="" nbsp="">
    sum(c4{i}); 
    s4{i}=sum(c4{i}); 

    c5{i}=(N{i}>40.0001)&(N{i}<50 div="" nbsp="">
    sum(c5{i}); 
    s5{i}=sum(c5{i}); 

    c6{i}=(N{i}>50.0001)&(N{i}<60 div="" nbsp="">
    sum(c6{i}); 
    s6{i}=sum(c6{i}); 

    c7{i}=(N{i}>60.0001)&(N{i}<70 div="" nbsp="">
    sum(c7{i}); 
    s7{i}=sum(c7{i}); 

    c8{i}=(N{i}>70.0001)&(N{i}<80 div="" nbsp="">
    sum(c8{i}); 
    s8{i}=sum(c8{i}); 

    c9{i}=(N{i}>80.0001)&(N{i}<90 div="" nbsp="">
    sum(c9{i}); 
    s9{i}=sum(c9{i}); 

    c10{i}=(N{i}>90.0001)&(N{i}<100 div="" nbsp="">
    sum(c10{i}); 
    s10{i}=sum(c10{i}); 

    c11{i}=(N{i}>-89.9)&(N{i}<-80 div="" nbsp="">
    sum(c11{i}); 
    s11{i}=sum(c11{i}); 
    c12{i}=(N{i}>-80.0001)&(N{i}<-70 div="" nbsp="">
    sum(c12{i}); 
    s12{i}=sum(c12{i}); 

    c13{i}=(N{i}>-70.0001)&(N{i}<-60 div="" nbsp="">
    sum(c13{i}); 
    s13{i}=sum(c13{i}); 

    c14{i}=(N{i}>-60.0001)&(N{i}<-50 div="" nbsp="">
    sum(c14{i}); 
    s14{i}=sum(c14{i}); 

    c15{i}=(N{i}>-50.0001)&(N{i}<-40 div="" nbsp="">
    sum(c15{i}); 
    s15{i}=sum(c15{i}); 

    c16{i}=(N{i}>-40.0001)&(N{i}<-30 div="" nbsp="">
    sum(c16{i}); 
    s16{i}=sum(c16{i}); 

    c17{i}=(N{i}>-30.0001)&(N{i}<-20 div="" nbsp="">
    sum(c17{i}); 
    s17{i}=sum(c17{i}); 

    c18{i}=(N{i}>-20.0001)&(N{i}<-10 div="" nbsp="">
    sum(c18{i}); 
    s18{i}=sum(c18{i}); 

    c19{i}=(N{i}>-10.0001)&(N{i}<-0 .0001="" div="" nbsp="">
    sum(c19{i}); 
    s19{i}=sum(c19{i}); 

    D{i}= [s1{i} s2{i} s3{i} s4{i} s5{i} s6{i} s7{i} s8{i} s9{i} s10{i} s11{i} s12{i} s13{i} s14{i} s15{i} s16{i} s17{i} s18{i} s19{i}]; 

close(w);

Guys thanks for visiting my blog,Have fun :)


This is the end of gesture recognition


Please LIKE and COMMENT...


Gesture Recognition using Neural Network in MATLAB Code Part 2

neuralnetwork_gesture.m

Go to First Part                             Go to Next Part



echo on
clc
pause
clc

Store the training informations in a test file

fid = fopen('train.txt','rt');
P1 = fscanf(fid,'%f',[19,inf]);
P=P1;

Open some text file using code to write and fetch the required information about image.


fid = fopen('testO.txt','rt');
TS1 = fscanf(fid,'%f',[19,inf]);

%(As here we are only testing alphabet 'O')

fid = fopen('target8.txt','rt');
T = fscanf(fid,'%f',[8,inf]);

It has been found that the optimal number of neurons for  the hidden layer is 85

S1 = 85;
S2 = 5;

Now we have to initialize pre-processing layer

[W1,b1] = initp(P,S1);

We also have to initialize learning layer

 [W2,b2] = initp(S1,T);

pause 

NOW TRAIN THE NETWORK


A1 = simup(P,W1,b1);
TP = [1 500]; 
pause
clf reset
figure(gcf)

% resize the frame size
setfsize(600,300);

[W2,b2,epochs,errors] = trainp(W2,b2,A1,T,TP);

pause
clc 

ploterr(errors); 


pause

M = MENU('Choose a file resolution','Test O');    %as we are only showing 'O',you can add more
if M == 1 
 TS = TS1;
else 
 disp('Wrong input');

a1 = simup(TS,W1,b1);        

a2 = simup(a1,W2,b2)      

echo off 

Next part will be posted in next Post,Thanks for visiting have fun

Gesture Recognition using Neural Network in MATLAB 


Gesture Recognition using Neural Network in MATLAB Code

Hi guys,many people were requesting for gesture recognition code so here it is ...
Well for any recognition system there are some simple common states what we also followed here they are:


1. First you have to have data set.Which you have to prepare or download from any website according to your demand.Like you want to want to recognize an alphabet 'O'.Then you have to provide particular data set for 'O'.


Like this :



Okey this is only one picture but I recommend at least 5 pictures you have to give to recognize a gesture.


2. Now give matlab access to the data sets providing particular path of the folder on your system,it is better to make different folder for different alphabet sample.


3. Now you have to train the network.I will show you how to do it in later part.It is the most important part,here you are making your network understand that " ANY IMAGE LIKE-THIS IS ALPHABET 'O' "


4.Here you need to provide an algorithm that will set such a threshold value that will decide whether the test image is 'O' or NOT.


5.Now you need some more sample of 'O' to test the network whether it is coming fine.


6.Well that is it. I will give you the sample code in my next post so that it will be easy for you to implement.


Proceed to Next Part


Thanks a lot for visiting have fun.









Sunday, 14 April 2013

People Counting System using face detection Code





close all;
clear all;
clc;
rgbInputImage = imread('photo.jpg');
labInputImage = applycform(rgbInputImage,makecform('srgb2lab'));
Lbpdfhe = fcnBPDFHE(labInputImage(:,:,1));
labOutputImage = cat(3,Lbpdfhe,labInputImage(:,:,2),labInputImage(:,:,3));
rgbOutputImage = applycform(labOutputImage,makecform('lab2srgb'));
figure, imshow(rgbInputImage);
figure, imshow(rgbOutputImage);
img=rgbOutputImage;
final_image = zeros(size(img,1), size(img,2));
if(size(img, 3) > 1)
for i = 1:size(img,1)
for j = 1:size(img,2)
R = img(i,j,1);
G = img(i,j,2);
B = img(i,j,3);
if(R > 92 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
final_image(i,j) = 1;
end
end
end
end
end
end
binaryImage=im2bw(final_image,0.6);
figure, imshow(binaryImage);
binaryImage = imfill(binaryImage, 'holes');
figure, imshow(binaryImage);
binaryImage = bwareaopen(binaryImage,1890);
figure,imshow(binaryImage);
labeledImage = bwlabel(binaryImage, 8);
blobMeasurements = regionprops(labeledImage, final_image, 'all');
numberOfPeople = size(blobMeasurements, 1)
imagesc(rgbInputImage); title('Outlines, from bwboundaries()');
hold on;
boundaries = bwboundaries(binaryImage);
for k = 1 : numberOfPeople
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
imagesc(rgbInputImage);
hold on;
title('Original with bounding boxes');
for k = 1 : numberOfPeople
thisBlobsBox = blobMeasurements(k).BoundingBox;
x1 = thisBlobsBox(1);
y1 = thisBlobsBox(2);
x2 = x1 + thisBlobsBox(3);
y2 = y1 + thisBlobsBox(4);
x = [x1 x2 x2 x1 x1];
y = [y1 y1 y2 y2 y1];
plot(x, y, 'LineWidth', 2);
end                          


fcnBPDFHE() function should be added

avialable in mathworks website link is here :



Used image URL : 








Sunday, 7 April 2013

Silent Password Creation using matlab

Here we are going to create silent password.We can do this using both from a video file or from live streaming.The main thing is that he camera should focus on the lip.It should track the lip movement.The key idea is that we are going to take a threshold value,using that particular value we are going to check whether the password is wrong or right.We will track the lip movement,if the movement is beyond threshold then wrong password otherwise right.



Well here are the steps we need to do to create a silent password with matlab :

1.Take video of lip movement or record using webcam.

2.Now use a detection algorithm algorithm from here
(Note : if you are using live detection you need to track the motion using another method,that code is also available in this blog,here is the link.

3.Now what you need to do is that you need to set the threshold value.

Threshold value :

Now the threshold value can be set or generated in many ways.I have done it in one way what i am going to tell you but you can follow different approach. 

i.I have calculated the no of frames between one lip touching frame to the next one.In live streaming case the threshold should be given a bit large for less errors.

ii..For my case the calculated frame no is the threshold.If you find any better approach please let me know through comment.

4.So once the threshold is calculated your prog is okk.

5.Now simple calculation if detected result is beyond threshold then rejected otherwise accepted.





Wednesday, 27 February 2013

Play Computer games with hand gesture recognition using Matlab

To do this experiment,just you need an webcam and matlab2012a or 2012b

Now we are gonna do live motion detection,the below live detection code is not written by me,i got it from this link http://arindambose.webs.com/htmls/Motion%20Detection%20in%20LIVE%20Video.html

vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ...
'ROI', [1 1 640 480], ...
'ReturnedColorSpace', 'rgb');
optical = vision.OpticalFlow('OutputValue', 'Horizontal and vertical components in complex form');

maxWidth = imaqhwinfo(vidDevice,'MaxWidth');
maxHeight = imaqhwinfo(vidDevice,'MaxHeight');
shapes = vision.ShapeInserter;
shapes.Shape = 'Lines';
shapes.BorderColor = 'Custom';
shapes.CustomBorderColor = [255 0 0];
r = 1:5:maxHeight;
c = 1:5:maxWidth;
[Y, X] = meshgrid(c,r);

hVideoIn = vision.VideoPlayer;
hVideoIn.Name = 'Original Video';
hVideoIn.Position = [30 100 640 480];
hVideoOut = vision.VideoPlayer;
hVideoOut.Name = 'Motion Detected Video';
hVideoOut.Position = [700 100 640 480];

nFrames = 0;
while (nFrames < Inf)
rgbData = step(vidDevice);
optFlow = step(optical,rgb2gray(rgbData));
optFlow_DS = optFlow(r, c);
H = imag(optFlow_DS)*50;
V = real(optFlow_DS)*50;
lines = [Y(:)'; X(:)'; Y(:)'+V(:)'; X(:)'+H(:)'];
rgb_Out = step(shapes, rgbData, lines');
step(hVideoIn, rgbData);
step(hVideoOut, rgb_Out);
nFrames = nFrames + 1;
end
release(hVideoOut);
release(hVideoIn);
release(vidDevice);

But after this Ive changed this a little bit and  made a different thing,hope you like it.
So the code i got from the above link,well im pasting it here,

Now again use the redbox around the motion

rectangle('Position',cen,'EdgeColor','r','LineWidth',5);

Now perform a mouse click operation whenever a redbox appears in the video,get the code here

So,this is how your computer player will fire or do some other stuff as per game settings

And move the mouse pointer as per box location,code is Here

By this your player will switch it's view,
Now after doing all this,

1.Run your matlab code
2.Minimize the video stream
3.Run the game you want to play


I've tried this with some popular games,like counter strike,IGI 



Well this is a very basic idea,you can implement it further....you can also add some keyboard operation for performing other tasks,Keyboard Code here

try it it will definitely work... Thank u



Press like and leave comment

Monday, 25 February 2013

Vehicle Counting System in Matlab


1. Input a video of vehicles ex. test.avi
2. Now extract the frames and save in a specific folder
    Get the code here, one of my previous post
3. Detect the motion of the vehicle in the video
    Get the code here

Now if everything has gone alright,we can begin.

We just make very simple changes in the previous code to make the thing work perfectly.

Step 1 : Watch the redbox around the moving object.Now insert this code in there

             rectangle('Position',cen,'EdgeColor','r','LineWidth',5);
     
             Here 'cen' is the centroid

Step 2: Now the most important step,insert this code after that

        txt=text(no, strcat('car: ', num2str(round(no))));
        set(txt, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'black');

It will display the number of cars. 'no' is a variable which is set to '0' at first.But when ever a motion is detected in the video 'no' will be incremented by 1,that is how we get the vehicle count.

But the basic problem what you will face in this method that is,here we are considering frame after frame,so the 'no' variable gets incremented each time,but thats not what we want,we want the actual count,so we are gonna need a FLAG variable which indicates if 'no' is incremented by 1 for a particular vehicle then it wont increment for the specific one again.

like this,
FLAG=0;
if FLAG==0
   no=no+1;
   flag=1;
   frame=frame+1;
end
else
   frame=frame+1;
end

So now it is done,Thank You :)
Press like and leave comment

Screen Capture With Matlab

screencapture.m

clc;
r=java.awt.Robot;
tool=java.awt.Toolkit.getDefaultToolkit();
rectangle=java.awt.Rectangle(tool.getScreenSize());
image=r.createScreenCapture(rectangle);
fileh=java.io.File('scrcap.jpg');
a=javax.imageio.ImageIO.write(image,'jpg',fileh);
disp('done');

Saturday, 23 February 2013

Bestfitness matlab code using neural network


    clc;
    a= [39.8878 39.9947 39.9544 40.0285 39.9263 40.0013 40.9078 39.7623 40.9278];
    b=[0.6016 0.6016 0.6045 0.6074 0.6067 0.6074 0.6052 0.5998 0.6056] ;
    c=[100 100 100 100 100 100 100 100 100];
    y=a+ b.*c;
    I=[a; b; c];
    T=y;
    R=[0 1000; 0 1000 ; 0 1000];
    S=[5 1];
    net = newff([0 1000;0 1000 ;0 1000],[4 1],{'tansig','purelin'});
    O=[100.0439 100.5907 100.4028 100.7729 100.5963 100.7457 100.5964 99.7375 100.6877];
    net=train(net,I,O);
    O1=sim(net,I);
    plot(1:9,O,1:9,O1);
     net.IW{1}
     net.LW{2,1}
     BestFitness=sim(net,[39.8595 0.6023 100]');

Wednesday, 13 February 2013

Making a Photoviewer with GUI using Matlab

Code :


clc;
imr=input('Enter the full path of the image frames:','s');
somefolder=imr;
filelist=dir(somefolder);
for i=1:size(filelist,1)
    if filelist(i).isdir ~=true
        fname=filelist(i).name;
        if strcmp(fname(size(fname,2)-3:size(fname,2)),'.jpg')==1
            tmp=imread([somefolder fname]);
            if size(tmp,3)==3;
                tmp=imresize(tmp,[400,400],'bilinear');
                imshow(tmp);
                pause(1);
                disp([fname,':loaded']);
            end
        end
    end
end

Building GUI :

If you dont know how create basic matlab GUI then you can see my previous post :

Building GUI with Matlab

Step 1 : I have made a very simple interface,drawn just a button  and an axes


Step 2 : Now open the GUI .m file by clicking view and then m-file editor



Step 3: Now paste the above code in the pushbutton_callback function and save

Step 4: Now run the code,press play button,then it should ask for the image folder path,write the path press          enter it will show the images

Building GUI with Matlab

1. Type 'guide' on the console and press enter



2. Now select a guide template and mark 'save on start up as' option then change the name,ex. test.fig
then press ok.

3. A screen will appear like this one...



4. Now you can draw button,use axis for showing images or videos,and make your own GUI.

5. To edit the matlab code do this,



6. Copy the matlab code what you want to execute after pressing a button within that particular button function

7. Then run your code pressing 'f5' it should show the GUI you built.



Monday, 4 February 2013

Virtual Mouse using Hand gestures Matlab Code

1. Take a sample Video

2. Use any motion tracking algorithm like camshift or kalman to detect and track the motion of your hand movements.

Get code here : Motion detection and tracking matlab code


3. Now track the centroids

 like this ----
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;

4. Now move the cursor as per centroids last recorded location

use this piece of code to move the cursor


         import java.awt.Robot;
         cursor = Robot;
         cursor.mouseMove(bc(1), bc(2));


5. Clicking mechanism :

Now where you want a clicking operation during motion detection use this code

import java.awt.Robot;
import java.awt.event.*;

cursor = Robot;

cursor.mousePress(InputEvent.BUTTON1_MASK);

For more hardware access help : Click here


Saturday, 2 February 2013

Real time Video Recording and Save as AVI matlab code

Here is an easy way to do this using my older Posts :

Just first Run this file  :

Capture and save Frames using Webcam matlab Code


Now run this :

Frames to AVI using Matlab Code

*just combine them both and save as a single file

Guess what... its done... :D

So,what I want to say is that always look at the smaller modules,combine them,Make your own project...



Frames to AVI using Matlab Code


avi = avifile('output1.avi');
avi.COMPRESSION ='None';
for i =1:numOfFrames
   %%%read image
   %%% call imread or related something
   %%%%%%%%%%%%%
   avi = addframe(avi,img);
end
aviobj = close(avi);


Reverse thing,you may also see Video to frames


Capture and save Frames using Webcam matlab Code


clc ; % clearing the command window
n = input(' Enter the number of photos to be taken: ');
intervel = input(' Enter the time(seconds) gap between succeessive photos: ');
photosave = input(' Do you want to save the files(y/n): ','s');
disp('Please wait...');
outputFolder = fullfile(cd, 'frames');
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
obj = videoinput('winvideo',1);
preview(obj);
disp('Press Enter to start after webcam initialization.');
pause;
disp('First shot will taken after 1 second');
pause(1);
for i=1:n
img=getsnapshot(obj);
image(img);
if(photosave == 'y')
outputBaseFileName = sprintf('fr%d.png',i);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite(img,outputFullFileName,'jpg');
end
pause(intervel);
end
closepreview;

disp('The program successfully taken the photos');
disp('Done.');

Friday, 1 February 2013

Access Webcam using Matlab

webcam.m

clc;
vid = videoinput('winvideo', 1, 'RGB24_320x240');
preview(vid);


Wednesday, 30 January 2013

Client server program Matlab Code


server.m


import java.net.*;
import java.io.*;

%% Create Socket
port = 20;
    %input('Enter port number: ');
Server = ServerSocket (port);
disp('Waiting for a connection...')
connected = Server.accept;

iStream = connected.getInputStream;
oStream = connected.getOutputStream;

% Greets the client
oStream.sendS('Welcome client!')

% Waiting for messages from client
while ~(iStream.available)
end
readS(iStream);

%% Communication
msg = '';
while isempty(strfind(msg,'!q'))
% Waits for messages from client
while ~(iStream.available)
end
msg = readS(iStream);

if isempty(strfind(msg,'!q'))
 % Sends message to client
 disp 'Server''s turn!'
 %cmd = input('Toclient>> ', 's');
      cmd = 'hey im feeling okey!'
 oStream.sendS(cmd);

else
 oStream.sendS('!q');
end
end

pause(1)
connected.close;
disp (['Connection ended: ' datestr(now)]);

client.m


import java.net.*;
import java.io.*;

%% Create Socket and Connect to server
% Note that I am connecting to localhost, but you may change that to the corresponding machine IP that is running the server.
port = 20;
    %input('Enter port number: ');
disp('Connecting to server...')
clientSocket = Socket('localhost', port);

iStream = clientSocket.getInputStream;
oStream = clientSocket.getOutputStream;

% Greets the server on connection is accepted
oStream.sendS('Hi Server!')

% Waiting for messages from Server
while ~(iStream.available)
end
readS(iStream);
msg = '';
while isempty(strfind(msg,'!q'))
% Sends message to server
disp 'Client''s turn!'
cmd = input('ToServer>> ', 's');
oStream.sendS(cmd);

% Waits for replies from server
while ~(iStream.available)
end
msg = readS(iStream);
end
clientSocket.close
disp (['Connection ended: ' datestr(now)]);

readS.m


function b = readS(iStream)

disp 'Reply:'

% Number of messages
n = iStream.available;

% Buffer size = 500 characters
b = zeros(1,500);
for i = 1:n
   b(i) = iStream.read();
end

if (b(1) ~= 0)
   disp (char(b))
end
disp ('')

sendS.m


    function sendS(oStream,str)
oStream.write(int8([str 10]))





Sunday, 27 January 2013

Access serial port using Matlab code


AccessSerialPort.m


clear all;
close all;

s = serial('COM1');  %assigns the object s to serial port

set(s, 'InputBufferSize', 256);  %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));

disp(['Port Setup Done!!',num2str(prop)]);

fopen(s);           %opens the serial port
t=1;
disp('Running');
x=0;
while(t<200 p="">   a =fread(s);
   a=max(a);
   x =[x a];
   plot(x);
   axis auto;
   grid on;
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;
   drawnow;
end

fclose(s); %close the serial port