You are on page 1of 17

PROGRAMMABLE AND EMBEDDED SYSTEMS ASSIGNMENT PART 2

FIR FIXED POINT FILTER DESIGN

SOHINI ROY , 18IE33007

warning('off','all')

GENERATION OF A NOISY SIGNAL FROM A RECORDED VOICE SIGNAL

[V,Fs] = audioread('D:\LABS\PES\Comb_Filter_Design\Voice.m4a');
%sound(V,Fs);
[N,Fs] = audioread('D:\LABS\PES\Comb_Filter_Design\Noise6.m4a');
%sound(N,Fs);
Fs = 10000;
audiowrite('Voice_write.wav',V,Fs)
audiowrite('Noise_write.wav',N,Fs)

[V,Fs] = audioread('D:\LABS\PES\Comb_Filter_Design\Voice_write.wav');
[N,Fs] = audioread('D:\LABS\PES\Comb_Filter_Design\Noise_write.wav');

x = randn(10000,1); %% Random Gaussian Distributed Noise Signal Generation


h = ones(20,1)/20;
y= filter(h,1,x);

f = 50;
Ts=1e-04;
w = 0.01*sin(2*pi*f*Ts*[0:(length(y)-1)]'); %Pure Sinusoidal signal
yn=y+w;

V1 = 10*V(50000:54000);
N1 = N(50000:54000)+yn(1000:5000);
X = V1+N1;
plot(X)
title ("Noisy Signal")

1
GENERATING THE FILTER COEFFICIENTS

%%filterDesigner (Generates LPF coefficients with fc=1KHz and Fs = 10KHz)


% 31 ORDER LOW PASS FILTER
h1=load('Low_Pass_Filter.mat')

h1 = struct with fields:


Hlp: [-0.0057 0.0061 0.0173 0.0233 0.0206 0.0087 -0.0096 -0.0283 -0.0398 -0.0373 -0.0169 0.0207 0.0698 0.1209 0.

h2 = struct2cell( h1 );
h = cell2mat( h2 );

% For a Word Length of 32


W = 8

W = 8

%Determing the length of the fraction


hmax = max(abs(h))

hmax = 0.1871

b = log((2^(W-1)-1)/hmax)

2
b = 6.5204

%Getting the fraction length


b = 6

b = 6

%Getting the Fixed point Coefficients


ht = h/(2^b)

ht = 1×32
-0.0001 0.0001 0.0003 0.0004 0.0003 0.0001 -0.0002 -0.0004

%Getting the Filtered Waveform in Fixed Point Form


hf = sfi(h,W,b);
Xf = sfi(X,W,b);
yfixed = conv(Xf,hf);
yfloat = conv(X,h);

eh = 100*(h-double(hf))./h;
ex = 100*(X-double(Xf))./X;
ey = 100*(yfloat-double(yfixed))./yfloat;

bar(eh)
title("Error in Filter Coefficients values")

3
bar(ex)
title("Error in Filter Input values")

bar(ey)
title("Error in Filter Output values")

4
plot(yfloat) % Filtered signal using the floating point representation
title ("Filtered Signal in Floating Point")

5
plot(yfixed) % Filtered signal using the fixed point representation
title ("Filtered Signal in Fixed Point")

6
Here we shall see the results of filtering with fixed point coefficients and the comparison of plots for different
word lengths and the corresponsing fraction length hence obtained.

% For a Word Length of 8


W = 16

W = 16

%Determing the length of the fraction


hmax = max(abs(h))

hmax = 0.1871

b = log((2^(W-1)-1)/hmax)

b = 12.0734

%Getting the fraction length


b = 12

b = 12

%Getting the Fixed point Coefficients


ht = h/(2^b)

ht = 1×32
10-4 ×
-0.0139 0.0149 0.0423 0.0568 0.0503 0.0211 -0.0235 -0.0691

%Getting the Filtered Waveform in Fixed Point Form


hf = sfi(h,W,b);
Xf = sfi(X,W,b);
yfixed = conv(Xf,hf);
yfloat = conv(X,h);

eh = 100*(h-double(hf))./h;
ex = 100*(X-double(Xf))./X;
ey = 100*(yfloat-double(yfixed))./yfloat;

bar(eh)
title("Error in Filter Coefficients values")

7
bar(ex)
title("Error in Filter Input values")

8
bar(ey)
title("Error in Filter Output values")

9
plot(yfloat) % Filtered signal using the floating point representation
title ("Filtered Signal in Floating Point")

10
plot(yfixed) % Filtered signal using the fixed point representation
title ("Filtered Signal in Fixed Point")

11
% For a Word Length of 32
W = 32

W = 32

%Determing the length of the fraction


hmax = max(abs(h))

hmax = 0.1871

b = log((2^(W-1)-1)/hmax)

b = 23.1638

%Getting the fraction length


b = 23

b = 23

%Getting the Fixed point Coefficients


ht = h/(2^b)

ht = 1×32
10-7 ×
-0.0068 0.0073 0.0206 0.0277 0.0245 0.0103 -0.0115 -0.0337

%Getting the Filtered Waveform in Fixed Point Form


hf = sfi(h,W,b);
Xf = sfi(X,W,b);
yfixed = conv(Xf,hf);
yfloat = conv(X,h);

eh = 100*(h-double(hf))./h;
ex = 100*(X-double(Xf))./X;
ey = 100*(yfloat-double(yfixed))./yfloat;

bar(eh)
title("Error in Filter Coefficients values")

12
bar(ex)
title("Error in Filter Input values")

13
bar(ey)
title("Error in Filter Output values")

14
plot(yfloat) % Filtered signal using the floating point representation
title ("Filtered Signal in Floating Point")

15
plot(yfixed) % Filtered signal using the fixed point representation
title ("Filtered Signal in Fixed Point")

16
The error converges to a very small value for Word length 32 , Thus as the word length increases error reduces
and filtered signal becomes more accurate.

17

You might also like