Skip to content

Instantly share code, notes, and snippets.

@cryptix
Created August 4, 2013 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptix/6150074 to your computer and use it in GitHub Desktop.
Save cryptix/6150074 to your computer and use it in GitHub Desktop.
PSHDL 4-tap Fir Filter
// simple 4 tap fir
// coeff's are power of two
package de.tuhh.hbubert.noiseCancel;
module simpleFir {
param uint Width = 8;
@clock in bit clk;
@reset in bit rst;
in int<Width> x;
out register int<Width> y;
register(resetValue = {0,0,0,0}) int<Width> tap[4];
// write output
// [1, 1, 1, 1]
y = tap[0]
+ tap[1]
+ tap[2]
+ tap[3];
// how to const array?
//register(resetValue = {-1, 3.75, 3.75, -1}) int<Width> coeff[4];
//y = coeff[0] * tap[0]
// + coeff[1] * tap[1]
// + coeff[2] * tap[2]
// + coeff[3] * tap[3];
// low pass
// [-1, 3.75, 3.75, -1]
// y =
// -1 * tap[0] // -1
// + 2* tap[1] + tap[1] + tap[1]/2 + tap[1]/4 // +3.75
// + 2* tap[2] + tap[2] + tap[2]/2 + tap[2]/4 // +3.75
// -1 * tap[3]; // -1
// shift!
for (I={1:3}) {
tap[I] = tap[I-1];
}
// read input
tap[0] = x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment