Prechádzať zdrojové kódy

Реализуется новый cic фильтр.

ChStepan 1 rok pred
rodič
commit
ff7a1a3596

+ 50 - 0
src/src/FftDataFiltering/CicBlock.v

@@ -0,0 +1,50 @@
+module CicBlock
+#(
+	parameter 	M = 1,			
+	parameter	InDataWidth	=	14,
+	parameter	OutDataWidth	=	15
+)
+(
+	input Clk_i,
+	input Rst_i,
+	input [InDataWidth-1:0] Data_i,
+	input DataNd_i,
+	output [OutDataWidth-1:0] Data_o,
+	output DataValid_o
+);
+
+wire	[OutDataWidth-1:0]	intFilteredData;
+wire	intFilteredDataValid;
+wire	intDataVal;
+
+	intFilterBlock 
+	#(	
+		.InDataWidth	(InDataWidth),
+		.OutDataWidth	(OutDataWidth)
+	)
+	intFilterBlockInst
+	(
+		.Clk_i(Clk_i),
+		.Rst_i(Rst_i),
+		.Data_i(Data_i),
+		.DataNd_i(DataNd_i),
+		.Data_o(intFilteredData),
+		.DataValid_o(intFilteredDataValid)
+	);
+		
+	combFilterBlock 
+	#(	
+		.M(M),
+		.InOutDataWidth	(OutDataWidth)
+	)
+	combFilterBlockInst
+	(
+		.Clk_i(Clk_i),
+		.Rst_i(Rst_i),
+		.Data_i(intFilteredData),
+		.DataNd_i(intFilteredDataValid),
+		.Data_o(Data_o),
+		.DataValid_o(DataValid_o)
+	);
+
+endmodule

+ 41 - 44
src/src/FftDataFiltering/DecimFilterWrapperTest.v

@@ -20,15 +20,10 @@
 //////////////////////////////////////////////////////////////////////////////////
 module	DecimFilterWrapperTest
 #(	
-	parameter	AdcDataWidth		=	14,
-	parameter	N	=	4,
+	parameter	InDataWidth		=	14,
+	parameter	N	=	1,
 	parameter	M	=	1,
-	parameter	FilteredDataWidth	=	32,
-	parameter	FirOutDataWidth		=	48,
-	parameter	FirOutCutBit		=	42,
-	parameter	LsbForR1	=	10'd16,
-	parameter	LsbForR2	=	10'd16,
-	parameter	LsbForR4	=	10'd16
+	parameter	OutDataWidth	=	15
 )
 (
 	input	Clk_i,
@@ -36,62 +31,64 @@ module	DecimFilterWrapperTest
 	input	Rst_i,
 	
 	input	DataVal_i,
-	input	signed	[AdcDataWidth-1:0]	Data_i,
+	input	signed	[InDataWidth-1:0]	Data_i,
 	
-	// output	signed	[16-1:0]	Data_o,
-	output	signed	[FilteredDataWidth-1:0]	Data_o,
+	output	signed	[OutDataWidth-1:0]	Data_o,
 	output	DataVal_o
 );
 //================================================================================
 //	REG/WIRE
 //================================================================================
-	wire	signed	[FilteredDataWidth-1:0]	decimData;
+	wire	signed	[OutDataWidth-1:0]	decimData;
 	wire	decimDataVal;
 	
-	localparam	extendBitNum	=	FilteredDataWidth-AdcDataWidth;
+	localparam	extendBitNum	=	OutDataWidth-InDataWidth;
 	
-	wire	[FilteredDataWidth-1:0]	adcExtData	=	{{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i};
+	wire	[OutDataWidth-1:0]	adcExtData	=	{{extendBitNum{Data_i[InDataWidth-1]}},Data_i};
+	
+	wire	[OutDataWidth-1:0]	inData	[N-1:0];
+	wire	intDataVal	[N-1:0];
+	
+	wire	[OutDataWidth-1:0]	cicBlockOutData	[N-1:0];
+	wire	cicBlockOutVal	[N-1:0];
 	
-	reg dataValReg;
-	wire dataValNeg = !DataVal_i&dataValReg;
-
 //================================================================================
 //	ASSIGNMENTS
 //================================================================================
 
-	assign Data_o		=	decimData;
-	assign DataVal_o	=	decimDataVal;
+assign	Data_o	=	cicBlockOutData[N-1];
+assign	DataVal_o	=	cicBlockOutVal[N-1];
 
 //================================================================================
 //	CODING
 //================================================================================
-	always @(posedge Clk_i) begin
-		if (!Rst_i) begin
-			dataValReg <= DataVal_i;
-		end else begin
-			dataValReg <= 0;
-		end
+
+genvar i;
+generate 
+	for (i=0; i<N; i=i+1)	begin: CicBlockGen
+		
+		assign	inData	[i]		=	(i==0)?adcExtData:cicBlockOutData[i-1];
+		assign	intDataVal[i]	=	(i==0)?DataVal_i:cicBlockOutVal[i-1];
+		
+		CicBlock 
+		#(
+			.M (M),	//comb delay
+			.InDataWidth	(OutDataWidth),
+			.OutDataWidth	(OutDataWidth)
+		)
+		CicBlock
+		(
+			.Clk_i			(Clk_i),
+			.Rst_i			(Rst_i),
+			.Data_i			(inData[i]),
+			.DataNd_i		(intDataVal[i]),
+			.Data_o			(cicBlockOutData[i]),
+			.DataValid_o	(cicBlockOutVal[i])
+		);
 	end
 	
-cicFilterTest 
-#(
-	.N (N),	//filter order
-	.M (M),	//comb delay
-	.filteredDataWidth	(FilteredDataWidth),
-	.inOutDataWidth		(FilteredDataWidth),
-	.decimCntWidth		(7)
-)
-cicFilterInstI
-(
-	.Clk_i			(Clk_i),
-	// .Rst_i			(Rst_i),
-	.Rst_i			(Rst_i|!DataVal_i),
-	.DecimFactor_i	(DecimFactor_i),
-	.Data_i			({{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i}),
-	.DataNd_i		(DataVal_i),
-	.Data_o			(decimData),
-	.DataValid_o	(decimDataVal)
-);
+endgenerate
+
 
 endmodule
 

+ 43 - 30
src/src/FftDataFiltering/combFilterBlock.v

@@ -1,50 +1,63 @@
 module combFilterBlock 
 #(
 	parameter	M=4,
-	parameter	inOutDataWidth	=	18,
-	parameter	filteredDataWidth	=	25
+	parameter	InOutDataWidth	=	18
 )
 (
 	input Clk_i,
 	input Rst_i,
-	input [inOutDataWidth-1:0] Data_i,
+	input [InOutDataWidth-1:0] Data_i,
 	input DataNd_i,
-	output [inOutDataWidth-1:0] Data_o,
+	output [InOutDataWidth-1:0] Data_o,
 	output DataValid_o
 );
 
-
-	
-reg signed	[inOutDataWidth-1:0] sumResult;
+reg ndReg;
+reg	signed	[InOutDataWidth-1:0]	inReg;
+reg signed	[InOutDataWidth-1:0]	sumResult;
 reg	dataValid;
-reg	signed	[inOutDataWidth-1:0] delData;
+reg	signed	[InOutDataWidth-1:0] delData	[M-1:0];
 
-assign Data_o = sumResult;
-assign DataValid_o = dataValid;
-	
-always @(posedge Clk_i) begin
-	if (Rst_i) begin
-		delData <= 0;
-	end else begin
-		if (DataNd_i) begin
-			delData	<= Data_i;
+	always	@(posedge Clk_i)	begin
+		if	(!Rst_i)	begin
+			ndReg <= DataNd_i;
+			if	(DataNd_i)	begin
+				inReg	<=	Data_i;
+			end
+		end	else	begin
+			ndReg	<=	0;
+			inReg	<=	0;
 		end
 	end
-end
 
-always @(posedge Clk_i or posedge Rst_i) begin
-	if (Rst_i) begin
-		sumResult <= 0;
-		dataValid <= 1'b0;
-	end else begin
-		if (DataNd_i) begin
-			sumResult <= Data_i-delData;
-			dataValid <= 1'b1;
-		end else begin
-			dataValid <= 1'b0;
+genvar i;
+generate 
+	for (i=0; i<M; i=i+1)	begin:combGen
+		always	@(posedge	Clk_i)	begin
+			if	(i==0)	begin
+				delData	[i]	<=	inReg;
+			end	else	begin
+				delData	[i]	<=	delData[i-1];
+			end
 		end
 	end
-end
-
+	
+	always	@(posedge	Clk_i)	begin
+		if	(!Rst_i)	begin
+			if	(ndReg)	begin
+				sumResult	<=	inReg+-delData[M-1];
+				dataValid	<=	1'b1;
+			end	else	begin
+				dataValid	<=	1'b0;
+				// sumResult	<=	0;
+			end
+		end	else	begin
+			sumResult	<=	0;
+			dataValid	<=	1'b0;
+		end
+	end
+endgenerate
 
+assign	Data_o	=	sumResult;
+assign	DataValid_o	=	dataValid;
 endmodule

+ 18 - 6
src/src/FftDataFiltering/decimBlock.v

@@ -35,6 +35,8 @@ module decimBlock
 );
 
 reg	[decimCntWidth-1:0]	decimCnt;
+reg	[inOutDataWidth-1:0]	dataReg;
+reg	valReg;
 
 reg	[2:0]	decimFactor;
 
