Преглед изворни кода

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

ChStepan пре 1 година
родитељ
комит
429c323105

+ 27 - 27
src/src/ExtDspInterface/DspInterface.v

@@ -229,20 +229,20 @@ DspSlaveSpi
 	.Miso_o		(Miso_o)
 );
 
-// DecimFilterWrapperTest	DecimFilter
-// (
-	// .Clk_i			(Clk_i),
-	// .Rst_i			(Rst_i),
-	// .DataVal_i		(OscWind_i),
-	// .DecimFactor_i	(DecimFactor_i),
+DecimFilterWrapperTest	DecimFilter
+(
+	.Clk_i			(Clk_i),
+	.Rst_i			(Rst_i),
+	.DataVal_i		(OscWind_i),
+	.DecimFactor_i	(DecimFactor_i),
 	
 	
-	// .Data_i		(currDataChannel),
+	.Data_i		(currDataChannel),
 	// .TestData_o		(testData),
 	
-	// .Data_o	(filteredDecimData),
-	// .DataVal_o	(filteredDecimDataVal)
-// );
+	.Data_o	(filteredDecimData),
+	.DataVal_o	(filteredDecimDataVal)
+);
 
 reg [15:0] currDecimFactor;
 reg [15:0] currDecimFactorR;
@@ -343,26 +343,26 @@ always @(posedge Clk_i) begin
 	end	
 end
 
-CicTest CicCompilerTest (
-  .aclk(Clk_i),                                  // input wire aclk
-  .s_axis_config_tdata(s_axis_config_tdata),    // input wire [15 : 0] s_axis_config_tdata
-  .s_axis_config_tvalid(s_axis_config_tvalid),  // input wire s_axis_config_tvalid
-  .s_axis_config_tready(s_axis_config_tready),  // output wire s_axis_config_tready
+// CicTest CicCompilerTest (
+  // .aclk(Clk_i),                                  // input wire aclk
+  // .s_axis_config_tdata(s_axis_config_tdata),    // input wire [15 : 0] s_axis_config_tdata
+  // .s_axis_config_tvalid(s_axis_config_tvalid),  // input wire s_axis_config_tvalid
+  // .s_axis_config_tready(s_axis_config_tready),  // output wire s_axis_config_tready
   
-  .s_axis_data_tdata(s_axis_data_tdata),        // input wire [15 : 0] s_axis_data_tdata
-  .s_axis_data_tvalid(s_axis_data_tvalid),      // input wire s_axis_data_tvalid
-  .s_axis_data_tready(s_axis_data_tready),      // output wire s_axis_data_tready
+  // .s_axis_data_tdata(s_axis_data_tdata),        // input wire [15 : 0] s_axis_data_tdata
+  // .s_axis_data_tvalid(s_axis_data_tvalid),      // input wire s_axis_data_tvalid
+  // .s_axis_data_tready(s_axis_data_tready),      // output wire s_axis_data_tready
   
-  .m_axis_data_tdata(filteredDecimData),        // output wire [31 : 0] m_axis_data_tdata
-  .m_axis_data_tvalid(filteredDecimDataVal)      // output wire m_axis_data_tvalid
-);
+  // .m_axis_data_tdata(filteredDecimData),        // output wire [31 : 0] m_axis_data_tdata
+  // .m_axis_data_tvalid(filteredDecimDataVal)      // output wire m_axis_data_tvalid
+// );
 
 OscDataFormer	DecimDataFormer
 (
 	.Clk_i				(Clk_i), 
 	.Rst_i				(Rst_i),	
-	.OscWind_i			(s_axis_data_tvalid),
-	// .OscWind_i			(OscWind_i),
+	// .OscWind_i			(s_axis_data_tvalid),
+	.OscWind_i			(OscWind_i),
 	.MeasNum_i			(MeasNum_i),
 
 	.AdcDataVal_i		(filteredDecimDataVal),
@@ -400,10 +400,10 @@ MeasDataFifoInst
 	.MeasNum_i		(MeasNum_i),	
 	.StartMeasDsp_i	(StartMeasDsp_i),	
 	.DspReadyForRx_i(DspReadyForRx_i),	
-	// .MeasDataBus_i	(measDataBus),
-	.MeasDataBus_i	(dataForFifo),
-	// .MeasDataVal_i	(LpOutStart_i),	
-	.MeasDataVal_i	(dataForFifoVal),	
+	.MeasDataBus_i	(measDataBus),
+	// .MeasDataBus_i	(dataForFifo),
+	.MeasDataVal_i	(LpOutStart_i),	
+	// .MeasDataVal_i	(dataForFifoVal),	
 	
 	.MeasDataBus_o	(measDataBusTx),
 	.MeasDataVal_o	(measDataValTx)

+ 30 - 8
src/src/FftDataFiltering/DecimFilterWrapperTest.v

@@ -5,7 +5,7 @@
 // 
 // create date:    16:37:06 07/11/2019 
 // design name: 
-// module name:    dsp_linkport_interface 
+// module name:    
 // project name: 
 // target devices: 
 // tool versions: 
@@ -18,12 +18,13 @@
 // additional comments: 
 //
 //////////////////////////////////////////////////////////////////////////////////
+
 module	DecimFilterWrapperTest
 #(	
 	parameter	InDataWidth		=	14,
-	parameter	N	=	1,
-	parameter	M	=	1,
-	parameter	OutDataWidth	=	15
+	parameter	N	=	4,
+	parameter	M	=	2,
+	parameter	OutDataWidth	=	17
 )
 (
 	input	Clk_i,
@@ -33,18 +34,20 @@ module	DecimFilterWrapperTest
 	input	DataVal_i,
 	input	signed	[InDataWidth-1:0]	Data_i,
 	
-	output	signed	[OutDataWidth-1:0]	Data_o,
+	output	signed	[InDataWidth-1:0]	Data_o,
 	output	DataVal_o
 );
