Skip to content

Commit

Permalink
clean codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neaeko committed Mar 4, 2024
1 parent b35315c commit 6f06225
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 91 deletions.
11 changes: 7 additions & 4 deletions sv/demod.sv
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ always_ff @( posedge clk or posedge rst ) begin : blockName
end

always_comb begin
i_abs = 0;
imm32 = 0;
demod_out = 0;
state_c=state;
rd_en_img=1'b0;
rd_en_rl=1'b0;
Expand All @@ -106,10 +109,10 @@ always_comb begin
if (empty_rl==1'b0 && empty_img==1'b0) begin
rd_en_img=1'b1;
rd_en_rl=1'b1;
r_c= DEQUANTIZE(rl_pre*rl) - DEQUANTIZE((-img_pre)*img);
i_c= DEQUANTIZE(rl_pre*img) + DEQUANTIZE((-img_pre)*rl);
//r_c=mul_frac10_32b(rl_pre,rl) - mul_frac10_32b((-img_pre),img);
//i_c=mul_frac10_32b(rl_pre,img) + mul_frac10_32b((-img_pre),rl);
//r_c= DEQUANTIZE(rl_pre*rl) - DEQUANTIZE((-img_pre)*img);
//i_c= DEQUANTIZE(rl_pre*img) + DEQUANTIZE((-img_pre)*rl);
r_c=mul_frac10_32b(rl_pre,rl) - mul_frac10_32b((-img_pre),img);
i_c=mul_frac10_32b(rl_pre,img) + mul_frac10_32b((-img_pre),rl);
state_c=RUN;
//store for next calcluate
rl_pre_c=rl;
Expand Down
21 changes: 2 additions & 19 deletions sv/fir_complex.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functs::*;

module fir_complex#(
parameter TAP_NUMBER = 20,
// inverse filter coefficients with buffer to ensure correct convolution
Expand Down Expand Up @@ -312,23 +314,4 @@ always_comb begin
end





// fixed point multiplication
function automatic logic [31:0] mul_frac10_32b (
input logic [31:0] ina,
input logic [31:0] inb
);
// Perform the multiplication
logic [63:0] product = $signed(ina) * $signed(inb);

// Shift the product right by 10 bits to maintain the 10-bit fractional part
logic [31:0] result = product >> 10;

return result;
endfunction



endmodule
28 changes: 2 additions & 26 deletions sv/fir_normal.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functs::*;

module fir_normal#(
parameter TAP_NUMBER = 32,
// inverse filter coefficients with buffer to ensure correct convolution
Expand Down Expand Up @@ -257,30 +259,4 @@ always_comb begin
end





// fixed point multiplication
function automatic logic [31:0] mul_frac10_32b (
input logic [31:0] ina,
input logic [31:0] inb
);
// Perform the multiplication
logic [63:0] product = $signed(ina) * $signed(inb);

// Shift the product right by 10 bits to maintain the 10-bit fractional part
logic [31:0] result = product >> 10;

return result;
endfunction


function logic[31:0] DEQUANTIZE;
input logic[31:0] i;
begin
return int'($signed(i) / $signed(1 << 10));
end
endfunction


endmodule
2 changes: 1 addition & 1 deletion sv/fm_radio_top.sv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`include "para.svh"
//`include "functions.svh"
`include "functions.svh"
import para::*;
import functs::*;

Expand Down
2 changes: 1 addition & 1 deletion sv/functions.svh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function automatic logic [31:0] mul_frac10_32b (
input logic [31:0] inb
);
// Perform the multiplication
real product = $signed(ina) * $signed(inb);
longint product = $signed(ina) * $signed(inb);

return int'($signed(product) / $signed(1 << 10));
endfunction
Expand Down
28 changes: 2 additions & 26 deletions sv/iir_normal.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functs::*;

module iir_normal#(
parameter TAP_NUMBER = 2,
// inverse filter coefficients with buffer to ensure correct convolution
Expand Down Expand Up @@ -238,30 +240,4 @@ always_comb begin
end





// fixed point multiplication
function automatic logic [31:0] mul_frac10_32b (
input logic [31:0] ina,
input logic [31:0] inb
);
// Perform the multiplication
logic [63:0] product = $signed(ina) * $signed(inb);

// Shift the product right by 10 bits to maintain the 10-bit fractional part
logic [31:0] result = product >> 10;

return result;
endfunction


function logic[31:0] DEQUANTIZE;
input logic[31:0] i;
begin
return int'($signed(i) / $signed(1 << 10));
end
endfunction


endmodule
16 changes: 2 additions & 14 deletions sv/multiplier_w_fifo.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functs::*;

module multiplier_w_fifo(
input logic reset,
input logic clock,
Expand Down Expand Up @@ -99,18 +101,4 @@ end



function automatic logic [31:0] mul_frac10_32b (
input logic [31:0] ina,
input logic [31:0] inb
);
// Perform the multiplication
logic [63:0] product = $signed(ina) * $signed(inb);

// Shift the product right by 10 bits to maintain the 10-bit fractional part
logic [31:0] result = product >> 10;

return result;
endfunction


endmodule

0 comments on commit 6f06225

Please sign in to comment.