Triple redundancy sensor matlab code

In summary, the code is trying to find the mean of an array that has non-nan values, but is not sure how to do it. If I add a while loop to the code to check for a certain condition, it might break. I am also having problems with my code breaking when I get a certain number of rows with all columns being NaN. Finally, I am not sure how to store the previous estimate.
  • #1
gfd43tg
Gold Member
950
50

Homework Statement


Hardware redundancy is important in many real-world engineering systems. Specifically, installing
multiple sensors that measure the same quantity provides a level of safety in the event that one
instrument fails during the mission lifetime. You do not want an expensive project to become a
complete failure simply due to the malfunction of one small part.

Suppose you are an engineer designing the control logic for a scientific telescope that will be
launched into space to study the sun. In order to provide a reasonable layer of safety, a triple
redundancy in the measurement of the telescope's elevation angle with respect to the horizon of
the Earth has been put into place (i.e. these three sensors measure the same quantity). Your task
is to program the software logic that will determine how the three independent measurements
will be combined in real-time, in order to provide the on-board computer with the best possible
estimate of the true elevation angle.

The following is known about the sensors:
- If a sensor fails, its measurement will read as NaN;
- Otherwise, working sensors provide measurements that will read as finite double values;
- Faulty/loose wiring may cause a measurement to read as NaN for a few samples, but can
return to valid measurements.

The estimator code must incorporate the following logic:
- On startup, the estimator logic defines the "previous estimate" to be NaN
- If there are any working sensors, define the elevation estimate as the average of the mea-
surements from all working sensors
- if all three sensors fail, the elevation estimate should be set to the previous estimate
- if all three sensors read NaN for 30 consecutive samples, then exit the sensor loop.

Load the sensorData.mat file which contains measurements, a Nx3 double array of sensor
measurements. Write code to "simulate" your sensor logic by looping through measurements
one row at a time to mimic the real-time sensor readings. Store the elevation estimates for each
loop iteration in a column vector called elevationEstimates.


Homework Equations





The Attempt at a Solution


This problem has a lot of information, so I am trying to break it down into 'subsystems' and solve the individual subsystems. I have a few problems right now with my code that I haven't been able to reconcile. I will list them out right now as I see them. This is a 150x3 array

1. I don't know how to find the mean of only the components of an array that are not NaN. If I do the mean of a row that has any components that are NaN, the mean is NaN. This problem becomes apparent in my code at the elevationEstimate lines, where I have a [ ] which is where I want to somehow specify to take the mean of the elements that are not NaN.

If I do isnan(measurements(4,:)) for example, I get an array [0 0 1]. Now, I want to go back to the elements of the array where isnan(measurements(i,:)) = 0 and take the mean of those.

2. I want the code to break when I get 30 rows consecutively that have all columns = NaN. I thought to do a while loop with failcounter(i:i+29) == 30. If I add break after that, will that let MATLAB know only to break if that condition is meant, or is it just going to break at that line no matter what. If it does break no matter what, how do I set it so that it will only break the loop if I get 30 consecutive rows of all NaN.

3. I am having some problems implementing this previousEstimates



Code:
failcounter = 0;
counter = 0;
previousEstimate = NaN;
for i = 1:length(measurements)
    while failcounter(i:i+29) == 30
break
if sum(isnan(measurements(i,:))) == 0
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i,:));
elseif sum(isnan(measurements(i,:))) == 1
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i,[ ]));
elseif sum(isnan(measurements(i,:))) == 2
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i, [ ]))
else
    failcounter = failcounter + 1;
    previousEstimate = elevationEstimates(counter);
end 
if sum(measurements(1,:)) == 3
    previousEstimates = NaN;
end 

    end
end
 
Physics news on Phys.org
  • #2
solved, disregard
 
  • #3
How did you solve this problem?
 
  • #4
Get help from the TA, good luck with E7!
 

1. What is a triple redundancy sensor?

A triple redundancy sensor is a type of sensor system that uses three separate sensors to measure the same parameter. This redundancy ensures accuracy and reliability in the data collected.

2. How does a triple redundancy sensor work?

A triple redundancy sensor works by having three identical sensors measure the same parameter. The readings from each sensor are then compared and any discrepancies are flagged. The final output is determined by taking the average of the three readings.

3. What is the purpose of using a triple redundancy sensor?

The purpose of using a triple redundancy sensor is to ensure accuracy and reliability in the data collected. By having three sensors measuring the same parameter, any errors or malfunctions in one sensor can be detected and corrected by comparing it to the other two sensors.

4. How is a triple redundancy sensor coded in MATLAB?

In MATLAB, a triple redundancy sensor can be coded by creating three separate sensor objects and using if/else statements to compare the readings and determine the final output. Alternatively, a function can be created to handle the redundancy and output the average of the three readings.

5. What are the advantages of using MATLAB for coding a triple redundancy sensor?

Using MATLAB for coding a triple redundancy sensor allows for easy implementation of complex algorithms and mathematical operations. It also has built-in functions for handling and analyzing data, making it a convenient tool for processing the readings from three sensors and determining the most accurate output.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
962
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
599
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Back
Top