Sfoglia il codice sorgente

Тестовые изменения фильтров.

ChStepan 1 anno fa
parent
commit
af87a9f00b

File diff suppressed because it is too large
+ 10 - 21
src/constrs/S5243Top.xdc


+ 1 - 3
src/src/FftDataFiltering/DecimFilterWrapperTest.v

@@ -21,7 +21,7 @@
 module	DecimFilterWrapperTest
 #(	
 	parameter	AdcDataWidth		=	14,
-	parameter	N	=	9,
+	parameter	N	=	4,
 	parameter	M	=	1,
 	parameter	FilteredDataWidth	=	32,
 	parameter	FirOutDataWidth		=	48,
@@ -83,9 +83,7 @@ cicFilterTest
 cicFilterInstI
 (
 	.Clk_i			(Clk_i),
-	// .Rst_i			(Rst_i|dataValNeg),
 	.Rst_i			(Rst_i),
-	// .DecimFactor_i	(currDecimFactor),
 	.DecimFactor_i	(DecimFactor_i),
 	.Data_i			({{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i}),
 	.DataNd_i		(DataVal_i),

+ 14 - 13
src/src/Sim/DecimFilterWrapperTb.v

@@ -18,7 +18,7 @@ real	signal;
 reg		[31:0]	tbCnt;
 
 wire 	[31:0] startValue = 32'd10;
-wire	[31:0] pNum = 10;
+wire	[31:0] pNum = 1000;
 wire 	[31:0] stopValue = startValue+pNum-1;
 
 // wire	oscWind	=	(tbCnt>=10&tbCnt<=509)?	1'b1:1'b0;
@@ -30,12 +30,14 @@ wire	signed	[13: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	[27:0]	adcDataMixed	=	oscWfind?(ncoSin1*ncoSin2):28'd0;
+// 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];
 
@@ -45,19 +47,20 @@ wire	signed	[13:0]	sinAdd	=	(ncoSin1>>>1)+(ncoSin2>>>1);
 
 
 // wire	signed	[13:0]	singlePulse	=	(tbCnt==10)?	14'h1fff:14'h0;
-wire	signed	[13:0]	singlePulse	=	(tbCnt==10)?	14'h1:14'h0;
-// wire	signed	[13:0]	singlePulse	=	(tbCnt>=10&tbCnt<=12)?	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	=	3;
+parameter	N	=	6;
 parameter	M	=	1;
 
 always	@(posedge	Clk50)	begin
 	if	(!Rst)	begin
-		decimFactor <= 2;
+		decimFactor <= 6;
 	end else begin
 		decimFactor <= 0;
 	end 
@@ -67,7 +70,7 @@ parameter	LsbForR1	=	10'd16;
 parameter	LsbForR2	=	10'd18;
 parameter	LsbForR4	=	10'd18;
 	
-parameter	[31:0]	Nco1PhaseInc	=	32'h19999999;
+parameter	[31:0]	Nco1PhaseInc	=	32'h051eb851;
 parameter	[31:0]	Nco2PhaseInc	=	32'h33333333;
 
 initial begin
@@ -182,7 +185,7 @@ DecimFilter
 
 DecimFilterWrapperTest	
 #(	
-	.AdcDataWidth	(14),
+	.AdcDataWidth	(16),
 	.N	(N),
 	.M	(M),
 	.FilteredDataWidth	(MaxWidth),
@@ -204,10 +207,8 @@ ImpulseResponseFilter
 	.Data_o	(impResponse),
 	.DataVal_o	(impRespVal)
 );
-	
 
 integer inSignal,filteredData, impResp;
-parameter	PNum	=	5000;
 
 
 
@@ -228,7 +229,7 @@ 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)+1) & tbCnt <= (stopValue+(N*2)+1));
+wire	writeEn	=	(tbCnt>= (startValue+(N*2)) & tbCnt <= (stopValue+(N*2)));
 
 always	@(posedge	Clk50)begin
 	if	(!Rst)	begin
@@ -255,8 +256,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	(writeEn)	begin
+		if	(impRespVal)	begin
 			$fwrite(impResp,"%d\n",   impResponse);
 		end	
 	end

+ 24 - 58
src/src/Sim/FFTTest.m

@@ -1,11 +1,11 @@
 FormatSpec = '%d';
 
 N = 1;
-R = 2;
+R = 6;
 B = 16;
 M = 1;
 
-PointsNum = 496;
+PointsNum = 1000;
 
 Bmax = ceil(log2(((R*M)^N)/R)+B);
 MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
@@ -20,7 +20,6 @@ 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);
@@ -42,26 +41,19 @@ fclose(ReadFilterCoefsId);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 FreqBandOrig = Fs*(1:(PointsNum))/PointsNum;
-FreqbandDecim = (Fs/2*R)*(1:(PointsNum))/PointsNum;
+FreqbandDecim = Fs*(1:((PointsNum/R)+1))/PointsNum;
 
 InDataFft = abs(fft(InDataSignal+randn(size(InDataSignal)))/PointsNum);
-InDataFftDb = 20*log10(InDataFft);
+InDataFftDb = 10*log10(InDataFft);
+InDataFftDb = InDataFftDb-max(InDataFftDb);
 
-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;
-
-%InDataFftDb = InDataFftDb(1:length(Fband));
-%FilteredDataFftDb = FilteredDataFftDb(1:length(Fband));
-%ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
+FbandOrig = 0:1/PointsNum:1-1/PointsNum;
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 figure('name','In Data Time/Freq', 'Numbertitle', 'off')
@@ -69,63 +61,37 @@ 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')
-subplot(3,1,1)
-plot(InDataFftDb)
+subplot(2,1,1)
+plot(FreqBandOrig,InDataFftDb)
 grid on;
 grid minor;
 % axis([0 25 -70 80]);
-title('Single-Sided Amplitude Spectrum of Data before filter')
-xlabel('Time')
-ylabel('Amp')
+title('Single-Sided Amplitude Spectrum of Data before filter');
+xlabel('Time');
+ylabel('Amp');
 
-subplot(3,1,2)
-plot(ImpuseRespFftDb)
-grid on;
-grid minor;
-% axis([0 50 -60 1]);
-title('Cic Frequency response')
-xlabel('f (Hz)')
-ylabel('Amp')
-
-subplot(3,1,3)
-plot(Fband,FilteredDataFftDb)
+subplot(2,1,2)
+plot(FreqbandDecim,FilteredDataFftDb)
 grid on;
 grid minor;
 % axis([0 25 -70 80]);
-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)
-% grid on;
-% grid minor;
-% title('In Signal')
-% xlabel('Time')
-% ylabel('Amp')
-
-% subplot(2,1,2)
-% plot(Fband,ImpuseRespFftDb)
-% grid on;
-% grid minor;
-% title('Single-Sided Amplitude Spectrum of InData')
-% xlabel('f (Hz)')
-% ylabel('Amp')
+title('Single-Sided Amplitude Spectrum of Data after filter');
+xlabel('f (Hz)');
+ylabel('Amp');
 
 
 

+ 166 - 4
src/src/Sim/FilteredData.txt

@@ -1,5 +1,167 @@
           0
-          0
-       4334
-      27027
-       4327
+      77204
+    5236950
+   34058672
+   83522383
+  114219832
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527
+ -103540812
+ -108827140
+  -55132681
+   28423662
+   96555891
+  112337478
+   67208497
+  -14364061
+  -88170025
+ -114203159
+  -78338054
+     -25481
+   78282136
+  114142599
+   88110608
+   14304475
+  -67267692
+ -112398002
+  -96614055
+  -28475332
+   55079152
+  108767353
+  103480827
+   42082175
+  -42141527

+ 26 - 3
src/src/Sim/ImpResp.m

@@ -5,7 +5,7 @@ R = 2;
 B = 16;
 M = 1;
 
-PointsNum = 1000;
+PointsNum = 250;
 Fband = 0:1/PointsNum:1-1/PointsNum;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -13,14 +13,22 @@ 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);
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 ImpuseRespFft = abs(fft(ImpulseResp));
 ImpuseRespFftDb = 20*log10(ImpuseRespFft);
 ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ImpuseRespTestFft = abs(fft(ImpulseRespTest));
+ImpuseRespTestFftDb = 20*log10(ImpuseRespTestFft);
+ImpuseRespTestFftDb = ImpuseRespTestFftDb-max(ImpuseRespTestFftDb);
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+figure(1);
 subplot(2,1,1)
 plot(Fband,ImpulseResp)
 grid on;
@@ -30,14 +38,29 @@ xlabel('f (Hz)')
 ylabel('Amp')
 
 subplot(2,1,2)
-plot(Fband,ImpuseRespFftDb)
+plot(Fband,ImpuseRespFft)
 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')
 
 
 

+ 160 - 3
src/src/Sim/ImpResp.txt

@@ -1,6 +1,163 @@
-          1
-          3
-          3
+       8191
+    5799228
+   51496817
+   60097367
+    9927492
+      57337
+          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
+          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

+ 250 - 0
src/src/Sim/ImpRespTest.txt

@@ -0,0 +1,250 @@
+        0
+     3033
+   131292
+   292521
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396
+  -624702
+  -407589
+   -89684
+   253374
+   535595
+   683463
+   659113
+   471675
+   170559
+  -170891
+  -471987
+  -659450
+  -683804
+  -535911
+  -253659
+    89427
+   407285
+   624370
+   690055
+   586759
+   336460
+     -170
+  -336776
+  -587084
+  -690396

File diff suppressed because it is too large
+ 995 - 5
src/src/Sim/InputSignal.txt