|
|
@@ -0,0 +1,92 @@
|
|
|
+FormatSpec = '%d';
|
|
|
+PointsNum = 500;
|
|
|
+N = 4;
|
|
|
+R = 2;
|
|
|
+B = 14;
|
|
|
+M = 1;
|
|
|
+
|
|
|
+Bmax = ceil(log2(((R*M)^N)/R)+B);
|
|
|
+x = 1:1:PointsNum;
|
|
|
+xDecim = 1:1:PointsNum/R;
|
|
|
+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);
|
|
|
+
|
|
|
+ReadFilterCoefsId = fopen('C:\Users\Work_Pc\Downloads\Telegram Desktop\filterTest.txt','r');
|
|
|
+FilterCoefs = fscanf(ReadFilterCoefsId,FormatSpec);
|
|
|
+fclose(ReadFilterCoefsId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+InDataFft = fft(InDataSignal);
|
|
|
+InDataFft = InDataFft(1:PointsNum/2);
|
|
|
+
|
|
|
+FilteredDataPNum = PointsNum/R;
|
|
|
+
|
|
|
+FilteredDataFft = fft(FilteredData);
|
|
|
+CicResp = 20*log10(abs(FilteredDataFft(1:FilteredDataPNum/2)));
|
|
|
+CicResp = CicResp-max(CicResp)
|
|
|
+
|
|
|
+Freqs = (Fs*(1:(PointsNum/2))/PointsNum);
|
|
|
+FreqsDecim = Fs/R*(1:(FilteredDataPNum/2))/FilteredDataPNum;
|
|
|
+
|
|
|
+FirResponce = 20 * log10(abs(fft(FilterCoefs, FilteredDataPNum)));
|
|
|
+FirResponce = FirResponce(1:FilteredDataPNum/2);
|
|
|
+FirResponce = FirResponce-max(FirResponce)
|
|
|
+
|
|
|
+CicComp = CicResp + FirResponce;
|
|
|
+CicComp = CicComp - max(CicComp);
|
|
|
+
|
|
|
+HCIC = (R^-N*abs(1*M*sin(pi*M*R*FreqsDecim) ./ sin(pi*FreqsDecim)).^N);
|
|
|
+HCICdb = 20 * log10(abs(HCIC));
|
|
|
+
|
|
|
+figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
|
|
|
+ plot(FreqsDecim, FirResponce, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
+ hold on;
|
|
|
+
|
|
|
+ plot(FreqsDecim, CicComp, '--', 'LineWidth', 2, 'Color',[0.2 0.5 0]);
|
|
|
+ hold on;
|
|
|
+
|
|
|
+ plot(FreqsDecim, CicResp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
+ hold on;
|
|
|
+
|
|
|
+ title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i, Coef. width = %i',NFIR,Bc)}]);
|
|
|
+ xlabel ('Freq (\pi x rad / samples)');
|
|
|
+ ylabel ('Magnitude (dB)');
|
|
|
+ legend('Comp. FIR','Sum Response','CIC filter','location','northeast');
|
|
|
+ grid on;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|