Skip to content

Instantly share code, notes, and snippets.

@rahulbhadani
Created September 12, 2022 22:54
Show Gist options
  • Save rahulbhadani/5ebd6337bfcc199215ae9ffacc4feec7 to your computer and use it in GitHub Desktop.
Save rahulbhadani/5ebd6337bfcc199215ae9ffacc4feec7 to your computer and use it in GitHub Desktop.
First-order and Second-order filter modules
#ifndef FIFTH_ORDER_H
#define FIFTH_ORDER_H
#include<systemc-ams>
using namespace std;
using namespace sca_tdf;
using namespace sca_util;
using namespace sc_core;
SCA_TDF_MODULE(first_order)
{
private:
/*Scaled Laplace TF in the time domain, numerator-denominator form */
sca_ltf_nd ltf_nd;
/*Vector to store denom. and num. coefficients*/
sca_vector<double> denom;
sca_vector<double> numer;
public:
sca_in<double> sig_in;
sca_out<double> sig_out;
void initialize()
{
numer(0) = 1.0;
denom(0) = 1.0;
denom(1) = 2.65E-3;
}
/* Initialize port attributes*/
void set_attributes()
{
sig_out.set_timestep(1.0, SC_US);
/* Specify the number of data samples that need to pass through I/O ports per time step */
sig_out.set_rate(1);
sig_in.set_rate(1);
/*Feedback loopp requires a delay, we specify one time step delay*/
sig_out.set_delay(1);
}
void processing()
{
/*Computation here*/
sig_out.write(ltf_nd(numer, denom, sig_in.read(), 1.0) );
}
SCA_CTOR(first_order) {}
~first_order() {}
};
SCA_TDF_MODULE(second_order)
{
private:
/*Scaled Laplace TF in the time domain, numerator-denominator form */
sca_ltf_nd ltf_nd;
/*Vector to store denom. and num. coefficients*/
sca_vector<double> denom;
sca_vector<double> numer;
public:
sca_in<double> sig_in;
sca_out<double> sig_out;
void initialize()
{
numer(0) = 1.0;
denom(0) = 1.0;
denom(1) = 4.3E-3;
denom(2) = 7.0E-6;
}
void set_attributes()
{
sig_out.set_timestep(1.0, SC_US);
/* Specify the number of data samples that need to pass through I/O ports per time step */
sig_out.set_rate(1);
sig_in.set_rate(1);
/*Feedback loopp requires a delay, we specify one time step delay*/
sig_out.set_delay(1);
}
void processing()
{
/*Computation here*/
sig_out.write(ltf_nd(numer, denom, sig_in.read(), 1.0) );
}
void set_coeffs(double n0, double d0, double d1, double d2)
{
numer(0) = n0;
denom(0) = d0;
denom(1) = d1;
denom(2) = d2;
}
SCA_CTOR(second_order) {}
~second_order() {}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment