Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
wind_sensor:wind_sensor_documentation [2015/11/25 21:28] jeremygg |
wind_sensor:wind_sensor_documentation [2015/12/03 23:11] daisygreen [Implementing Code] |
||
---|---|---|---|
Line 94: | Line 94: | ||
What is needed is a memory-less way to update the mean of the current signal. | What is needed is a memory-less way to update the mean of the current signal. | ||
- | In this case we do a moving average type of equation. Assume you have a signal of N samples with samples k<sub>1</sub> to k<sub>N</sub> with a mean of μ. If you would only like to take the average of the past N samples, after adding sample k<sub>N+1</sub>, the average would be (k<sub>N+1</sub>+Nμ-k<sub>1</sub>)/N. If the variance of the k's are low and/or the N is high enough, you can treat k<sub>1</sub> practically as μ. You can calculate for the new mean, lets call it μ[n+1] = (k<sub>n</sub>+Nμ[n]-μ[n])/N = μ[n+1] (k<sub>n</sub>)/N+((N-1)μ[n])/N If the signal ends up changing from its original mean to a different value, the steady state of this method will converge to the newer mean. Our implementation is below: | + | In this case we do a moving average type of equation. Assume you have a signal of N samples with samples k<sub>1</sub> to k<sub>N</sub> with a mean of μ. If you would only like to take the average of the past N samples, after adding sample k<sub>N+1</sub>, the average would be (k<sub>N+1</sub>+Nμ-k<sub>1</sub>)/N. If the variance of the k's are low and/or the N is high enough, you can treat k<sub>1</sub> practically as μ. You can calculate for the new mean, lets call it μ[n+1] = (k<sub>n</sub>+Nμ[n]-μ[n])/N = μ[n+1] (k<sub>n</sub>)/N + ( (N-1)μ[n])/N If the signal ends up changing from its original mean to a different value, the steady state of this method will converge to the newer mean. Our implementation is below: |
<code> | <code> | ||
Line 130: | Line 130: | ||
Notice if you don't chose a value N large enough, the output of the mean of the last N samples will very large, an example is shown below. | Notice if you don't chose a value N large enough, the output of the mean of the last N samples will very large, an example is shown below. | ||
- | </code>% Test on how the N parameter makes a difference in find the moving average | + | <code> |
+ | % Test on how the N parameter makes a difference in find the moving average | ||
clc;clear;close all; % clears all | clc;clear;close all; % clears all | ||
Line 147: | Line 148: | ||
figure() | figure() | ||
RT = RTprocess(x',500); | RT = RTprocess(x',500); | ||
- | title('real time process N = 500')<code> | + | title('real time process N = 500') |
+ | end</code> | ||
{{:wind_sensor:input.jpg|}} | {{:wind_sensor:input.jpg|}} | ||
Line 159: | Line 161: | ||
Note: We did a piece wise regression at output<13 and output>13 because if you look above, that is when it changes a lot faster, and we rather avoid an extra power as a feature to decrease residual error and just use 2 models for 2 parts of the fitting. | Note: We did a piece wise regression at output<13 and output>13 because if you look above, that is when it changes a lot faster, and we rather avoid an extra power as a feature to decrease residual error and just use 2 models for 2 parts of the fitting. | ||
+ | The code for collecting data on Arduino is below. This is for collecting analog data before it is processed. This code collects data from all four microphones with a 1 microsecond delay in between readings. Note that each microphone is only being sampled one-fourth of the time. After releasing the reset button on the Arduino, microphone 1 will always be the first data point. | ||
- | (Insert arduino code) | + | <code> |
+ | void setup() { | ||
+ | Serial.begin(14400); | ||
+ | analogReference(EXTERNAL); | ||
+ | } | ||
+ | void loop() { | ||
+ | | ||
+ | delayMicroseconds(1); | ||
+ | int sensorValue1 = analogRead(A0); | ||
+ | delayMicroseconds(1); | ||
+ | int sensorValue2 = analogRead(A1); | ||
+ | delayMicroseconds(1); | ||
+ | int sensorValue3 = analogRead(A2); | ||
+ | delayMicroseconds(1); | ||
+ | int sensorValue4 = analogRead(A3); | ||
+ | |||
+ | Serial.println(sensorValue1); | ||
+ | Serial.println(sensorValue2); | ||
+ | Serial.println(sensorValue3); | ||
+ | Serial.println(sensorValue4); | ||
+ | | ||
+ | } | ||
+ | end</code> |