|
|
@@ -1,11 +1,12 @@
|
|
|
FormatSpec = '%d';
|
|
|
PointsNum = 500;
|
|
|
-N = 4;
|
|
|
+N = 12;
|
|
|
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;
|
|
|
@@ -30,11 +31,14 @@ InDataFft = InDataFft(1:PointsNum/2);
|
|
|
FilteredDataPNum = PointsNum/R;
|
|
|
|
|
|
FilteredDataFft = fft(FilteredData);
|
|
|
-CicResp = 20*log10(abs(FilteredDataFft(1:FilteredDataPNum/2)));
|
|
|
+FilteredDataFft = FilteredDataFft(1:FilteredDataPNum/2);
|
|
|
+
|
|
|
+CicResp = 20*log10(abs(FilteredDataFft));
|
|
|
CicResp = CicResp-max(CicResp)
|
|
|
|
|
|
Freqs = (Fs*(1:(PointsNum/2))/PointsNum);
|
|
|
FreqsDecim = Fs/R*(1:(FilteredDataPNum/2))/FilteredDataPNum;
|
|
|
+NormFreqs = FreqsDecim/Fs;
|
|
|
|
|
|
FirResponce = 20 * log10(abs(fft(FilterCoefs, FilteredDataPNum)));
|
|
|
FirResponce = FirResponce(1:FilteredDataPNum/2);
|
|
|
@@ -56,19 +60,41 @@ figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
|
|
|
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)}]);
|
|
|
+ title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i',N)}]);
|
|
|
xlabel ('Freq (\pi x rad / samples)');
|
|
|
ylabel ('Magnitude (dB)');
|
|
|
legend('Comp. FIR','Sum Response','CIC filter','location','northeast');
|
|
|
grid on;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+NFFT = 2^14; % FFT points for Freq Response (spectrum)
|
|
|
+STEP = 1/NFFT; % Step size
|
|
|
+ff = 0:1/NFFT:1-1/NFFT;
|
|
|
+
|
|
|
+Hcic = abs((sin(pi*M*R*NormFreqs) ./ sin(pi*NormFreqs))).^N;
|
|
|
+Hcicdb = 20 * log10(abs(Hcic));
|
|
|
+Hcicdb = Hcicdb - max(Hcicdb);
|
|
|
+##figure('name','Cic Response', 'Numbertitle', 'off')
|
|
|
+##plot(FreqsDecim, CicResp - max(CicResp), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
+##
|
|
|
+##title([{'Cic Response'}]);
|
|
|
+##xlabel ('Freq (\pi x rad / samples)');
|
|
|
+##ylabel ('Magnitude');
|
|
|
+##axis tight;
|
|
|
+##grid on;
|
|
|
+##
|
|
|
+##figure('name','CicResp', 'Numbertitle', 'off')
|
|
|
+## plot(NormFreqs, CicResp, 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
+## hold on;
|
|
|
+##
|
|
|
+##figure('name','HCICdb Frequency Response', 'Numbertitle', 'off')
|
|
|
+## plot(NormFreqs, Hcicdb, 'LineWidth', 2, 'Color',[0.2 0.5 0]);
|
|
|
+## hold on;
|
|
|
+
|
|
|
+figure('name','Resulting Frequency Response', 'Numbertitle', 'off')
|
|
|
+plot(FreqsDecim,20*log10(abs(FilteredDataFft)), 'LineWidth',2)
|
|
|
+title("Single-Sided Amplitude Spectrum of cic+fir filter")
|
|
|
+xlabel("f (Hz)")
|
|
|
+ylabel("Amp")
|
|
|
|
|
|
|
|
|
|