+
 //================================================================================
 //	REG/WIRE
 //================================================================================
+
 	wire	signed	[OutDataWidth-1:0]	decimData;
 	wire	decimDataVal;
 	
 	localparam	extendBitNum	=	OutDataWidth-InDataWidth;
 	
-	wire	[OutDataWidth-1:0]	adcExtData	=	{{extendBitNum{Data_i[InDataWidth-1]}},Data_i};
+	wire	[OutDataWidth-1:0]	adcExtData	=	(InDataWidth<OutDataWidth)? {{extendBitNum{Data_i[InDataWidth-1]}},Data_i}:Data_i;
 	
 	wire	[OutDataWidth-1:0]	inData	[N-1:0];
 	wire	intDataVal	[N-1:0];
@@ -52,11 +55,16 @@ module	DecimFilterWrapperTest
 	wire	[OutDataWidth-1:0]	cicBlockOutData	[N-1:0];
 	wire	cicBlockOutVal	[N-1:0];
 	
+	wire	[InDataWidth-1:0] shTest;
+	
 //================================================================================
 //	ASSIGNMENTS
 //================================================================================
 
-assign	Data_o	=	cicBlockOutData[N-1];
+assign	 shTest = cicBlockOutData[N-1]>>>14;
+
+// assign	Data_o	=	cicBlockOutData[N-1];
+assign	Data_o	=	shTest;
 assign	DataVal_o	=	cicBlockOutVal[N-1];
 
 //================================================================================
@@ -89,7 +97,21 @@ generate
 	
 endgenerate
 
-
+decimBlock
+#(	
+	.InDataWidth	(OutDataWidth)
+)
+decimBlockInst
+(
+	.Clk_i			(Clk_i),
+	.Rst_i			(Rst_i),
+	.DecimFactor_i	(DecimFactor_i),
+	.Data_i			(cicBlockOutData[N-1]),
+	.DataNd_i		(cicBlockOutVal[N-1]),
+	.Data_o			(decimData),
+	.DataValid_o	(decimDataVal)
+);	
+		
 endmodule
 
 

+ 11 - 11
src/src/FftDataFiltering/decimBlock.v

@@ -20,22 +20,22 @@
 //////////////////////////////////////////////////////////////////////////////////
 module decimBlock
 #(	
-	// parameter	R	=	2,
-	parameter	inOutDataWidth	=	18,
-	parameter	decimCntWidth	=	7
+	parameter	InDataWidth	=	18
 )
 (
 	input Clk_i,
 	input Rst_i,
 	input [2:0]	DecimFactor_i,
-	input [inOutDataWidth-1:0] Data_i,
+	input [InDataWidth-1:0] Data_i,
 	input DataNd_i,
-	output [inOutDataWidth-1:0] Data_o,
+	output [InDataWidth-1:0] Data_o,
 	output DataValid_o
 );
 
-reg	[decimCntWidth-1:0]	decimCnt;
-reg	[inOutDataWidth-1:0]	dataReg;
+localparam CntWidth = 7;
+
+reg	[CntWidth-1:0]	decimCnt;
+reg	[InDataWidth-1:0]	dataReg;
 reg	valReg;
 
 reg	[2:0]	decimFactor;
