/* 
 * File:   FirComplex.hpp
 * Author: jens
 *
 * Created on 20. Dezember 2014, 08:12
 */

#ifndef _RADIO_FIRCOMPLEX_HPP_
#define	_RADIO_FIRCOMPLEX_HPP_

#include <cpp/radio/Vector.hpp>
#include <cpp/radio/processor/src/Buffer.hpp>

namespace Radio
{

class FirComplex
{
public:
	FirComplex(size_t numTaps = 0)
	: m_numTaps(numTaps)
	, m_state(numTaps)
	{
	}
	virtual ~FirComplex()
	{
		
	}
	
	void setNumTaps(size_t numTaps)
	{
		m_numTaps = numTaps;
		m_state.resize(numTaps);
		m_state = ComplexScalar(0,0);
	}
	
	// Feed single scalar
	void feed(ComplexScalar const &x)
	{
		insert_left(m_state, x);
	}

	// Feed from array
	void feed(ComplexScalar const *x, size_t len)
	{
		for (size_t i=0; i < len; i++)
		{
			feed(*(x++));
		}
	}

	// Feed from Processor::Buffer
	void feed(Processor::Buffer<ComplexScalar> &buf_in, size_t len)
	{
		for (size_t i=0; i < len; i++)
		{
			ComplexScalar x = buf_in.readAt(0);
			feed(x);
		}
	}

	ComplexScalar process(CVec const &coeff)
	{
		return trans(m_state) * conj(coeff);
	}
	
	ComplexScalar processReal(RVec const &coeff)
	{
		return trans(m_state) * coeff;
	}

protected:
	size_t m_numTaps;
	CVec m_state;
};

} // ::Radio

#endif	/* _RADIO_FIRCOMPLEX_HPP_ */

