0% found this document useful (0 votes)
45 views3 pages

All All: Clear Close CLC

This MATLAB script analyzes a CIC filter with compensation. It computes the frequency response of the CIC filter, designs a compensation filter, and plots the compensated frequency response. The script generates and plots the CIC filter response, compensation filter coefficients, and combined response to analyze the filter design and compensation.

Uploaded by

verma85_amit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

All All: Clear Close CLC

This MATLAB script analyzes a CIC filter with compensation. It computes the frequency response of the CIC filter, designs a compensation filter, and plots the compensated frequency response. The script generates and plots the CIC filter response, compensation filter coefficients, and combined response to analyze the filter design and compensation.

Uploaded by

verma85_amit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

%================================================================

==========
% CIC Filter Analysis Script
%
% Compute CIC filter frequency response, compensation filter
coefficients,
% and compensated frequency response for a given set of design
paramenters.
%
%
%
Author: Tom Chatt
%
%
Revision History:
%================================================================
==========
%
09/23/2010
Tom Chatt
Initial
Version
%================================================================
==========
clear all; close all; clc;
%=============================
% CIC Filter Design Parameters
%=============================
N = 3;
% Sinc/Comb-Filter order
M = 1;
% Stage delay (should be 1 or 2).
D = 64;
% Decimation factor
fs = 10e6;
% Pre-decimation sampling Frequency
fs_lo = fs / D;
% Post-decimation sampling frequency
%==============================
% Compensator Design Parameters
%==============================
B = 12; % Compensator coefficient bit width
% fir2 parameters
fc = fs/D/2;
% Ideal cutoff frequency
L = 16;
% Filter order - 1. Must be even. Final filter
length is L + 1.
Fo = D*fc/fs;
% Normalized cutoff frequency
%=====================================================
% Generate and plot filters
%

% Floating point compensator filter coef. stored in h


% Fixed point compensator filter coef. stored in hz
%
%======================================================
% CIC Compensator using fir2
p = 2e3;
%
s = 0.25 / p;
%
fpass = 0:s:Fo;
%
fstop = (Fo + s) : s : 0.5; %
ff = [fpass fstop] * 2;
%
f <= 1

Granularity
Step size
Pass band frequency samples
Stop band frequency samples
Normalized frequency samples, 0 <=

Mp = ones(1,length(fpass)); %% Pass band response; Mp(1)=1


Mp(2:end) =
abs( M*D*sin(pi*fpass(2:end)/D)./sin(pi*M*fpass(2:end))).^N;
Mf = [Mp zeros(1,length(fstop))];
ff(end) = 1;
h = fir2(L,ff,Mf); %% Filter length L+1
h = h/max(h); %% Floating point coefficients
hz = round(h*power(2,B-1)-1)/(2^(B-1)); %% Fixed point
coefficients
f = linspace(0,1,4*length(ff));
f_lo = [ff ff+1 ff+2 ff+3];
H = (D^-N*abs(D*M*sin(pi*M*D*f) ./ (pi*M*D*f)).^N);
HH = (D^-N*abs(D*M*sin(pi*M*ff) ./ (pi*M*ff)).^N);
HHH = (D^-N*abs(D*M*sin(pi*M*f_lo) ./ (pi*M*f_lo)).^N);
H_comp = abs(fft(hz,length(ff)));
%=========
% Plotting
%=========
figure('name','CIC Frequency Response','Numbertitle','off');
subplot(211);
plot(f*fs, db(H), 'b');
grid on;
title([{'Wideband frequency response of CIC filter'};{sprintf('D
= %i, N = %i',D,N)}]);
xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})| (dB)');
axis([0,fs,-1250,0]);
subplot(212);
plot(f_lo*fs_lo, db(HHH));
grid on;

title('Narrowband frequency response of CIC filter');


xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})| (dB)');
axis([0,4*fs_lo,-200,5]);
figure('name','CIC with Compensator Filter','Numbertitle','off');
subplot(211);
hold on;
grid on;
plot(f_lo*fs_lo, db(HHH), 'b');
plot(f_lo*fs_lo, db([H_comp H_comp H_comp H_comp]), 'g');
plot(f_lo*fs_lo, db(HHH .* [H_comp H_comp H_comp H_comp]), 'r');
axis([0,4*fs_lo,-200,25])
title([{'CIC with Compensator FIR'};{sprintf('Compensator length
= %i, Coefficient precision = %i',L,B)}]);
xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})| (dB)');
subplot(212);
hold on;
grid on;
plot(ff*fs_lo, HH, 'b');
plot(ff*fs_lo, H_comp, 'g');
plot(ff*fs_lo, HH .* H_comp, 'r');
axis([0,1*fs_lo,0,1.1]);
title('Closeup of CIC + compensator passband');
xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})|');
legend('CIC','Compensator Filter','Net
Response','location','northeast');

You might also like