Skip to content

Commit

Permalink
Update code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
01binary committed Aug 29, 2024
1 parent ce469fb commit 6464a31
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/articles/kalman-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ A basic *moving average* filter can be implemented as follows:
```matlab
function output = movingAverageFilter(input, bufferSize)
buffer = ones(bufferSize, 1) * input(1);
output = zeros(length(input));
output = zeros(length(input), 1);
for sampleIndex = 1:length(input)
bufferIndex = mod(sampleIndex - 1, bufferSize) + 1;
buffer(bufferIndex) = input(sampleIndex);
% Output is average of last bufferSize inputs
output(sampleIndex, 1) = ...
output(sampleIndex) = ...
sum(buffer) / bufferSize;
end
end
Expand All @@ -67,7 +67,7 @@ A basic *low-pass* filter can be implemented as follows:
```matlab
function output = lowPassFilter(input, coefficient)
estimate = input(1);
output = zeros(length(input));
output = zeros(length(input), 1);
for sampleIndex = 1:length(input)
sample = input(sampleIndex);
Expand All @@ -77,7 +77,7 @@ function output = lowPassFilter(input, coefficient)
(1.0 - coefficient) * estimate + ...
coefficient * sample;
output(sampleIndex, 1) = estimate;
output(sampleIndex) = estimate;
end
end
```
Expand Down

0 comments on commit 6464a31

Please sign in to comment.