Pages: [1] 2   Go Down
Author Topic: need help to write a code please  (Read 832 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Kindly, i want to write a code for read  analog signal 10 times and put these reading in a matrix as

Code:
for (int i=0;i<10;i++) {
    a[i]=readRead(A0);
}
then i compare the elements of matrix if they belong to another matrix contain 50 elements as
int b[50] = { 512,519,520,600,...........................,400};

i do not want to make a loop to compare 50 times cause it will take a long time...i want a code to check with minimum time
« Last Edit: June 19, 2013, 09:40:38 am by dany151 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24310
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tell us what you want to do, not how you think you should do it.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 18
Posts: 1170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, but brute force is sometimes the only way to go.

However, I think you are going to have problems with this just because of the noise inherent in reading the analog input, I don't think a check for exact equality will work very well.

Are you trying to match a pattern, or single values?

A binary search will cut the time a lot, as well as hashing.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Tell us what you want to do, not how you think you should do it

i have 4 analog signal patterns i want to check if the reads belongs to which  pattern...so that i will make a database for each pattern then check if the new signal belong to the pattern with acceptable error rate
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the noise inherent in reading the analog input
good point
Quote
I don't think a check for exact equality will work very well
it must have some error rate
Logged

Offline Offline
Edison Member
*
Karma: 18
Posts: 1170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use a hash or binary search to see if the first element is in the pattern array. Then check each one in turn, as soon as it fails to find a match quit the search.

Remember, the arduino does not have much memory for a "database".
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Use a hash or binary search to see if the first element is in the pattern array. Then check each one in turn, as soon as it fails to find a match quit the search.

good idea

Quote
Remember, the arduino does not have much memory for a "database".

i will take it in my account..thank you

-----------------------but i want to check all the readings at the same time please help
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Define "same time".

To the Arduino?

To the human eye?

To a Physicist?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Define "same time".

To the Arduino?

To the human eye?

To a Physicist?

??????????????????
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24310
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there something wrong with your question-mark key?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Define "same time".

To the Arduino?

To the human eye?

To a Physicist?

??????????????????

"same time" is subjective. It sounds like you want to do this process with respect to the Arduino. Unfortunately, the Arduino doesn't have a "compare array of values to withing a specific threshold" instruction.
Logged

Mid-Atlantic, USA
Offline Offline
Sr. Member
****
Karma: 21
Posts: 435
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Define "same time".

To the Arduino?

To the human eye?

To a Physicist?

??????????????????

Time scales are relative...
To the Arduino, the "same time" is on the order of microseconds.
To the human eye, the "same time" is on the order of 100's of milliseconds.
To a Physicists I work with, the "same time" is on the order of picoseconds (or smaller).
To a Geologist, the "same time" is on the order of hundreds of years (or larger)...
Logged


Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Unfortunately, the Arduino doesn't have a "compare array of values to withing a specific threshold" instruction

i think it need a statistical operation to do like  this things

Quote
Time scales are relative...
To the Arduino, the "same time" is on the order of microseconds.
To the human eye, the "same time" is on the order of 100's of milliseconds.
Quote

for me i process human eye signal with arduino...
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i think it need a statistical operation to do like  this things

Like what things? Can you try that sentence again?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Like what things? Can you try that sentence again?

like find the Mean absolute error or Mean squared  error
Logged

Pages: [1] 2   Go Up
Jump to: