Ignore data from serial

4 views (last 30 days)
Pedro Gomes
Pedro Gomes on 19 Apr 2012
I am collecting from the serial port the instantaneous values of current and voltage, however because the reading is to fast sometimes Matlab gives me incorrect values that I want to ignore. I will try to explain.
When I receive normal data I have about 24 points per sin, however when I receive incorrect data I have less than 24 points per sinu so the frequency of the signal will not be 50Hz (20ms) like is supposed to.
Is there any solution for me to try to ignore all the data from this "wrong" sinu, and continue reading??
Help would be appreciated.
clear all
close all
clc
delete(instrfind({'Port'},{'COM3'}));
s = serial('COM3','BaudRate', 115200);
fopen(s);
x= zeros(1,2);
MAX = 256;
t=0;
n=1;
c=1;
while (c<10),
while(n<=MAX),
x=fscanf(s,'%d,%d');
if length(x) ==2,
if x(1) >= 1024 || x(1) <= 200,
continue
end
data1(n,c) = x(1);
data2(n,c) = x(2);
if n<MAX
t(n+1) = t(n)+ 20e-3/24; %here the 24 is the number of points per sinu, if someone know who to make this value change depending on the sinu it would be great, because sometimes is 23 another times 24.
end
n = n+1;
end;
end;
c = c+1;
figure(1);
plot(data1);
figure(2);
plot(data2);
figure(3);
plot(t,data1);
end
fclose(s)
After I use another program to see the collected data and after to do another calculations like fft and so on.
This is a link for you to see my data and what happens to the sinu wave
The error does not occur always in the same positions of the vector.
I would like to share my .mat file but I don't know how to do it.
Thank you.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!