data/full_repos/permissive/133043770/ConvolutionFilter.v
1: b'%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:147: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s NEGATE generates 32 or 13 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[5] = -4190; \n                               ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:148: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?sh1de4\' generates 32 or 13 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[6] = 7652;\n                               ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:149: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s NEGATE generates 32 or 14 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[7] = -10908;\n                               ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:150: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?sh2fe6\' generates 32 or 14 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[8] = 12262; \n                               ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:151: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s NEGATE generates 32 or 14 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[9] = -10908; \n                               ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:152: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?sh1de4\' generates 32 or 13 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[10] = 7652; \n                                ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:153: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s NEGATE generates 32 or 13 bits.\n                                                                            : ... In instance ConvolutionFilter\n  filterBandReject500to2220[11] = -4190; \n                                ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:206: Operator ADD expects 65 bits on the RHS, but RHS\'s VARREF \'tempSample\' generates 12 bits.\n                                                                            : ... In instance ConvolutionFilter\n    sampleSum = sampleSum + tempSample;\n                          ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:212: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s VARREF \'sampleSum\' generates 65 bits.\n                                                                            : ... In instance ConvolutionFilter\n   IIRBuffer[11:0] = sampleSum;\n                   ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:229: Operator ADD expects 65 bits on the RHS, but RHS\'s VARREF \'tempSample\' generates 12 bits.\n                                                                            : ... In instance ConvolutionFilter\n     sampleIIRSum = sampleIIRSum + tempSample;\n                                 ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:232: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s ADD generates 65 bits.\n                                                                            : ... In instance ConvolutionFilter\n    sample = sampleSum + sampleIIRSum;\n           ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:235: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s VARREF \'sampleSum\' generates 65 bits.\n                                                                            : ... In instance ConvolutionFilter\n    sample = sampleSum;\n           ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:251: Operator ADD expects 65 bits on the RHS, but RHS\'s VARREF \'tempSample\' generates 12 bits.\n                                                                            : ... In instance ConvolutionFilter\n    sampleSum = sampleSum + tempSample;\n                          ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:254: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s DIVS generates 65 bits.\n                                                                            : ... In instance ConvolutionFilter\n   sample = sampleSum / 16;\n          ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:263: Operator ADD expects 65 bits on the RHS, but RHS\'s VARREF \'tempSample\' generates 12 bits.\n                                                                            : ... In instance ConvolutionFilter\n    sampleSum = sampleSum + tempSample;\n                          ^\n%Warning-WIDTH: data/full_repos/permissive/133043770/ConvolutionFilter.v:265: Operator ASSIGN expects 12 bits on the Assign RHS, but Assign RHS\'s DIVS generates 65 bits.\n                                                                            : ... In instance ConvolutionFilter\n   sample = sampleSum / avgFilterSampleSpan;\n          ^\n%Error: Exiting due to 16 warning(s)\n'
module ConvolutionFilter(
	input signed [11:0] inSample,
	input inSampleReady,
	









	input [3:0] inFilterType,
	
	output [11:0] outSample
);
	localparam avgFilterSampleSpan = 16;
	localparam singleCutoffSampleSpan = 8;
	localparam singleCutoffIIRSampleSpan = 7;
	localparam multiCutoffSampleSpan = 17;
	
	localparam sampleSize = 12;
	localparam bufferedSamples = 20;
	
	reg [sampleSize * singleCutoffIIRSampleSpan - 1:0] IIRBuffer = 0;
	reg [sampleSize * bufferedSamples - 1:0] sampleBuffer = 0;
	reg signed [sampleSize - 1:0] sample = 0;
	reg signed [sampleSize - 1:0] tempSample = 0;
	reg signed [64:0] sampleSum;
	reg signed [64:0] sampleIIRSum;
	
	integer i;
	integer j;
	integer bitIter;
	


	reg signed [sampleSize - 1:0] filterLowPass500[singleCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] filterHighPass500[singleCutoffSampleSpan - 1:0];

	reg signed [sampleSize - 1:0] filterBandPass500to2220[multiCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] filterBandReject500to2220[multiCutoffSampleSpan - 1:0];
	

	reg signed [sampleSize - 1:0] IIRfilterLowPass500[singleCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] IIRfilterHighPass500[singleCutoffSampleSpan - 1:0];
	
	initial begin



		filterLowPass500[0] = 1;
		filterLowPass500[1] = 7;
		filterLowPass500[2] = 21;
		filterLowPass500[3] = 35;
		filterLowPass500[4] = 35;
		filterLowPass500[5] = 21;
		filterLowPass500[6] = 7;
		filterLowPass500[7] = 1;
		

		filterHighPass500[0] = -1;
		filterHighPass500[1] = 7;
		filterHighPass500[2] = -21;
		filterHighPass500[3] = 35;
		filterHighPass500[4] = -35;
		filterHighPass500[5] = 21;
		filterHighPass500[6] = -7;
		filterHighPass500[7] = 1;
		

		filterBandPass500to2220[0] = 1;
		filterBandPass500to2220[1] = 0; 
		filterBandPass500to2220[2] = -8; 
		filterBandPass500to2220[3] = 0; 
		filterBandPass500to2220[4] = 28;
		filterBandPass500to2220[5] = 0; 
		filterBandPass500to2220[6] = -56;
		filterBandPass500to2220[7] = 0;
		filterBandPass500to2220[8] = 70; 
		filterBandPass500to2220[9] = 0; 
		filterBandPass500to2220[10] = -56; 
		filterBandPass500to2220[11] = 0; 
		filterBandPass500to2220[12] = 28; 
		filterBandPass500to2220[13] = 0; 
		filterBandPass500to2220[14] = -8; 
		filterBandPass500to2220[15] = 0;
		filterBandPass500to2220[16] = 1;
		

		filterBandReject500to2220[0] = 1;
		filterBandReject500to2220[1] = -15; 
		filterBandReject500to2220[2] = 117; 
		filterBandReject500to2220[3] = -543; 
		filterBandReject500to2220[4] = 1755;
		filterBandReject500to2220[5] = -4190; 
		filterBandReject500to2220[6] = 7652;
		filterBandReject500to2220[7] = -10908;
		filterBandReject500to2220[8] = 12262; 
		filterBandReject500to2220[9] = -10908; 
		filterBandReject500to2220[10] = 7652; 
		filterBandReject500to2220[11] = -4190; 
		filterBandReject500to2220[12] = 1755; 
		filterBandReject500to2220[13] = -543; 
		filterBandReject500to2220[14] = 117; 
		filterBandReject500to2220[15] = -15;
		filterBandReject500to2220[16] = 1;
		


		IIRfilterLowPass500[0] = 0;
		IIRfilterLowPass500[1] = -5;
		IIRfilterLowPass500[2] = 16;
		IIRfilterLowPass500[3] = -29;
		IIRfilterLowPass500[4] = 30;
		IIRfilterLowPass500[5] = -19;
		IIRfilterLowPass500[6] = 6;

		

		IIRfilterLowPass500[0] = 0;
		IIRfilterLowPass500[1] = -5;
		IIRfilterLowPass500[2] = 16;
		IIRfilterLowPass500[3] = -29;
		IIRfilterLowPass500[4] = 30;
		IIRfilterLowPass500[5] = -19;
		IIRfilterLowPass500[6] = 6;

		
	end
	
	always @(posedge inSampleReady) begin
		sampleBuffer = sampleBuffer << 12;
		sampleBuffer[11:0] = inSample;
		sampleSum = 0;
		sampleIIRSum = 0;
		bitIter = 0;
		
		if(inFilterType == 4'b0000) begin
			sample = inSample;
		end
		else if (inFilterType == 4'b0001 || inFilterType == 4'b1001 || inFilterType == 4'b0010 || inFilterType == 4'b1010) begin
			for(i = 0; i < singleCutoffSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				if(inFilterType == 4'b0001) begin
					tempSample = tempSample * filterLowPass500[i];
				end
				else if (inFilterType == 4'b0010) begin
					tempSample = tempSample * filterHighPass500[i];
				end
				sampleSum = sampleSum + tempSample;
			end

			sampleSum = sampleSum / 64;
			
			IIRBuffer = IIRBuffer << 12;
			IIRBuffer[11:0] = sampleSum;
			

			if(inFilterType == 4'b1001 || inFilterType == 4'b1010) begin
				bitIter = 0;
				for(i = 0; i < singleCutoffIIRSampleSpan; i = i + 1) begin

					for(j = 0; j < sampleSize; j = j + 1) begin
						tempSample[j] = sampleBuffer[bitIter];
						bitIter = bitIter + 1;
					end
					if(inFilterType == 4'b0001) begin
						tempSample = tempSample * IIRfilterLowPass500[i];
					end
					else if (inFilterType == 4'b0010) begin
						tempSample = tempSample * IIRfilterHighPass500[i];
					end
					sampleIIRSum = sampleIIRSum + tempSample;
				end
				sampleIIRSum = sampleIIRSum / 128;
				sample = sampleSum + sampleIIRSum;
			end	
			else begin
				sample = sampleSum;
			end
		end 
		else if (inFilterType == 4'b0011 || inFilterType == 4'b0100) begin
			for(i = 0; i < multiCutoffSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				if(inFilterType == 4'b0011) begin
					tempSample = tempSample * filterBandPass500to2220[i];
				end
				else if (inFilterType == 4'b0100) begin
					tempSample = tempSample * filterBandReject500to2220[i];
				end
				sampleSum = sampleSum + tempSample;
			end

			sample = sampleSum / 16;
		end 
		else if (inFilterType == 4'b0101) begin
			for(i = 0; i < avgFilterSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				sampleSum = sampleSum + tempSample;
			end
			sample = sampleSum / avgFilterSampleSpan;
		end
		else begin
			sample = 0;
		end
	end
	
	assign outSample = sample;
endmodule
module ConvolutionFilter(
	input signed [11:0] inSample,
	input inSampleReady,
	









	input [3:0] inFilterType,
	
	output [11:0] outSample
);

	localparam avgFilterSampleSpan = 16;
	localparam singleCutoffSampleSpan = 8;
	localparam singleCutoffIIRSampleSpan = 7;
	localparam multiCutoffSampleSpan = 17;
	
	localparam sampleSize = 12;
	localparam bufferedSamples = 20;
	
	reg [sampleSize * singleCutoffIIRSampleSpan - 1:0] IIRBuffer = 0;
	reg [sampleSize * bufferedSamples - 1:0] sampleBuffer = 0;
	reg signed [sampleSize - 1:0] sample = 0;
	reg signed [sampleSize - 1:0] tempSample = 0;
	reg signed [64:0] sampleSum;
	reg signed [64:0] sampleIIRSum;
	
	integer i;
	integer j;
	integer bitIter;
	


	reg signed [sampleSize - 1:0] filterLowPass500[singleCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] filterHighPass500[singleCutoffSampleSpan - 1:0];

	reg signed [sampleSize - 1:0] filterBandPass500to2220[multiCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] filterBandReject500to2220[multiCutoffSampleSpan - 1:0];
	

	reg signed [sampleSize - 1:0] IIRfilterLowPass500[singleCutoffSampleSpan - 1:0];
	reg signed [sampleSize - 1:0] IIRfilterHighPass500[singleCutoffSampleSpan - 1:0];
	
	initial begin



		filterLowPass500[0] = 1;
		filterLowPass500[1] = 7;
		filterLowPass500[2] = 21;
		filterLowPass500[3] = 35;
		filterLowPass500[4] = 35;
		filterLowPass500[5] = 21;
		filterLowPass500[6] = 7;
		filterLowPass500[7] = 1;
		

		filterHighPass500[0] = -1;
		filterHighPass500[1] = 7;
		filterHighPass500[2] = -21;
		filterHighPass500[3] = 35;
		filterHighPass500[4] = -35;
		filterHighPass500[5] = 21;
		filterHighPass500[6] = -7;
		filterHighPass500[7] = 1;
		

		filterBandPass500to2220[0] = 1;
		filterBandPass500to2220[1] = 0; 
		filterBandPass500to2220[2] = -8; 
		filterBandPass500to2220[3] = 0; 
		filterBandPass500to2220[4] = 28;
		filterBandPass500to2220[5] = 0; 
		filterBandPass500to2220[6] = -56;
		filterBandPass500to2220[7] = 0;
		filterBandPass500to2220[8] = 70; 
		filterBandPass500to2220[9] = 0; 
		filterBandPass500to2220[10] = -56; 
		filterBandPass500to2220[11] = 0; 
		filterBandPass500to2220[12] = 28; 
		filterBandPass500to2220[13] = 0; 
		filterBandPass500to2220[14] = -8; 
		filterBandPass500to2220[15] = 0;
		filterBandPass500to2220[16] = 1;
		

		filterBandReject500to2220[0] = 1;
		filterBandReject500to2220[1] = -15; 
		filterBandReject500to2220[2] = 117; 
		filterBandReject500to2220[3] = -543; 
		filterBandReject500to2220[4] = 1755;
		filterBandReject500to2220[5] = -4190; 
		filterBandReject500to2220[6] = 7652;
		filterBandReject500to2220[7] = -10908;
		filterBandReject500to2220[8] = 12262; 
		filterBandReject500to2220[9] = -10908; 
		filterBandReject500to2220[10] = 7652; 
		filterBandReject500to2220[11] = -4190; 
		filterBandReject500to2220[12] = 1755; 
		filterBandReject500to2220[13] = -543; 
		filterBandReject500to2220[14] = 117; 
		filterBandReject500to2220[15] = -15;
		filterBandReject500to2220[16] = 1;
		


		IIRfilterLowPass500[0] = 0;
		IIRfilterLowPass500[1] = -5;
		IIRfilterLowPass500[2] = 16;
		IIRfilterLowPass500[3] = -29;
		IIRfilterLowPass500[4] = 30;
		IIRfilterLowPass500[5] = -19;
		IIRfilterLowPass500[6] = 6;

		

		IIRfilterLowPass500[0] = 0;
		IIRfilterLowPass500[1] = -5;
		IIRfilterLowPass500[2] = 16;
		IIRfilterLowPass500[3] = -29;
		IIRfilterLowPass500[4] = 30;
		IIRfilterLowPass500[5] = -19;
		IIRfilterLowPass500[6] = 6;

		
	end
	
	always @(posedge inSampleReady) begin
		sampleBuffer = sampleBuffer << 12;
		sampleBuffer[11:0] = inSample;
		sampleSum = 0;
		sampleIIRSum = 0;
		bitIter = 0;
		
		if(inFilterType == 4'b0000) begin
			sample = inSample;
		end
		else if (inFilterType == 4'b0001 || inFilterType == 4'b1001 || inFilterType == 4'b0010 || inFilterType == 4'b1010) begin
			for(i = 0; i < singleCutoffSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				if(inFilterType == 4'b0001) begin
					tempSample = tempSample * filterLowPass500[i];
				end
				else if (inFilterType == 4'b0010) begin
					tempSample = tempSample * filterHighPass500[i];
				end
				sampleSum = sampleSum + tempSample;
			end

			sampleSum = sampleSum / 64;
			
			IIRBuffer = IIRBuffer << 12;
			IIRBuffer[11:0] = sampleSum;
			

			if(inFilterType == 4'b1001 || inFilterType == 4'b1010) begin
				bitIter = 0;
				for(i = 0; i < singleCutoffIIRSampleSpan; i = i + 1) begin

					for(j = 0; j < sampleSize; j = j + 1) begin
						tempSample[j] = sampleBuffer[bitIter];
						bitIter = bitIter + 1;
					end
					if(inFilterType == 4'b0001) begin
						tempSample = tempSample * IIRfilterLowPass500[i];
					end
					else if (inFilterType == 4'b0010) begin
						tempSample = tempSample * IIRfilterHighPass500[i];
					end
					sampleIIRSum = sampleIIRSum + tempSample;
				end
				sampleIIRSum = sampleIIRSum / 128;
				sample = sampleSum + sampleIIRSum;
			end	
			else begin
				sample = sampleSum;
			end
		end 
		else if (inFilterType == 4'b0011 || inFilterType == 4'b0100) begin
			for(i = 0; i < multiCutoffSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				if(inFilterType == 4'b0011) begin
					tempSample = tempSample * filterBandPass500to2220[i];
				end
				else if (inFilterType == 4'b0100) begin
					tempSample = tempSample * filterBandReject500to2220[i];
				end
				sampleSum = sampleSum + tempSample;
			end

			sample = sampleSum / 16;
		end 
		else if (inFilterType == 4'b0101) begin
			for(i = 0; i < avgFilterSampleSpan; i = i + 1) begin

				for(j = 0; j < sampleSize; j = j + 1) begin
					tempSample[j] = sampleBuffer[bitIter];
					bitIter = bitIter + 1;
				end
				sampleSum = sampleSum + tempSample;
			end
			sample = sampleSum / avgFilterSampleSpan;
		end
		else begin
			sample = 0;
		end
	end
	
	assign outSample = sample;
endmodule