| 
									
										
										
										
											2022-07-20 09:07:00 +02:00
										 |  |  | // Copyright 2015-2020 Mobilinkd LLC.
 | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Filter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <array>
 | 
					
						
							|  |  |  | #include <cstddef>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 23:03:07 +02:00
										 |  |  | namespace modemm17 | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 20:12:35 +02:00
										 |  |  | template <size_t N> | 
					
						
							|  |  |  | struct BaseFirFilter : FilterBase<float> | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-27 19:02:23 +02:00
										 |  |  | 	BaseFirFilter(const std::array<float, N>& taps) | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | 	: taps_(taps) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		history_.fill(0.0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-06-09 20:12:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float operator()(float input) override | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		history_[pos_++] = input; | 
					
						
							|  |  |  | 		if (pos_ == N) pos_ = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 20:12:35 +02:00
										 |  |  | 		float result = 0.0; | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | 		size_t index = pos_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (size_t i = 0; i != N; ++i) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			index = (index != 0 ? index - 1 : N - 1); | 
					
						
							|  |  |  | 			result += history_.at(index) * taps_.at(i); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void reset() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		history_.fill(0.0); | 
					
						
							|  |  |  | 		pos_ = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-27 19:02:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	const std::array<float, N>& taps_; | 
					
						
							|  |  |  | 	std::array<float, N> history_; | 
					
						
							|  |  |  | 	size_t pos_ = 0; | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 20:12:35 +02:00
										 |  |  | template <size_t N> | 
					
						
							|  |  |  | BaseFirFilter<N> makeFirFilter(const std::array<float, N>& taps) | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-09 20:12:35 +02:00
										 |  |  | 	return std::move(BaseFirFilter<N>(taps)); | 
					
						
							| 
									
										
										
										
											2022-06-07 03:22:18 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 23:03:07 +02:00
										 |  |  | } // modemm17
 |