0% found this document useful (0 votes)
127 views

Implementation of Fir Filter in c54x

1. The document describes an experiment to implement an FIR filter in C54x assembly language using PDSPs. 2. It involves generating FIR filter coefficients using window functions, storing the coefficients and input signals in memory, and performing convolution to filter the input. 3. MATLAB code is used to design the filter and CCS code shows the assembly implementation of the FIR filter convolution to filter a signal corrupted with noise.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Implementation of Fir Filter in c54x

1. The document describes an experiment to implement an FIR filter in C54x assembly language using PDSPs. 2. It involves generating FIR filter coefficients using window functions, storing the coefficients and input signals in memory, and performing convolution to filter the input. 3. MATLAB code is used to design the filter and CCS code shows the assembly implementation of the FIR filter convolution to filter a signal corrupted with noise.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No.

10
Date: 21/10/19

IMPLEMENTATION OF FIR FILTER IN `C54X

AIM:
To write assembly language program for implementing FIR filter in PDSPs.
OBJECTIVES:

1. To generate FIR filter coefficients for LPF using window functions.


2. Converting the coefficients into lookup table and storing in memory of PDSPs.
3. Storing input signal signal values in memory
4. To understand the response of digital filter
THEORY:
Filters are circuits which remove unwanted frequencies from the signal.
A finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length
input) is of finite duration, because it settles to zero in finite time.
Properties of FIR Filter
 Requires no feedback
 Stable
 Linear Phase
An FIR causal function can be represented by transfer function
𝑁−1

𝐻(𝑧) = ∑ ℎ(𝑛)𝑧−𝑛
𝑛=0

h(n) is the impulse response of the filter.


The output of the filter y [n] = x[n] * h[n]

FIR Filter design can be done using


 Window design method
 Frequency sampling method
 Weighted least square method
Types of windows used for filter design:
1. Hanning Window
𝑤𝐻𝑛(𝑛) = 0.5 + 0.5 cos ( 2𝜋𝑛 ) ; −𝑁− 1 ≤ 𝑛≤ 𝑁− 1
𝑁−1 2 2
= 0 ; 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
2. Hamming Window
𝑤𝐻𝑚(𝑛) = 0.54 + 0.46 cos ( 2𝜋𝑛 ) ; −𝑁 − 1 ≤ 𝑛≤ 𝑁 − 1
𝑁−1 2 2
= 0 ; 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
3. Blackmann Window
𝑤𝑏(𝑛) = 0.42 + 0.5 cos ( 2𝜋𝑛 ) + 0.08 cos ( 2𝜋𝑛 ) ; −𝑁 − 1 ≤ 𝑛≤ 𝑁 − 1
𝑁−1 𝑁−1 2 2
= 0 ; 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
4. Rectangular Window
𝑁−1 𝑁−1
𝑤𝑘(𝑛) = 1 ;− ≤𝑛≤
2 2
=0 ;
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
5. Bartlett Window 𝑁−1 𝑁−1
2|𝑛| ≤𝑛≤
;− 2 2
𝑤𝑡(𝑛) = 1 −
𝑁 −1
=0 ; 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
PROCEDURE:
 Calculate the filter coefficients using any one window function in MATLAB.
 Convert the filter coefficients into hexadecimal by scaling with suitable weighting factors.
 Store the coefficients either data or program memory of the processor.
 Get the input sample values, store it either data or program memory of the processor
 Perform the convolution to the input samples and filter coefficients, store the result in data
memory.
 The output to be displayed both in time and frequency domain.
PROGRAM CODE:
MATLAB CODE
%% Definition of signaLS
fs=5000;
t=0:1/fs:20/fs;
f1=400; f2=200; fn=800;
x1=5*sin(2*pi*f1*t) + 4*sin(2*pi*f2*t);
n=5*sin(2*pi*fn*t);
s=x1+n
subplot(2,1,1);
plot(t,x1);
title('Input Signal');
xlabel('value of n');
ylabel('Amplitude');
subplot(2,1,2);
plot(t,s);
title('distorted Signal');
xlabel('value of n');
ylabel('Amplitude');
%% definition of window functions
N=15; fc=500;
nw=(-(N-1)/2:1:(N-1)/2);
hlp=[];
for i=1:N
if i==(N-1)/2
hlp(i)=2*fc/fs;
else
hlp(i)=sin(2*pi*fc*(i-(N-1)/2)/fs)/(pi*(i-(N-1)/2));
end
end
whn=0.5 + 0.5*(cos(2*pi*nw/(N-1)));
N=15;
hhan=whn.*hlp;
hhan=hhan.*1024
yhan=conv(s,hhan);
figure;
plot(yhan);
fftSignalWHN = fft(yhan);
fftSignalWHN = fftshift(fftSignalWHN);
f = fs/2*linspace(-1,1,length(fftSignalWHN));
figure;
plot(f, abs(fftSignalWHN)); xlim([-1000 1000]);
title('MAGNITUDE FFT of HANNING FILTER O/P');
xlabel('Frequency (Hz)');
ylabel('magnitude');
fftSignalWHN = fft(x1);
fftSignalWHN = fftshift(fftSignalWHN);
f = fs/2*linspace(-1,1,length(fftSignalWHN));
figure;
plot(f, abs(fftSignalWHN)); xlim([-1000 1000]);
title('MAGNITUDE FFT of Desired Signal);
xlabel('Frequency (Hz)');
ylabel('magnitude');

CCS Code
.mmregs
.text
stm x+13,ar4
stm k,ar2
stm #5000h,ar3
stm k,ar5
ld #0h,a
ld #0h,b
stm #21,ar7
stm #14,ar6
stm #33,ar2
loop2:
rpt #13
macp *ar4-,k,a
stl a,*ar3+
ld #0h,a
mar *+ar4(15)
banz loop2,*ar2-

x .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,7,8,7,6,4,3,1,-1,-3,-3,-1,1,2,3,1,-1,-3,-
4,6,0,0,0,0,0,0,0,0,0,0,0,0
k .word 0,9,40,95,155,195,192,147,84,29,0,-6,-2,0 ( scaled by 1024)
nop
.end
INFERENCES:
1. A signal of desired choice x[n] is selected
𝑥[𝑛] = 𝑎1𝑠𝑖𝑛2𝜋𝑓1𝑡 + 𝑎2𝑠𝑖𝑛2𝜋𝑓2𝑡
𝑓𝑠 = 5000 𝐻𝑧
𝑎1 = 5 𝑎2 = 4 𝑓1 = 400 𝐻𝑧 𝑓2 = 200 𝐻𝑧
2. A noise signal was defined as
𝑁[𝑛] = 5𝑠𝑖𝑛2𝜋𝑓3𝑡
𝑓3 = 800 𝐻𝑧
3. Noise was added to x[n]
S=x+N
The time domain signal, magnitude & phase spectrum were plotted for the desired and the
corrupted signal.
Distorted Signal(CCS)
Filter Output(CCS)

Magnitude FFT of Distorted Signal(CCS)

Magnitude FFT of Filter Output (CCS)

Hanning window was designed with 15 taps.


Convolution was performed between corrupted signal and FIR filter transfer function.
The time domain plot and magnitude spectrum were plotted for filter output.
Original Corrupted Signal: Peaks at 200 Hz, 400 Hz, 800 Hz
Filtered Output: Peaks at 200 Hz, 400 Hz

You might also like