Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Dec 4, 2024
1 parent 14e85f4 commit 527f096
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 53 deletions.
6 changes: 3 additions & 3 deletions examples/test_butter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ for i in Int(N/2):N
end

# apply the filter
buffer = zeros(N)
results = zeros(N)
tfilter = DF2TFilter(butter)
for i in 1:N
results[i] = apply_filter(butter, measurements[i], buffer, i)
results[i] = apply_filter(tfilter, measurements[i], i)
end
@time apply_filter(butter, measurements[N], buffer, N)
@time apply_filter(tfilter, measurements[N], N)

# Plot the step response
p = plot((1:N)*dt, [measurements, results]; xlabel="Time (s)", ylabel="Amplitude",
Expand Down
50 changes: 0 additions & 50 deletions examples/test_butter2.jl

This file was deleted.

17 changes: 17 additions & 0 deletions src/DiscreteFilters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ function apply_filter(butter, measurement, buffer, index)
res = filt(butter, buffer[1:index])
return res[index]
end
"""
apply_filter(tfilter::DF2TFilter, measurement, index)
Apply the filter to the measurement.
# Arguments
- `tfilter`: The filter, created with `create_filter` and converted to a DF2TFilter
- `measurement`: The measurement value
- `buffer`: The buffer to store the measurements
- `index`: The index of the measurement
"""
function apply_filter(tfilter::DF2TFilter, measurement, index)
results = zeros(1)
measurements = ones(1) * measurement
@views filt!(results[1:1], tfilter, measurements)
return results[1]
end

function apply_delay(measurement, buffer, index; delay=1)
buffer[index] = measurement
Expand Down

0 comments on commit 527f096

Please sign in to comment.