@@ -56,21 +58,31 @@ always	@(posedge	Clk_i)	begin
 		if	(DataNd_i)	begin
 			if	(decimCnt	==	decimFactor-1)	begin
 				decimCnt	<=	{decimCntWidth{1'b0}};
-				// valReg		<=	1'b1;
+				valReg		<=	1'b1;
 			end	else	begin
 				decimCnt	<=	decimCnt+7'd1;
-				// valReg		<=	1'b0;
+				valReg		<=	1'b0;
 			end
 		end	else	begin
 			decimCnt	<=	{decimCntWidth{1'b0}};
-			// valReg		<=	1'b0;
+			valReg		<=	1'b0;
 		end
 	end	else	begin
-		// valReg		<=	1'b0;
 		decimCnt	<=	{decimCntWidth{1'b0}};
+		valReg		<=	1'b0;
+	end
+end
+	
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		if	(decimCnt	==	decimFactor-1)	begin
+			dataReg	<=	Data_i;
+		end	
+	end	else	begin
+		dataReg	<=	0;
 	end
 end
 
-assign	Data_o	=	Data_i;
-assign	DataValid_o	=	DataNd_i? (decimCnt	==	0):1'b0;
+assign	Data_o	=	dataReg;
+assign	DataValid_o	=	valReg;
 endmodule

+ 37 - 21
src/src/FftDataFiltering/intFilterBlock.v

@@ -1,37 +1,53 @@
 module intFilterBlock 
 #(	
-	parameter	inOutDataWidth	=	18,
-	parameter	filteredDataWidth	=	25
+	parameter	InDataWidth	=	18,
+	parameter	OutDataWidth	=	25
 )
 (
 	input Clk_i,
 	input Rst_i,
-	input [inOutDataWidth-1:0] Data_i,
+	input [InDataWidth-1:0] Data_i,
 	input DataNd_i,
-	output [filteredDataWidth-1:0] Data_o,
+	output [OutDataWidth-1:0] Data_o,
 	output DataValid_o
 );
 
-	reg [filteredDataWidth-1:0] outAcc;
-	reg outVal;
+	reg [1:0] ndShReg;
 	
-	assign Data_o = outAcc;
-	assign DataValid_o = outVal;
-	
-	always @(posedge Clk_i or posedge Rst_i) begin
-		if (Rst_i) begin
-			outAcc <= 0;
-			outVal <= 1'b0;
-		end else begin
-			if (DataNd_i) begin
-				outAcc <= outAcc+Data_i;
-				outVal <= 1'b1;
-			end else begin
-				outAcc <= 0;
-				outVal <= 1'b0;
-			end 
+	always @ (posedge Clk_i)	begin
+		if	(!Rst_i)	begin
+			ndShReg <= {ndShReg[0:0], DataNd_i};
+		end	else	begin
+			ndShReg <= 2'h0;
 		end
 	end
 	
+	reg signed [InDataWidth-1:0] inReg;
+	reg signed [OutDataWidth-1:0] sumResult;
+	
+	always	@(posedge	Clk_i)	begin
+		if (!Rst_i)	begin
+			if (DataNd_i)	begin
+				inReg <= Data_i;
+			end
+		end	else	begin
+			inReg	<= 0;
+		end
+	end
 	
+	always @ (posedge Clk_i)	begin
+		if (!Rst_i)	begin
+			if (ndShReg[0])	begin
+				sumResult <= inReg + sumResult;
+			end	else	begin
+				sumResult <= 0;
+			end
+		end	else	begin
+			sumResult	<=	0;
+		end
+	end
+
+	assign Data_o = sumResult;
+	assign DataValid_o = ndShReg[1];
+
 endmodule

+ 1 - 1
src/src/Sim/BitWidthCalc.m

@@ -7,7 +7,7 @@ FormatSpecW = '%X\n';
 %FormatSpecW = '%h\n';
 
 MaxArg = 2^32;
-Fc = 3;
+Fc = 10;
 Fs = 50;
 
 Fnqst = (Fs/R)/2

+ 28 - 31
src/src/Sim/CicTestMatlab.m

@@ -1,6 +1,6 @@
-m = 1;  % Differential delays in the filter.
-n = 2;  % Filter sections
-r = 2;   % Decimation factor
+m = 2;  % Differential delays in the filter.
+n = 4;  % Filter sections
+r = 1;   % Decimation factor
 x = int16(zeros(160,1)); x(1) = 1;    % Create a 160-point
                                       % impulse signal.
 hm = mfilt.cicdecim(r,m,n); % Expects 16-bit input
@@ -14,33 +14,30 @@ yCorr = double(y);
 
 FilteredDataFft = abs(fft(yCorr));
 FilteredDataFftDb = 20*log10(FilteredDataFft);
-% FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
-
-hm = mfilt.cicdecim(r,m,n);
-fvtool(hm)
+FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% figure('name','In Data Time/Freq', 'Numbertitle', 'off')
-% subplot(3,1,1)
-% plot(x)
-% grid on;
-% grid minor;
-% title('In Signal')
-% xlabel('Time')
-% ylabel('Amp')
-% 
-% subplot(3,1,2)
-% plot(yCorr)
-% grid on;
-% grid minor;
-% title('Imp Resp')
-% xlabel('Time')
-% ylabel('Amp')
-% 
-% subplot(3,1,3)
-% plot(FilteredDataFftDb)
-% grid on;
-% grid minor;
-% title('Filtered Data')
-% xlabel('Time')
-% ylabel('Amp')
+figure('name','In Data Time/Freq', 'Numbertitle', 'off')
+subplot(3,1,1)
+plot(x)
+grid on;
+grid minor;
+title('In Signal')
+xlabel('Time')
+ylabel('Amp')
+
+subplot(3,1,2)
+plot(yCorr)
+grid on;
+grid minor;
+title('Imp Resp')
+xlabel('Time')
+ylabel('Amp')
+
+subplot(3,1,3)
+plot(FilteredDataFftDb)
+grid on;
+grid minor;
+title('Filtered Data')
+xlabel('Time')
+ylabel('Amp')

+ 70 - 113
src/src/Sim/DecimFilterWrapperTb.v

@@ -2,77 +2,66 @@
 
 module DecimFilterWrapperTb	();
 
+//================================================================================
+//	PARAMETERS
+//================================================================================
+
+parameter	N	=	4;
+parameter	M	=	3;
+parameter	InDataWidth	=	14;
+
+parameter	K = N*20*($log10(M));
+parameter	BitGworth = $ceil(2**(K/20));
+parameter	MaxWidth = InDataWidth+BitGworth+1;
+
+parameter	[31:0]	Nco1PhaseInc	=	32'h40000000;
+parameter	[31:0]	Nco2PhaseInc	=	32'h0F5C28F6;
+
+
+
+//================================================================================
+//	REG/WIRE
+//================================================================================
+
+
 reg		Clk50;
 reg		Rst;
 
 reg		[2:0]	decimFactor;
 
-parameter	MaxWidth	=	32;
-
-reg		[13:0]	adcData;
-real	pi	=	3.14159265358;
-real	phase	=	0;
-real	phaseInc	=	0.001;
-real	signal;
-
 reg		[31:0]	tbCnt;
 
-wire 	[31:0] startValue = 32'd10;
-wire	[31:0] pNum = 1000;
-wire 	[31:0] stopValue = startValue+pNum-1;
+wire	oscWind	=	(tbCnt>=100&tbCnt<=199)?	1'b1:1'b0;
 
-// wire	oscWind	=	(tbCnt>=10&tbCnt<=509)?	1'b1:1'b0;
-wire	oscWind	=	(tbCnt>=startValue & tbCnt<=stopValue)?	1'b1:1'b0;
+wire	resultVal;
+wire	respVal;
 
-wire	signed	[13:0]	ncoSin1;
-wire	signed	[13:0]	ncoSin2;
-wire	signed	[13:0]	ncoSin3;
+wire	signed	[InDataWidth-1:0]	ncoSin1;
+wire	signed	[InDataWidth-1:0]	ncoSin2;
+wire	signed	[InDataWidth-1:0]	ncoSin3;
 
 wire	signed	[MaxWidth-1:0]	filteredDataOut;
 wire	signed	[MaxWidth-1:0]	impResponse;
-wire	signed	[MaxWidth-1:0]	impResponseTest;
 
-wire	resultVal;
-wire	impRespVal;
-wire	impRespValTest;
+wire	signed	[InDataWidth*2-1:0]	adcDataMixed	=	(ncoSin1*ncoSin2);
+wire	signed	[InDataWidth-1:0]	adcDataMixedCut	=	adcDataMixed[26-:14];
 
+wire	signed	[InDataWidth-1:0]	sinAdd	=	(ncoSin1>>>1)+(ncoSin2>>>1);
 
-// wire	signed	[27:0]	adcDataMixed	=	oscWind?(ncoSin1*ncoSin2):28'd0;
-wire	signed	[27:0]	adcDataMixed	=	(ncoSin1*ncoSin2);
-wire	signed	[13:0]	adcDataMixedCut	=	adcDataMixed[26-:14];
+wire	signed	[InDataWidth-1:0]	singlePulse	=	(tbCnt==100)?	14'h1fff:14'h0;
 
-// wire	signed	[13:0]	sinAdd	=	(ncoSin1>>>2)+(ncoSin2>>>2)+(ncoSin3>>>2);
-wire	signed	[13:0]	sinAdd	=	(ncoSin1>>>1)+(ncoSin2>>>1);
-// wire	signed	[13:0]	sinAdd	=	ncoSin1;
+integer inSignal,filteredData, impResp;
 
+//================================================================================
+//	CLK GEN
+//================================================================================
 
-// wire	signed	[13:0]	singlePulse	=	(tbCnt==10)?	14'h1fff:14'h0;
-// wire	signed	[15:0]	singlePulse	=	(tbCnt==10)?	16'h1fff:14'h0;
-// wire	signed	[15:0]	singlePulse	=	(tbCnt==10)?	16'h1:14'h0;
-wire	signed	[15:0]	singlePulse	=	(tbCnt>=10&tbCnt<=11)?	14'h1fff:14'h0;
-//==========================================================================================
-//clocks gen
 always	#10 Clk50	=	~Clk50;
 
-//==========================================================================================
-parameter	N	=	1;
-parameter	M	=	1;
-
-always	@(posedge	Clk50)	begin
-	if	(!Rst)	begin
-		decimFactor <= 0;
-	end else begin
-		decimFactor <= 0;
-	end 
-end
-
-parameter	LsbForR1	=	10'd16;
-parameter	LsbForR2	=	10'd18;
-parameter	LsbForR4	=	10'd18;
+//================================================================================
+//	CODING
+//================================================================================
 	
-parameter	[31:0]	Nco1PhaseInc	=	32'h051eb851;
-parameter	[31:0]	Nco2PhaseInc	=	32'h33333333;
-
 initial begin
 	Clk50		=	1'b1;
 	Rst			=	1'b1;
@@ -87,31 +76,31 @@ always	@(posedge	Clk50)	begin
 		tbCnt	<=	32'd0;
 	end
 end
-
-reg	[20:0]	oscWindDelay;
-
+	
 always	@(posedge	Clk50)	begin
 	if	(!Rst)	begin
-		oscWindDelay	<=	{oscWindDelay[20:0],oscWind};
-	end	else	begin
-		oscWindDelay	<= 22'd0;
-	end
-end
-
-always @ (posedge Clk50)	begin
-	if (oscWind)	begin
-			phase = phase + phaseInc;
-			phaseInc <= phaseInc + 0.003;
-			signal = $sin(2*pi*phase);
-			adcData = 2**12 * signal;
-	end	else	begin
-		adcData = 0;
-		phase	=	0;
-		phaseInc	=	0.001;
-	end
+		if (tbCnt == 100) begin
+			decimFactor	<= 2;
+		end
+		// end else if (tbCnt == 5400) begin
+			// decimFactor	<= 1;
+		// end else if (tbCnt == 6400) begin
+			// decimFactor	<= 2;
+		// end else if (tbCnt == 7400) begin
+			// decimFactor	<= 3;
+		// end else if (tbCnt == 8400) begin
+			// decimFactor	<= 4;
+		// end else if (tbCnt == 9400) begin
+			// decimFactor	<= 5;
+		// end else if (tbCnt == 10400) begin
+			// decimFactor	<= 6;
+		// end else if (tbCnt == 11400) begin
+			// decimFactor	<= 7;
+		// end
+	end else begin
+	 decimFactor <= 2;
+	end 
 end
-	
-
 
 CordicNco		
 #(	
@@ -157,15 +146,10 @@ ncoInst2
 
 DecimFilterWrapperTest	
 #(	
-	.AdcDataWidth	(14),
+	.InDataWidth	(InDataWidth),
 	.N	(N),
 	.M	(M),
-	.FilteredDataWidth	(MaxWidth),
-	.FirOutDataWidth	(48),
-	.FirOutCutBit		(42),
-	.LsbForR1			(LsbForR1),
-	.LsbForR2			(LsbForR2),
-	.LsbForR4			(LsbForR4)
+	.OutDataWidth	(MaxWidth)
 )
 DecimFilter
 (
@@ -175,9 +159,6 @@ DecimFilter
 	.DataVal_i		(oscWind),
 
 	.Data_i		(sinAdd),
-	// .Data_i		(adcDataMixedCut),
-	// .Data_i		(adcData),
-	// .Data_i		(ncoSin2),
 	
 	.Data_o	(filteredDataOut),
 	.DataVal_o	(resultVal)
@@ -185,15 +166,10 @@ DecimFilter
 
 DecimFilterWrapperTest	
 #(	
-	.AdcDataWidth	(16),
+	.InDataWidth	(InDataWidth),
 	.N	(N),
 	.M	(M),
-	.FilteredDataWidth	(MaxWidth),
-	.FirOutDataWidth	(48),
-	.FirOutCutBit		(42),
-	.LsbForR1			(LsbForR1),
-	.LsbForR2			(LsbForR2),
-	.LsbForR4			(LsbForR4)
+	.OutDataWidth	(MaxWidth)
 )
 ImpulseResponseFilter
 (
@@ -205,13 +181,9 @@ ImpulseResponseFilter
 	.Data_i		(singlePulse),
 	
 	.Data_o	(impResponse),
-	.DataVal_o	(impRespVal)
+	.DataVal_o	()
 );
-
-integer inSignal,filteredData, impResp;
-
-
-
+	
 always	@(posedge	Clk50)	begin
 	if	(tbCnt==32'd1)	begin
 		inSignal = $fopen("C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt","w");
@@ -225,28 +197,13 @@ always	@(posedge	Clk50)	begin
 	end	
 end
 
-reg	[31:0]	testCnt;
-wire	[10:0]	test = N*2+N*2+decimFactor;
-wire	[10:0]	test1 = N*2+N*2+decimFactor-1;
-// wire	writeEn	=	(oscWindDelay[N*2+N*2+decimFactor-2]);
-wire	writeEn	=	(tbCnt>= (startValue+(N*2)) & tbCnt <= (stopValue+(N*2)));
-
-always	@(posedge	Clk50)begin
-	if	(!Rst)	begin
-		if	(writeEn)	begin
-			testCnt	<=	testCnt	+1;
-		end
-	end	else	begin
-		testCnt	<=	0;
-	end
-end
-
 always	@(posedge	Clk50)	begin
 	if	(tbCnt==32'd1)	begin
 		filteredData = $fopen("C:/S5243_FFT_REPO/src/src/Sim/FilteredData.txt","w");
 	end	else	begin
 		if	(resultVal)	begin
 			$fwrite(filteredData,"%d\n",   filteredDataOut);
+			// $fwrite(filteredData,"%d\n",   firDataOut);
 		end	
 	end	
 end
@@ -256,8 +213,8 @@ always	@(posedge	Clk50)	begin
 	if	(tbCnt==32'd1)	begin
 		impResp = $fopen("C:/S5243_FFT_REPO/src/src/Sim/ImpResp.txt","w");
 	end	else	begin
-		// if	(writeEn)	begin
-		if	(impRespVal)	begin
+		if	(resultVal)	begin
+			// $fwrite(impResp,"%d\n",   firRespout);
 			$fwrite(impResp,"%d\n",   impResponse);
 		end	
 	end

+ 59 - 28
src/src/Sim/FFTTest.m

@@ -1,11 +1,11 @@
 FormatSpec = '%d';
 
-N = 1;
-R = 6;
-B = 16;
-M = 1;
+N = 3;
+R = 1;
+B = 14;
+M = 3;
 
-PointsNum = 1000;
+PointsNum = 100;
 
 Bmax = ceil(log2(((R*M)^N)/R)+B);
 MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
@@ -20,6 +20,7 @@ xDecim = 1:1:PointsNum/R;
 
 Fc = 3;
 Fs = 50;
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 ReadInDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt','r');
 InDataSignal = fscanf(ReadInDataId,FormatSpec);
@@ -41,19 +42,26 @@ fclose(ReadFilterCoefsId);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 FreqBandOrig = Fs*(1:(PointsNum))/PointsNum;
-FreqbandDecim = Fs*(1:((PointsNum/R)+1))/PointsNum;
+FreqbandDecim = (Fs/2*R)*(1:(PointsNum))/PointsNum;
 
 InDataFft = abs(fft(InDataSignal+randn(size(InDataSignal)))/PointsNum);
-InDataFftDb = 10*log10(InDataFft);
-InDataFftDb = InDataFftDb-max(InDataFftDb);
+InDataFftDb = 20*log10(InDataFft);
 
-% FilteredDataFft = abs(fft(FilteredData+randn(size(FilteredData)))/PointsNum);
-FilteredDataFft = abs(fft(FilteredData)/PointsNum);
+FilteredDataFft = abs(fft(FilteredData+randn(size(FilteredData)))/PointsNum);
+% FilteredDataFft = abs(fft(FilteredData)/PointsNum);
 FilteredDataFftDb = 20*log10(FilteredDataFft);
 FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
 
+ImpuseRespFft = abs(fft(ImpulseResp));
+ImpuseRespFftDb = 20*log10(ImpuseRespFft);
+ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
+
 Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
-FbandOrig = 0:1/PointsNum:1-1/PointsNum;
+FbandOrig = 0:Fs/PointsNum:Fs-1/PointsNum;
+
+%InDataFftDb = InDataFftDb(1:length(Fband));
+%FilteredDataFftDb = FilteredDataFftDb(1:length(Fband));
+%ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 figure('name','In Data Time/Freq', 'Numbertitle', 'off')
@@ -61,37 +69,60 @@ subplot(2,1,1)
 plot(InDataSignal)
 grid on;
 grid minor;
-title('In Signal');
-xlabel('Time');
-ylabel('Amp');
+title('In Signal')
+xlabel('Time')
+ylabel('Amp')
 
 subplot(2,1,2)
 plot(FilteredData)
 grid on;
 grid minor;
-title('Filtered Data');
-xlabel('Time');
-ylabel('Amp');
+title('Filtered Data')
+xlabel('Time')
+ylabel('Amp')
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-figure('name','Frequency compare', 'Numbertitle', 'off')
+% figure('name','Frequency compare', 'Numbertitle', 'off')
+% subplot(3,1,1)
+% plot(FbandOrig,InDataFftDb)
+% grid on;
+% grid minor;
+% title('Single-Sided Amplitude Spectrum of Data before filter')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(3,1,2)
+% plot(ImpuseRespFftDb)
+% grid on;
+% grid minor;
+% title('Cic Frequency response')
+% xlabel('f (Hz)')
+% ylabel('Amp')
+% 
+% subplot(3,1,3)
+% plot(Fband,FilteredDataFftDb)
+% grid on;
+% grid minor;
+% title('Single-Sided Amplitude Spectrum of Data after filter')
+% xlabel('f (Hz)')
+% ylabel('Amp')
+
+figure('name','Impulse Response Time/Freq', 'Numbertitle', 'off')
 subplot(2,1,1)
-plot(FreqBandOrig,InDataFftDb)
+plot(ImpulseResp)
 grid on;
 grid minor;
-% axis([0 25 -70 80]);
-title('Single-Sided Amplitude Spectrum of Data before filter');
-xlabel('Time');
-ylabel('Amp');
+title('In Signal')
+xlabel('Time')
+ylabel('Amp')
 
 subplot(2,1,2)
-plot(FreqbandDecim,FilteredDataFftDb)
+plot(ImpuseRespFftDb)
 grid on;
 grid minor;
-% axis([0 25 -70 80]);
-title('Single-Sided Amplitude Spectrum of Data after filter');
-xlabel('f (Hz)');
-ylabel('Amp');
+title('Single-Sided Amplitude Spectrum of InData')
+xlabel('f (Hz)')
+ylabel('Amp')
 
 
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 100 - 1000
src/src/Sim/FilteredData.txt


+ 46 - 28
src/src/Sim/ImpResp.m

@@ -1,36 +1,69 @@
 FormatSpec = '%d';
 
-N = 2;
-R = 2;
+N = 4;
+R = 4;
 B = 16;
 M = 1;
 
-PointsNum = 250;
-Fband = 0:1/PointsNum:1-1/PointsNum;
+PointsNum = 500;
+
+Bmax = ceil(log2(((R*M)^N)/R)+B);
+MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
+MaxWidthR4 = ceil(log2(((4*M)^N)/4)+B);
+
+K = N*20*log10(M);
+BitGrowth = ceil(2^(K/20));
+Bnew = B+BitGrowth;
+
+x = 1:1:PointsNum;
+xDecim = 1:1:PointsNum/R;
+
+Fc = 3;
+Fs = 50;
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ReadInDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt','r');
+InDataSignal = fscanf(ReadInDataId,FormatSpec);
+fclose(ReadInDataId);
+
+ReadFilteredDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/FilteredData.txt','r');
+FilteredData = fscanf(ReadFilteredDataId,FormatSpec);
+fclose(ReadFilteredDataId);
 
 ReadImpulseRestId = fopen('C:\S5243_FFT_REPO\src\src\Sim\ImpResp.txt','r');
 ImpulseResp = fscanf(ReadImpulseRestId,FormatSpec);
 fclose(ReadImpulseRestId);
 
-ReadImpulseRestTestId = fopen('C:\S5243_FFT_REPO\src\src\Sim\ImpRespTest.txt','r');
-ImpulseRespTest = fscanf(ReadImpulseRestTestId,FormatSpec);
-fclose(ReadImpulseRestTestId);
+ReadFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\CorrFilterCoefs.txt','r');
+FilterCoefs = fscanf(ReadFilterCoefsId,FormatSpec);
+fclose(ReadFilterCoefsId);
+
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+InDataFft = abs(fft(InDataSignal+randn(size(InDataSignal)))/PointsNum);
+InDataFftDb = 20*log10(InDataFft);
+
+FilteredDataFft = abs(fft(FilteredData+randn(size(FilteredData)))/PointsNum);
+% FilteredDataFft = abs(fft(FilteredData)/PointsNum);
+FilteredDataFftDb = 20*log10(FilteredDataFft);
+FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
+
 ImpuseRespFft = abs(fft(ImpulseResp));
 ImpuseRespFftDb = 20*log10(ImpuseRespFft);
 ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
 
-ImpuseRespTestFft = abs(fft(ImpulseRespTest));
-ImpuseRespTestFftDb = 20*log10(ImpuseRespTestFft);
-ImpuseRespTestFftDb = ImpuseRespTestFftDb-max(ImpuseRespTestFftDb);
+Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
+FbandOrig = 0:1/PointsNum:1-1/PointsNum;
+
+%InDataFftDb = InDataFftDb(1:length(Fband));
+%FilteredDataFftDb = FilteredDataFftDb(1:length(Fband));
+%ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-figure(1);
+
 subplot(2,1,1)
-plot(Fband,ImpulseResp)
+plot(ImpulseResp)
 grid on;
 grid minor;
 title('Cic Frequency response')
@@ -38,29 +71,14 @@ xlabel('f (Hz)')
 ylabel('Amp')
 
 subplot(2,1,2)
-plot(Fband,ImpuseRespFft)
+plot(ImpuseRespFftDb)
 grid on;
 grid minor;
 title('Cic Frequency response')
 xlabel('f (Hz)')
 ylabel('Amp')
 
-figure(2);
-subplot(2,1,1)
-plot(Fband,ImpulseRespTest)
-grid on;
-grid minor;
-title('Cic Frequency response')
-xlabel('f (Hz)')
-ylabel('Amp')
 
-subplot(2,1,2)
-plot(Fband,ImpuseRespTestFft)
-grid on;
-grid minor;
-title('Cic Frequency response')
-xlabel('f (Hz)')
-ylabel('Amp')
 
 
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 100 - 1000
src/src/Sim/ImpResp.txt


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 100 - 1000
src/src/Sim/InputSignal.txt


+ 10 - 10
src/src/Sim/S5243TopPulseProfileTb.v

@@ -71,7 +71,6 @@ module S5243TopPulseProfileTb;
 	
 	//COMMANDS	FOR REG_MAP
 	parameter	[31:0]	MeasCmdBypass	=	{8'h11,8'h0,8'h63,8'h5};
-	parameter	[31:0]	MeasCmdBypass2	=	{8'h11,8'h0,8'h63,8'hB};
 	// parameter	[31:0]	MeasCmdFft 		=	{8'h11,8'h0,8'h63,7'h5,1'b1};
 	// parameter	[31:0]	MeasCmd 		=	{8'h11,8'h0,8'h53,8'h0};
 	// parameter	[31:0]	MeasCmd =	{8'h11,8'h3e,8'h63,8'h0};
@@ -239,7 +238,7 @@ always	@(posedge	Clk70)	begin
 	if	(!rst)	begin
 		if	(!endMeas)	begin
 			// if	(tb_cnt	==	3550	|	tb_cnt	==	3950	|tb_cnt	==	4505)	begin
-			if	(tb_cnt	==	3550|tb_cnt	==	6200)	begin
+			if	(tb_cnt	==	3550)	begin
 				startCalcCmdReg	<=	1'b1;
 			end	
 		end	else	begin
@@ -261,8 +260,8 @@ end
 wire	Adc1DataDa0P;
 wire	Adc1DataDa1P;
 
-reg	[31:0]	nco1PhaseInc	=	32'h051eb851;
-reg	[31:0]	nco2PhaseInc	=	32'h33333333;
+wire	[31:0]	ncoPhInc1	=	32'h19999999;
+wire	[31:0]	ncoPhInc2	=	32'h33333333;
 
 CordicNco		
 #(	.ODatWidth	(14),
@@ -274,7 +273,7 @@ ncoInst1
 	.Clk_i				(Clk50),
 	.Rst_i				(rst),
 	.Val_i				(1'b1),
-	.PhaseInc_i			(nco1PhaseInc),
+	.PhaseInc_i			(ncoPhInc1),
 	.WindVal_i			(1'b1),
 	.WinType_i			(),
 	.Wind_o				(),
@@ -293,7 +292,7 @@ ncoInst2
 	.Clk_i				(Clk50),
 	.Rst_i				(rst),
 	.Val_i				(1'b1),
-	.PhaseInc_i			(nco2PhaseInc),
+	.PhaseInc_i			(ncoPhInc2),
 	.WindVal_i			(1'b1),
 	.WinType_i			(),
 	.Wind_o				(),
@@ -440,6 +439,7 @@ always	@(posedge	Clk41)	begin
 	end
 end
 	
+
 always	@(posedge	Clk41)	begin
 	if	(txCurrState	==	CMD)	begin
 		if	(cmdCnt	==	0)	begin
@@ -580,10 +580,10 @@ always	@(posedge	Clk41)	begin
 			DspSpiData		<=	MuxCtrl3RegCmd;
 		end	else	if	(cmdCnt	==	68)	begin
 			DspSpiData		<=	AdcCtrl;
-		end	else 	if	(cmdCnt	==	100) begin
-			DspSpiData		<=	MeasCmdBypass2;
-		end	else begin
-			DspSpiData	<=	32'h0;
+		end	else	if	(cmdCnt	==	99)	begin
+			DspSpiData		<=	{8'h58,24'd100};
+		end	else	begin
+			DspSpiData	<=	32'hfffffff;
 		end
 	end	else	if	(txCurrState	==	TX)	begin
 		DspSpiData	<=	DspSpiData<<1;