@@ -52,23 +52,22 @@ always	@(posedge	Clk_i)	begin
 	end
 end
 
-
 always	@(posedge	Clk_i)	begin
 	if	(!Rst_i)	begin
 		if	(DataNd_i)	begin
 			if	(decimCnt	==	decimFactor-1)	begin
-				decimCnt	<=	{decimCntWidth{1'b0}};
+				decimCnt	<=	{CntWidth{1'b0}};
 				valReg		<=	1'b1;
 			end	else	begin
 				decimCnt	<=	decimCnt+7'd1;
 				valReg		<=	1'b0;
 			end
 		end	else	begin
-			decimCnt	<=	{decimCntWidth{1'b0}};
+			decimCnt	<=	{CntWidth{1'b0}};
 			valReg		<=	1'b0;
 		end
 	end	else	begin
-		decimCnt	<=	{decimCntWidth{1'b0}};
+		decimCnt	<=	{CntWidth{1'b0}};
 		valReg		<=	1'b0;
 	end
 end
@@ -85,4 +84,5 @@ end
 
 assign	Data_o	=	dataReg;
 assign	DataValid_o	=	valReg;
+
 endmodule

+ 9 - 8
src/src/Sim/DecimFilterWrapperTb.v

@@ -6,13 +6,13 @@ module DecimFilterWrapperTb	();
 //	PARAMETERS
 //================================================================================
 
-parameter	N	=	4;
-parameter	M	=	3;
+parameter	N	=	8;
+parameter	M	=	4;
 parameter	InDataWidth	=	14;
 
 parameter	K = N*20*($log10(M));
 parameter	BitGworth = $ceil(2**(K/20));
-parameter	MaxWidth = InDataWidth+BitGworth+1;
+parameter	MaxWidth = InDataWidth+BitGworth;
 
 parameter	[31:0]	Nco1PhaseInc	=	32'h40000000;
 parameter	[31:0]	Nco2PhaseInc	=	32'h0F5C28F6;
@@ -34,14 +34,15 @@ reg		[31:0]	tbCnt;
 wire	oscWind	=	(tbCnt>=100&tbCnt<=199)?	1'b1:1'b0;
 
 wire	resultVal;
+wire	impResponseVal;
 wire	respVal;
 
 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	[InDataWidth-1:0]	filteredDataOut;
+wire	signed	[InDataWidth-1:0]	impResponse;
 
 wire	signed	[InDataWidth*2-1:0]	adcDataMixed	=	(ncoSin1*ncoSin2);
 wire	signed	[InDataWidth-1:0]	adcDataMixedCut	=	adcDataMixed[26-:14];
@@ -174,14 +175,14 @@ DecimFilterWrapperTest
 ImpulseResponseFilter
 (
 	.Clk_i			(Clk50),
-	.DecimFactor_i	(decimFactor),
+	.DecimFactor_i	(1),
 	.Rst_i			(Rst),
 	.DataVal_i		(oscWind),
 
 	.Data_i		(singlePulse),
 	
 	.Data_o	(impResponse),
-	.DataVal_o	()
+	.DataVal_o	(impResponseVal)
 );
 	
 always	@(posedge	Clk50)	begin
@@ -213,7 +214,7 @@ 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	(resultVal)	begin
+		if	(impResponseVal)	begin
 			// $fwrite(impResp,"%d\n",   firRespout);
 			$fwrite(impResp,"%d\n",   impResponse);
 		end	

+ 36 - 36
src/src/Sim/FFTTest.m

@@ -56,7 +56,7 @@ ImpuseRespFft = abs(fft(ImpulseResp));
 ImpuseRespFftDb = 20*log10(ImpuseRespFft);
 ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
 
-Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
+Fband = 0:(Fs/R)/(PointsNum/R):(Fs/R)-1/(PointsNum/R);
 FbandOrig = 0:Fs/PointsNum:Fs-1/PointsNum;
 
 %InDataFftDb = InDataFftDb(1:length(Fband));
@@ -64,52 +64,52 @@ FbandOrig = 0:Fs/PointsNum:Fs-1/PointsNum;
 %ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-figure('name','In Data Time/Freq', 'Numbertitle', 'off')
-subplot(2,1,1)
-plot(InDataSignal)
+% figure('name','In Data Time/Freq', 'Numbertitle', 'off')
+% subplot(2,1,1)
+% plot(InDataSignal)
+% grid on;
+% grid minor;
+% title('In Signal')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(2,1,2)
+% plot(FilteredData)
+% grid on;
+% grid minor;
+% title('Filtered Data')
+% xlabel('Time')
+% ylabel('Amp')
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+figure('name','Frequency compare', 'Numbertitle', 'off')
+subplot(3,1,1)
+plot(FbandOrig,InDataFftDb)
 grid on;
 grid minor;
-title('In Signal')
+title('Single-Sided Amplitude Spectrum of Data before filter')
 xlabel('Time')
 ylabel('Amp')
 
-subplot(2,1,2)
-plot(FilteredData)
+subplot(3,1,2)
+plot(FbandOrig,ImpuseRespFftDb)
 grid on;
 grid minor;
-title('Filtered Data')
-xlabel('Time')
+title('Cic Frequency response')
+xlabel('f (Hz)')
 ylabel('Amp')
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 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')
+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(ImpulseResp)
+plot(FbandOrig,ImpulseResp)
 grid on;
 grid minor;
 title('In Signal')
@@ -117,7 +117,7 @@ xlabel('Time')
 ylabel('Amp')
 
 subplot(2,1,2)
-plot(ImpuseRespFftDb)
+plot(FbandOrig,ImpuseRespFftDb)
 grid on;
 grid minor;
 title('Single-Sided Amplitude Spectrum of InData')

+ 100 - 100
src/src/Sim/FilteredData.txt

@@ -1,100 +1,100 @@
-    -52
-   2558
-  15739
-  49262
-  99715
- 142551
- 147758
- 108224
-  43928
- -23684
- -87986
--145197
--182031
--188074
--167711
--129046
- -72256
-    -76
-  72114
- 128920
- 167602
- 187970
- 181931
- 145098
-  87891
-  23583
- -44040
--110731
--161878
--185053
--182233
--159060
--113549
- -46860
-  26403
-  90709
- 142280
- 179111
- 190791
- 170424
- 126112
-  69310
-   2763
- -69422
--131854
--170527
--185253
--179213
--148015
- -90806
- -20864
-  46746
- 107781
- 158912
- 187716
- 184896
- 156094
- 110599
-  49566
- -23684
- -93624
--145197
--176393
--188074
--173349
--129046
- -66618
-    -76
-  66476
- 128920
- 173240
- 187970
- 176293
- 145098
-  93529
-  23583
- -49678
--110731
--156240
--185053
--187871
--159060
--107911
- -46860
-  20765
-  90709
- 147918
- 179111
- 185153
- 170424
- 131750
-  69310
-  -2875
- -69422
--126216
--170527
--190891
--179213
--142377
- -90806
+    -1
+     0
+     1
+     8
+    31
+    92
+   227
+   480
+   889
+  1458
+  2138
+  2811
+  3303
+  3426
+  3035
+  2082
+   645
+ -1082
+ -2824
+ -4287
+ -5220
+ -5456
+ -4942
+ -3739
+ -2012
+    -4
+  2005
+  3731
+  4933
+  5442
+  5186
+  4201
+  2626
+   682
+ -1358
+ -3208
+ -4607
+ -5360
+ -5360
+ -4607
+ -3208
+ -1358
+   682
+  2626
+  4201
+  5186
+  5442
+  4934
+  3732
+  2005
+    -3
+ -2012
+ -3738
+ -4940
+ -5448
+ -5192
+ -4208
+ -2633
+  -689
+  1351
+  3201
+  4600
+  5352
+  5352
+  4600
+  3201
+  1351
+  -689
+ -2633
+ -4208
+ -5193
+ -5449
+ -4940
+ -3738
+ -2012
+    -4
+  2005
+  3731
+  4933
+  5442
+  5186
+  4201
+  2626
+   682
+ -1358
+ -3208
+ -4607
+ -5360
+ -5360
+ -4607
+ -3208
+ -1358
+   682
+  2626
+  4201
+  5186
+  5442
+  4934
+  3732
+  2005

+ 100 - 100
src/src/Sim/ImpResp.txt

@@ -1,100 +1,100 @@
-   8191
-  32764
-  81910
- 131056
- 155629
- 131056
-  81910
-  32764
-   8191
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
-      0
+     0
+     3
+    17
+    59
+   160
+   363
+   713
+  1235
+  1911
+  2663
+  3363
+  3863
+  4045
+  3863
+  3363
+  2663
+  1911
+  1235
+   713
+   363
+   160
+    59
+    17
+     3
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0
+     0