Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to plot digital data in sin graph in matlab

Status
Not open for further replies.

zack_rosman

Newbie level 3
Joined
May 28, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
hai...I tried to plot digital data in sin graph...but I fail...I want to plot data from pendulum and plot it in sin graph..I used photosensor to plot the movement of pendulum.can someone help plot the sin graph?
This is the program that I used...I took it from internet.

Code:
%run('clean');
clear all;
close all;

if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end

s = serial('COM5'); %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);
set(s, 'Terminator', 'CR');
%clc;
 
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=0;
t_samp=0.1;
disp('Running');
x=0;
while(t<200)  %Runs for 200 cycles - if you cant see the symbol, it is "less than" sign. so while (t less than 200)
 
   a =fread(s); %reads the data from the serial port and stores it to the matrix a
   a=max(a);  % in this particular example, I'm plotting the maximum value of the 256B input buffer
 
   x =[x a];  % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
                 %Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
                  %data at the end!
   
   plot(x);
   axis auto;
   grid on;
 
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;  %Clear the buffer
   drawnow;
end
 
fclose(s); %close the serial port
 

Hi zack_rosman,
Please provide more information, so that it would be easy to help you.

What is the setup?
Is pendulum is connected to computer through serial interface.
or
It is a standalone setup and you are collecting data by manual observation.
 

the setup : it is bifilar pendulum...there has a sensor to detect the motion of the pendulum...sensor connected to the computer through UART...i'm using pic microcontroller..
 

hi,
Welcome to edaboard.
I am not sure which stage exactly you are in... let us start from begining.
1) Do you have the details of serial interface configuration like baud rate, no. of data bits, odd or even parity etc.
2) Once you have this information, interface the setup with computer and check the recieved data with hyperterminal or similar serial port monitors.
3) After understanding the data format, it is not difficult to play with matlab.
Please update, which stage are you in.
 

thnx for the reply...im already pass those stages...:
1) I have the details of the interface detail like baudrate and etc.
2) I have already check with hyperterminal and got the data
3)my problem is at matlab, I'm trying to plot a "sin graph" from the serial input...

=)

- - - Updated - - -

thnx for the reply...im already pass those stages...:
1) I have the details of the interface detail like baudrate and etc.
2) I have already check with hyperterminal and got the data
3)my problem is at matlab, I'm trying to plot a "sin graph" from the serial input...

=)
 

Hi,
Code:
experiment = serial('COM2','BaudRate',9600,'Terminator','CR');
fopen(experiment)
Read_Data = fgets(experiment)
fclose(experiment)
delete(experiment)
you should start exploring something like above code. once you start getting data inside matlab, its not a big deal to seperate x and y values and plotting in graph. If you unable to plot in graph, kindly update us exactly in what format you are getting data inside matlab.
Hope this helps...
 

I'm getting the data inside the matlab... =) sorry, actually i'm trying to plot oscillation damping graph...my experiment setup is a simple pendulum... is it possible?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top