// Pulse-shaping FIR for one channel (I or Q). // The input is +1, -1 or 0 (a symbol every SPS samples, zeros in between), // so each "multiplication" is just +tap, -tap or nothing. // The taps in TAP_FILE are scaled so that the output always fits in 16 bits // (checked by test_qpsk_model.py). Two's complement wrap-around in the // accumulator therefore cancels out and a 16-bit accumulator is enough. `timescale 1ns / 1ps module pulse_shaper #( parameter int NTAPS = 49, parameter TAP_FILE = "rrc_taps.hex" ) ( input logic clk, input logic rst, input logic signed [1:0] x_in, output logic signed [15:0] y ); logic signed [15:0] taps [NTAPS]; initial $readmemh(TAP_FILE, taps); logic signed [1:0] xs [NTAPS]; // delay line of input samples logic signed [15:0] acc; always_ff @(posedge clk) begin if (rst) begin for (int k = 0; k < NTAPS; k++) xs[k] <= '0; end else begin xs[0] <= x_in; for (int k = 1; k < NTAPS; k++) xs[k] <= xs[k-1]; end end always_comb begin acc = '0; for (int k = 0; k < NTAPS; k++) begin if (xs[k] == 2'sd1) acc = acc + taps[k]; else if (xs[k] == -2'sd1) acc = acc - taps[k]; end end always_ff @(posedge clk) begin if (rst) y <= '0; else y <= acc; end endmodule