Sie sind auf Seite 1von 159

Blekinge Institute of Technology

Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 1


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Group Members

Adnan Saleem
E-mail:electropall@hotmail.com
Student Personal No: 810524-P510

Syed Majid Ali Shah


E-mail:syedmaji@hotmail.com
Student Personal No: 800321-1714

Syed Hassan Shaheed


E-mail:hassey22@yahoo.com
Student Personal No: 800410-P732

Arif Ullah Khan


E-mail:arifullahkhan1@hotmail.com
Student Personal No: 800323-P837

Telecoder Group, Applied Signal Processing Assignment 2


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Table of Contents
Assignment 1 --------------------------------------------------------------------------------------------------------- 5
Assignment 1.1------------------------------------------------------------------------------------------------------- 6
Assignment 1.2------------------------------------------------------------------------------------------------------- 9
Assignment 1.3------------------------------------------------------------------------------------------------------13
Assignment 1.4------------------------------------------------------------------------------------------------------17
Assignment 1.5------------------------------------------------------------------------------------------------------18
Assignment 1.6------------------------------------------------------------------------------------------------------21
Assignment 1.7------------------------------------------------------------------------------------------------------23
Assignment 1.8------------------------------------------------------------------------------------------------------26
Assignment 1.9------------------------------------------------------------------------------------------------------28
Assignment 1.10 ----------------------------------------------------------------------------------------------------30
Assignment 1.11 ----------------------------------------------------------------------------------------------------32
Assignment 1.12 ----------------------------------------------------------------------------------------------------34
Assignment 1.13 ----------------------------------------------------------------------------------------------------36
Assignment 1.14 ----------------------------------------------------------------------------------------------------37
Assignment 1.15 ----------------------------------------------------------------------------------------------------40
Assignment 1.16 ----------------------------------------------------------------------------------------------------43
Assignment 1.17 ----------------------------------------------------------------------------------------------------44
Assignment 1.18 ----------------------------------------------------------------------------------------------------46
Assignment 1.19 ----------------------------------------------------------------------------------------------------48
Assignment 2 --------------------------------------------------------------------------------------------------------49
Assignment 2.1------------------------------------------------------------------------------------------------------50
Assignment 2.2------------------------------------------------------------------------------------------------------52
Assignment 2.3------------------------------------------------------------------------------------------------------54
Assignment 2.4------------------------------------------------------------------------------------------------------56
Assignment 2.5------------------------------------------------------------------------------------------------------60
Assignment 2.6------------------------------------------------------------------------------------------------------62
Assignment 2.7------------------------------------------------------------------------------------------------------64
Assignment 2.8------------------------------------------------------------------------------------------------------68
Assignment 2.9------------------------------------------------------------------------------------------------------70
Assignment 2.10 ----------------------------------------------------------------------------------------------------72
Assignment 2.11 ----------------------------------------------------------------------------------------------------74
Assignment 2.12 ----------------------------------------------------------------------------------------------------75
Assignment 3 --------------------------------------------------------------------------------------------------------76
Assignment 3.1------------------------------------------------------------------------------------------------------77
Assignment 3.2------------------------------------------------------------------------------------------------------78
Assignment 3.3------------------------------------------------------------------------------------------------------80
Assignment 3.4------------------------------------------------------------------------------------------------------83
Assignment 3.5------------------------------------------------------------------------------------------------------85
Assignment 3.6------------------------------------------------------------------------------------------------------86
Assignment 3.7------------------------------------------------------------------------------------------------------92
Assignment 4 --------------------------------------------------------------------------------------------------------94
Assignment 4.1------------------------------------------------------------------------------------------------------95

Telecoder Group, Applied Signal Processing Assignment 3


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.2------------------------------------------------------------------------------------------------------97
Assignment 4.3------------------------------------------------------------------------------------------------------99
Assignment 4.4---------------------------------------------------------------------------------------------------- 102
Assignment 4.5---------------------------------------------------------------------------------------------------- 104
Assignment 4.6---------------------------------------------------------------------------------------------------- 108
Assignment 5 ------------------------------------------------------------------------------------------------------ 112
Assignment 5.1---------------------------------------------------------------------------------------------------- 113
Assignment 5.2---------------------------------------------------------------------------------------------------- 115
Assignment for Grade 4------------------------------------------------------------------------------------------ 117
Assignment Grade 4.1-------------------------------------------------------------------------------------------- 118
Assignment Grade 4.2-------------------------------------------------------------------------------------------- 127
Assignment Grade 4.3-------------------------------------------------------------------------------------------- 130
Assignment Grade 4.4-------------------------------------------------------------------------------------------- 134
Assignment Grade 4.5-------------------------------------------------------------------------------------------- 141
Assignment Grade 4.6-------------------------------------------------------------------------------------------- 144
Assignment Grade 4.7-------------------------------------------------------------------------------------------- 147
Assignment Grade 4.8-------------------------------------------------------------------------------------------- 151
Assignment Grade 4.9-------------------------------------------------------------------------------------------- 154
Assignment Grade 4.10 ------------------------------------------------------------------------------------------ 157

Telecoder Group, Applied Signal Processing Assignment 4


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1

Telecoder Group, Applied Signal Processing Assignment 5


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.1
Matlab Code

clear all; close all; clc;

t=0:99;

delta=zeros(1,100);

delta(1,1)=1;

plot(t,delta,'*b')

title('Unit Impulse function');

figure(2)

UnitS=ones(1,100);

plot(t,UnitS,'*r')

title('Unit Step function');

figure(3)

stem(t,delta)

title('Unit Impulse Function')

figure(4)

stem(t,UnitS)

title('Unit Step function');

Telecoder Group, Applied Signal Processing Assignment 6


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 7


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 8


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.2
Matlab Code

clear all; close all; clc;

n=0:99;

a=input('Enter value of a ')

UnitS=ones(1,100);

func= a.^n.*UnitS;

S_matlab=sum(func)

Geom_sum= (1 - a^100) /( 1 - a )

plot(n,func)

title('Exponentially Decaying function')

Results

Time vector = 0:99

a=0.5

Sum by Matlab= 2
Geometric sum = 2

a=0.9

Sum by Matlab= 9.9997


Geometric sum =9.9997

a=1

Sum by Matlab= 100


Geometric sum = 100

a=1.1

Sum by Matlab= 1.3780e+005


Geometric sum = 1.3780e+005

Telecoder Group, Applied Signal Processing Assignment 9


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

a=2

Sum by Matlab= 1.2677e+030


Geometric sum = 1.2677e+030

Figures

Telecoder Group, Applied Signal Processing Assignment 10


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 11


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 12


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.3
Matlab Code

clear all; close all; clc;

fs=2;

n=0:1/fs:(8192-1)/fs;

f=[0 1/16 1/8 1/4 0.5 1/sqrt(5)];

for k=1:6

x(:,k)=cos(2*pi*f(k)*n);

figure(k)

plot(n,x(:,k))

end

sound(x(:,1))

pause

sound(x(:,2))

pause

sound(x(:,3))

pause

sound(x(:,4))

pause

sound(x(:,5))

pause

sound(x(:,6))

Figures

Telecoder Group, Applied Signal Processing Assignment 13


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 14


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 15


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 16


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.4
Matlab Code

clear all; close all; clc;

fs=2;

n=0:1/fs:(8192-1)/fs;

f1= 1/8 - 1/8192;

f2= 1/8 + 1/8192;

x1=cos(2*pi*f1*n);

x2=cos(2*pi*f2*n);

x=x1 + x2;

sound(x)

pause

sound(x1)

pause

f1 = 0.5 - 1/8192;

x1= cos(2*pi*f1*n);

sound(x1)

Results

Summation of two signals gives beat only first signal with one frequency doesn’t have any beat.

Telecoder Group, Applied Signal Processing Assignment 17


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.5
Matlab Code

clear all; close all; clc;

fs=512;

n=0:1/fs:(8192-1)/fs;

f= [1/8 7/8 9/8];

for k=1:3

x(:,k)=cos(2*pi*f(k)*n);

figure(k)

if k==1

plot(n,x(:,k),'b')

gtext('Signal frequency is 1/8 Hz','fontsize',12)

title(' Cosine Signal ','fontsize',14)

end

if k==2

plot(n,x(:,k),'r')

gtext('Signal frequency is 7/8 Hz','fontsize',12)

title(' Cosine Signal ','fontsize',14)

end

if k==3

plot(n,x(:,k),'g')

gtext('Signal frequency is 9/8 Hz','fontsize',12)

title(' Cosine Signal ','fontsize',14)

end

Telecoder Group, Applied Signal Processing Assignment 18


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

end

Figures

Telecoder Group, Applied Signal Processing Assignment 19


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 20


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.6
Matlab Code

clear all; close all; clc;

fs=512;

n=0:1/fs:(8192-1)/fs;

a=3;

f0=5;

x = exp(log(a)*n + sqrt(-1)*2*pi*f0*n);

plot(n,x);

hold on;

plot(n,abs(x),'r');

plot(n,real(x),'g');

plot(n,imag(x),'m')

legend( 'pure signal','absolute of signal','real part of signal','imaginary part of signal',2)

title(' Exponential Signal ', 'fontsize',14)

sound(x);

pause

sound(abs(x));

pause

sound(real(x))

pause

sound(imag(x))

Figures

Telecoder Group, Applied Signal Processing Assignment 21


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 22


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.7
Matlab Code

clear all; close all; clc;

fs=1024;

t1=0:1/fs:(16384*5-1)/fs;

y=chirp(t1,0,1,100); % chirp signal

figure(1)

plot(y,'r');

title('Chirp signal','fontsize',14)

fs=2;

t=0:1/fs:(8192-1)/fs;

x1=cos(2*pi*(0.5-(1/(8192)))*t);

x2=cos(2*pi*((1/2)+(1/(8192)))*t);

x3 = x2 + x1;

sound(x3)

figure(2)

plot(t,x3,'b')

title('Beating effect, Signal with sum of adjacent frequencies')

gtext('f0 is 0.5, f1 is 1/8192')

delay = 2;

[y,ty] = rcosflt(y,1,2,'fir',.3,delay);

sound(y)

figure(4)

plot(ty,y)

Telecoder Group, Applied Signal Processing Assignment 23


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title(' Vibration effect by using Delay in chirp signal')

Figures

Telecoder Group, Applied Signal Processing Assignment 24


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 25


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.8
Matlab Code

clear all; close all; clc;

fs=8;

n=0:1/fs:(8192*8-1)/fs;

f1=20;

f2=10;

y=cos(2*pi*f1*n);

x=cos(2*pi*f2*n);

xy=[x y x y x y x y];

n=[n n n n n n n n]

sound(xy)

plot(n,xy)

title('Alteration of two frequencies','fontsize',14)

gtext('f1 = 20; f2 = 10')

Telecoder Group, Applied Signal Processing Assignment 26


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 27


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.9
Matlab Code

clear all; close all; clc;

n=linspace(0,8191,8192);

x=1+cos(2*pi*0.0625*n);

figure(1)

plot(n(1:200),x(1:200),'b')

title('Signal, 1+cos(2*pi*0.0625*n)','fontsize',14)

y(:,1)=x(1);

for k=2:500

y(:,k)=x(k)-x(k-1);

end

figure(2)

plot(n(1:length(y)),y,'r')

title('Impulse Response','fontsize',14)

Telecoder Group, Applied Signal Processing Assignment 28


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 29


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.10
Matlab Code

clear all; close all; clc;

n = 0:1:255;

x = 1 + cos(2*pi*0.0625*n);

yy=zeros(256,256);

YY=[];

for k=1:256

yy(1:k,k)=(x(1,1:k));

YY=sum(yy);

End

plot(n,YY)

title('Filter calculating Cumulative sum','fontsize',14)

gtext(' 1 + cos(2*pi*0.0625*n)')

Telecoder Group, Applied Signal Processing Assignment 30


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 31


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.11
Matlab Code

clear all; clc; close all

n=1:100;

nn=length(n);

x=zeros(1,nn);

x(1,1)=1;

y(1,1)=x(1,1);

y(1,2)=x(1,1)+x(1,2);

y(1,3)=x(1,1)+x(1,2)+x(1,3);

y(1,4)=x(1,1)+x(1,2)+x(1,3)+x(1,4);

for m=5:100,

y(1,m)=x(1,(m-4))+x(1,(m-3))+x(1,(m-2))+x(1,(m-1))+x(1,m);

end

stem(y,'r');

title('Impulse response','fontsize',14)

Telecoder Group, Applied Signal Processing Assignment 32


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 33


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.12
Matlab Code

clear all; close all; clc;

n=linspace(-20,8171,8192);

f0=0.025;

x=1 + cos(2*pi*f0*n);

p=1;

y=zeros(1,8192);

yy=zeros(1,8192);

for t=-20:1:79

if t==-20

y(1,p)=10;

end

if t==-10

yy(1,p)=10;

end

p=p+1;

end

X=y-yy+x;

for m=-17:8171

k=m+21;

yy=[X(1,k) X(1,k-1) X(1,k-2) X(1,k-3)];

Y(1,k-3)=median(yy);

End

Telecoder Group, Applied Signal Processing Assignment 34


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

figure(1)

plot(n(1:length(Y)),Y)

title('GLIDING MEAN OF 10?(n ? 10) ? 10?(n ? 20) + x(n) = 1+cos(2*pi*f0*n)' );

Figures

Telecoder Group, Applied Signal Processing Assignment 35


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.13
Matlab Code

clear all; close all; clc;

x=[1 2 3 4 5];

y=[1 3 2];

Conv_xy= conv(x,y)

Cross_corr=xcorr(x,y)

Results

Conv_xy = 1 5 11 17 23 23 10

Cross_corr = 0.0000 0 2.0000 7.0000 13.0000 19.0000 25.0000 19.0000 5.0000

Telecoder Group, Applied Signal Processing Assignment 36


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.14
Matlab Code

clear all; close all; clc;

load assign1_9

conv1_9=conv(x,y);

figure(1)

stem(conv1_9(1:50))

title('Impulse response of assignment 1.9 using CONV ')

load assign1_10

conv1_10=conv(x,y);

figure(2)

stem(conv1_10(1:50))

title('Impulse response of assignment 1.10 using CONV ')

load assign1_11

conv1_11=conv(x,y);

figure(3)

stem(conv1_11(1:50))

title('Impulse response of assignment 1.11 using CONV ')

Telecoder Group, Applied Signal Processing Assignment 37


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 38


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 39


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.15
Matlab Code

close all; clear all; clc;

load assign1_9

filt1_9=filter(x,1,y);

figure(1)

stem(filt1_9(1:50))

title('Impulse response of assignment 1.9 using FILT ')

load assign1_10

filt1_10=filter(x,1,y);

figure(2)

stem(filt1_10(1:50))

title('Impulse response of assignment 1.10 using FILT ')

load assign1_11

filt1_11=filter(x,1,y);

figure(3)

stem(filt1_11(1:50))

title('Impulse response of assignment 1.11 using FILT ')

Telecoder Group, Applied Signal Processing Assignment 40


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 41


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 42


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.16
Matlab Code

clear all; close all; clc;

load handel;

yy=y;

N=25;

n=zeros(1,N);

p1=n;

p1(1,1)=1;

load assign1_9 %% loading assignment 1.9 data

conv1_9=conv(x,y);

p2=[1];

y1=filter(conv1_9,p2,yy);

sound(y1)

pause; %% Press any key to listen sound of using filter in assignment 11

load assign1_11 %% loading assignment 1.11 data

conv1_11=conv(x,y);

y2=filter(conv1_11,p2,yy);

sound(y2)

Telecoder Group, Applied Signal Processing Assignment 43


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.17
Matlab Code

clear all; close all; clc;

n=1:1:50;

y=((0.5).^n).*cos(pi*n/6);

x=ones(1,50);

[r h]=deconv(y,x);

h=h+r;

plot(h);

hold on

stem(y,'r')

title('IMPULSE RESPONSE AND STEP RESPONSE');

legend('Impluse response','Step response')

Telecoder Group, Applied Signal Processing Assignment 44


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 45


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.18
Matlab Code

clear all; close all; clc;

n=1:1:50;

h=((0.5).^n).*cos(pi*n/6);

x=ones(1,50);

y =conv(h,x);

plot(h);

hold on

stem(y(1:length(h)),'r')

title('IMPULSE RESPONSE AND STEP RESPONSE');

legend('Impulse response','Step response')

[h r]= deconv(y,x);

figure

plot(h)

title('Regained Impulse response from deconvultion')

Telecoder Group, Applied Signal Processing Assignment 46


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 47


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 1.19
Matlab Code

clear all; close all; clc;

t=0:1/8:(16384*2-1)/8;

f=13;

for k=6:15

p=k-5;

y(:,p)=sin(2*pi*k*f*t);

end

yy=sum(y(:,1:10)'); %% summation of all the harmonics

sound(yy)

yyy=yy';

Y=yyy-y(:,1); %% Removal of 1st harmonic

sound(Y)

Telecoder Group, Applied Signal Processing Assignment 48


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2

Telecoder Group, Applied Signal Processing Assignment 49


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.1
Matlab Code

clear all; close all; clc;

b=[1 -0.5 0];

a=[1 -1 0.5];

Poles=roots(a)

Zeros=roots(b)

n=100; %% no. of samples to be used in impulse response

[h,t] = impz(b,a,n);

plot(t,h)

xlabel('Time')

title('Impulse Response','fontsize',14)

hold on

n=0:99;

H= (1/sqrt(2)).^n .* cos(pi*n./4);

stem(t,H,'or')

legend('Impz function','Theoretical Calculation')

Telecoder Group, Applied Signal Processing Assignment 50


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 51


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.2
Matlab Code

clear all; close all; clc;

b=[1 0 0 0];

a=[1 -1 -1 1];

Poles=roots(a)

Zeros=roots(b)

figure(1)

grid on

plot(Poles,'*r');

hold on

grid on

plot(Zeros,'ob');

legend('Poles','Zeros')

n=200; %% no. of samples to be used in impulse response

[h,t] = impz(b,a,n);

figure(2)

stem(t,h,'ob')

xlabel('Time')

title('Impulse Response','fontsize',14)

hold on

n=1:200;

[r p k]=residue(b,a)

H=r(1)*(-1).^n + r(2) + r(3)*n - k;

Telecoder Group, Applied Signal Processing Assignment 52


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

plot(t,H,'*r')

legend('Impz function','Theoritical calculations',2)

Figures

Telecoder Group, Applied Signal Processing Assignment 53


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.3
Matlab Code

clear all; close all; clc;

b=[1 zeros(1,14) -1];

a=[1 -1 zeros(1,14)];

Poles=roots(a)

Zeros=roots(b)

figure(1)

grid on

plot(Poles,'*r');

hold on

grid on

plot(Zeros,'ob');

legend('Poles','Zeros')

n=100; %% no. of samples to be used in impulse response

[h,t] = impz(b,a,n);

figure(2)

stem(t,h,'b')

xlabel('Time')

title('Impulse Response','fontsize',14)

hold on

u=[ones(1,100)];

U=[zeros(1,15) ones(1,length(u)-15)];

uu=u-U;

Telecoder Group, Applied Signal Processing Assignment 54


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

plot(t,uu,'*r')

legend('Impz function','Easy Realization of same system',1)

Figures

Telecoder Group, Applied Signal Processing Assignment 55


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.4
Matlab Code

clear all; close all; clc;

load ecg

figure(1)

plot(ecg)

title('ECG Signal','fontsize',14)

b=[0.2 0];

a=[1 -0.8];

Y=filter(b,a,ecg);

Yf=filter(b,a,Y);

figure(2)

plot(Yf,'b')

hold on

Yff=flipud(ecg);

hold on

plot(Yff,'r')

Yfff=filtfilt(b,a,ecg);

plot(Yfff,'g')

legend('Twice filtered signal','Filtered Signal using flipud','Filtered signal using filtfilt')

title('Filtered Signal using different Functions','fontsize',14)

[h,t] = impz(b,a,length(ecg));

figure(3)

plot(t,h)

Telecoder Group, Applied Signal Processing Assignment 56


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title('Impulse Response','fontsize',14)

y = conv(ecg,h);

figure(4)

plot(y,'b')

hold on

yf=conv(Yf,h);

hold on

plot(yf,'r')

hold on

yff=conv(Yff,h);

plot(yff,'g')

hold on

yfff=conv(Yfff,h);

plot(yfff,'k')

title('Output Signal Filtered by different Matlab functions','fontsize',14)

legend('Twice using filter','flipud','filtfilt')

axis([0 4500 -225 800])

Telecoder Group, Applied Signal Processing Assignment 57


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 58


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 59


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.5
Matlab Code

clear all; close all; clc;

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8]; %% Denominator coefficient

[Hr,w] = zerophase(b,a);

HR=abs(Hr.*Hr);

plot((HR))

title('Amplitude function of H(z)')

figure(2)

phi = angle(Hr);

plot(phi)

title('Phase function of H(z)')

Telecoder Group, Applied Signal Processing Assignment 60


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 61


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.6
Matlab Code

clear all; close all; clc;

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8];

[h,t]=impz(b,a);

[H,W]=freqz(h);

figure(1)

semilogy(W,abs(H),'b')

hold on

H_th=(0.2)./((sqrt(1 + 0.8^2 - 2*0.8*cos(W))));

semilogy(W,abs(H_th),'--r')

legend('freqz function','Hand calculation')

title('Frequency Function Comparison')

figure(2)

y = angle(H);

plot(y)

title('Phase function')

Telecoder Group, Applied Signal Processing Assignment 62


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 63


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.7
Matlab Code

clear all; close all; clc;

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8];

%% using 4 points

[H,W]=impz(b,a,4);

figure(1)

stem(W,abs(H))

title('Impulse response using 4 points')

%% using 8 points

[H,W]=impz(b,a,8);

figure(2)

stem(W,abs(H))

title('Impulse response using 8 points')

%% using 16 points

[H,W]=impz(b,a,16);

figure(3)

stem(W,abs(H))

title('Impulse response using 16 points')

%% using 32 points

[H,W]=impz(b,a,32);

figure(4)

stem(W,abs(H))

Telecoder Group, Applied Signal Processing Assignment 64


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title('Impulse response using 32 points')

%% Untruncated filter

[H,W]=impz(b,a);

figure(5)

stem(W,abs(H))

title('Impulse response using untruncated filter')

Figures

Telecoder Group, Applied Signal Processing Assignment 65


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 66


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 67


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.8
Matlab Code

clear all; close all; clc;

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8];

[h,t]=impz(b,a);

h=h';

k=1:44;

n=0:43;

for k=0:43

E = h(1:44).*exp(i*2*pi*k*n/44);

EE = sum(E);

H(:,k+1) = EE;
end

plot(abs(H),'*b')

hold on

HH = fft(h);

HHH = abs(HH);

plot(HHH,'g')

title(' Discrete fourier transform ')

legend(' Matrix multiplication ',' Using FFT function')

Telecoder Group, Applied Signal Processing Assignment 68


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 69


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.9
Matlab Code

clear all; close all; clc;

format long

tic

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8];

[h,W]=impz(b,a,4);

H = fft(h,512);

plot(abs(H),'k');

hold on

[h,W]=impz(b,a,8);

H = fft(h,512);

plot(abs(H),'g');

hold on

[h,W]=impz(b,a,16);

H = fft(h,512);

plot(abs(H),'r');

hold on

[h,W]=impz(b,a,32);

H = fft(h,512);

plot(abs(H),'b');

toc

title('Fourier Transform of Impulse')

Telecoder Group, Applied Signal Processing Assignment 70


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

legend('4 points','8 points','16 points','32 points',4)

Figures

Telecoder Group, Applied Signal Processing Assignment 71


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.10
According to the email reply, flops function is obsolete in Matlab now. So it is not included in
the code.

Matlab Code

clear all; close all; clc;

format long

tic

b = [0.2 0]; %% Numerator coefficient

a = [1 -0.8];

[h,W]=impz(b,a,3);

H = fft(h,512);

plot(abs(H),'k');

hold on

[h,W]=impz(b,a,7);

H = fft(h,512);

plot(abs(H),'g');

hold on

[h,W]=impz(b,a,15);

H = fft(h,512);

plot(abs(H),'r');

hold on

[h,W]=impz(b,a,31);

H = fft(h,512);

plot(abs(H),'b');

toc

Telecoder Group, Applied Signal Processing Assignment 72


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title('Fourier Transform of Impulse')

legend('4 points','8 points','16 points','32 points',4)

Figures

Telecoder Group, Applied Signal Processing Assignment 73


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.11
Matlab Code

clear all; close all; clc;

a = [ 1 -1 ]; b = [ 1 0.5 0.25 0.125 ];

A = fft(a,4);

B = fft(b,4);

AB = A .* B;

ab_4 = real(ifft(AB)) %% IDFT of 4 point fft

ab_conv = conv(a,b) %% Convolution

A = fft(a,8);

B = fft(b,8);

AB = A .* B;

ab_8 = real(ifft(AB)) %% IDFT of 8 points fft

Results

ab_4 = 0.8750 -0.5000 -0.2500 -0.1250

ab_conv = 1.0000 -0.5000 -0.2500 -0.1250 -0.1250

ab_8 = 1.0000 -0.5000 -0.2500 -0.1250 -0.1250 0 0 0.0000

Telecoder Group, Applied Signal Processing Assignment 74


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 2.12

Matlab Code

clear all; close all; clc;

load handel

b=[0.2 0];

a = [1 -0.8];

[h , t] = impz(b,a,73113);

H = fft(h,8192);

X = fft(y,8192);

yy = real(ifft(X.*H));

sound(yy)

Telecoder Group, Applied Signal Processing Assignment 75


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3

Telecoder Group, Applied Signal Processing Assignment 76


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.1
Matlab Code

clear all; close all; clc;

A = 1;

N = 256;

k = 50;

x = A * sin(2*pi*k/N*(0:255));

plot(x)

title('Sinusoid with k=50')

Figures

Telecoder Group, Applied Signal Processing Assignment 77


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.2
Matlab Code

clear all; close all; clc;

A = 1;

N = 256;

k = 63;

x = A * sin(2*pi*(k)/N*(0:255));

X = fft(x);

XX = 1/N*abs(X).^2;

figure(1)

plot(10*log10(XX),'r')

title(' PSD using fft in db scale ')

gtext('k=5 for signal')

figure(2)

[Pxx,w] = periodogram(x);

periodogram(x)

Telecoder Group, Applied Signal Processing Assignment 78


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 79


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.3
Matlab Code

We have to repeat the same code for k=5


clear all; close all; clc;

A = 1;

N = 256;

fs=128;

t = 0:1/fs:(255)/fs;

f=20;

x = A * sin(2*pi*f*t);

w = flattopwin(N);

wx = x.*w';

X = fft(wx);

f=0:fs/N:(fs-1)/2;

sf = 2*(1/sum(w))^2;

XX =2*sf*abs(X).^2;

xx = sqrt(XX);

figure(1)

plot(f,abs(xx(1:length(f))),'r')

title(' PSD scaled to Amplitude using fft ')

figure(2)

[Pxx,f] = periodogram(x,w,256,fs);

Pxx = sqrt(2*2*abs(Pxx));

plot(f,(Pxx))

Telecoder Group, Applied Signal Processing Assignment 80


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title('PSD scaled to Amplitude using periodogram')

Figures

Telecoder Group, Applied Signal Processing Assignment 81


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 82


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.4
Details

Here we have to compare the peak values by using different Matlab commands. One command is
periodogram to compute PSD and the other is pwelch which use Welch periodogram method.
Comparison between peaks is done in dB scale. So the spectrum which we obtain from Welch
periodogram, we convert it into dB. Also the Welch periodogram needs to be scaled so we multiply
it with N/k.

Maximum amplitude value from Welch periodogram = 20.6785

Maximum amplitude value from periodogram (Matlab function) = 20.3718

% Magnitude error = 1.48%

Here in the sinusoidal signal there is no leakage. If we encounter leakage in the signal then we have
to use window i.e. time signal should be multiplied with time window. Leakage produces
magnitude error in the signal in the frequency domain.

Matlab Code

A = 1;

N = 256;

k = 63;

x = A * sin(2*pi*(k)/N*(0:255));

[Pxx,w] = pwelch(x);

figure(1)

plot(w/pi,abs(Pxx))

figure(2)

T=periodogram(x)

periodogram(x)
db_max=max(T)

%% Conversion in to dB scale

linear_max=N/63*10*log10(max(abs(Pxx)))

Figures

Telecoder Group, Applied Signal Processing Assignment 83


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 84


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.5
To reduce magnitude error, we have to select window with large width of main lobe and peak side
lobe.
Different windows have different specifications.
Some of them give nice approximation of amplitude error which is reduced but on the other hand
they increase the frequency uncertainly. E.g., hanning window decrease the magnitude error to
16%. Similarly,

Window Main Lobe Width


Bartlett 0.039063
Hamming 0.039063
Hanning 0.042969
Blackman 0.050781

Matlab Code

clear all; close all; clc;

N=64;

wvtool(bartlett(N));

wvtool(hamming(N));

wvtool(hanning(N));

wvtool(blackman(N));

Telecoder Group, Applied Signal Processing Assignment 85


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.6
Matlab Code

clear all; close all; clc;

N=[32 64];

for k=1:2

wvtool(bartlett(N(k)))

wvtool(blackman(N(k)))

wvtool(hamming(N(k)))

wvtool(hann(N(k)))

wvtool(flattopwin(N(k)))

end

Telecoder Group, Applied Signal Processing Assignment 86


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 87


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 88


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 89


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 90


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 91


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 3.7
Matlab Code

clear all; close all; clc;

A = 1;

N = 256;

fs=128;

t = 0:1/fs:(255)/fs;

f=20;

x = A * sin(2*pi*f*t);

w = flattopwin(N);

wx = x.*w';

X = fft(wx);

f=0:fs/N:(fs-1)/2;

sf = 2*(1/sum(w))^2;

XX =2*sf*abs(X).^2;

xx = sqrt(XX);

figure(1)

plot(f,abs(xx(1:length(f))),'r')

title(' PSD scaled to Amplitude using fft ')

figure(2)

[Pxx,f] = periodogram(x,w,256,fs);

Pxx = sqrt(2*2*abs(Pxx));

plot(f,(Pxx))

title('PSD scaled to Amplitude using periodogram')

Telecoder Group, Applied Signal Processing Assignment 92


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 93


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4

Telecoder Group, Applied Signal Processing Assignment 94


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.1
Command Window

SNR [dB]: 2000

Antal koefficienter, M: 128

plot(h,'ob')

>> hold on

>> plot(hhat,'r')

>> legend('h','hhat')

>> Q

Results

Q = 0.1056

Figures

Telecoder Group, Applied Signal Processing Assignment 95


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 96


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.2
Part A:

SNR [dB]: 25

Antal koefficienter, M: 256

>> Q

Results

Q = 7.2169e+097

>> plot(hhat,'r')

>> hold on

>> plot(h,'ob')

>> legend('hhat','h')

gtext('SNR = 25 and M=256')

Part B:

SNR [dB]: 25

Antal koefficienter, M: 128

>> Q

Results

Q = 6.9789e+045

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=25 M=128')

Telecoder Group, Applied Signal Processing Assignment 97


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 98


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.3
Part A: corr64

SNR [dB]: 1500

Antal koefficienter, M: 256

Results

Q = 0.0304

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=1500 and M=256 Fft length=64')

Figures

Part B: corr128

SNR [dB]: 1500

Antal koefficienter, M: 256

Results

Q = 0.0148

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=1500 M=256 FFt length= 128')

Result:

Telecoder Group, Applied Signal Processing Assignment 99


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Part C: corr256

SNR [dB]: 1500

Antal koefficienter, M: 256

Results

Q = 0.0157

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=1500 M=256 FFt length= 256')

Figures

Telecoder Group, Applied Signal Processing Assignment 100


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 101


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.4
Part A: corr 64

SNR [dB]: 25

Antal koefficienter, M: 256

Results

Q = 0.0302

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=25 M=256 FFT length=64')

Part B: corr 128

Telecoder Group, Applied Signal Processing Assignment 102


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

SNR [dB]: 25

Antal koefficienter, M: 256

Results

Q = 0.0160

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=25 M=256 FFT length=128')

Figures

Telecoder Group, Applied Signal Processing Assignment 103


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Part C: corr 256

SNR [dB]: 25

Antal koefficienter, M: 256

Results

Q = 0.0293

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=25 M=256 FFT length=256')

Figures

Assignment 4.5

Telecoder Group, Applied Signal Processing Assignment 104


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Part A: M=256

SNR [dB]: 1500

Antal koefficienter, M: 256

Results

Q = 0.0280

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=25 M=256 ')

Figures

Part B:

M=128;

Telecoder Group, Applied Signal Processing Assignment 105


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

SNR [dB]: 1500

Antal koefficienter, M: 128

>> Q

Results

Q = 0.0024

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=1500 M=128 ')

Part C:

M=64

SNR [dB]: 1500

Telecoder Group, Applied Signal Processing Assignment 106


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Antal koefficienter, M: 64

>> Q

Results

Q = 0.0010

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=1500 M=64 ')

Telecoder Group, Applied Signal Processing Assignment 107


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 4.6
Part A:

M=256

SNR [dB]: 30

Antal koefficienter, M: 256

>> Q

Results

Q = 0.0031

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=30 M=256 ')

Telecoder Group, Applied Signal Processing Assignment 108


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Part B:

M=128

SNR [dB]: 30

Antal koefficienter, M: 128

>> Q

Results

Q = 8.7188e-004

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=30 M=128 ')

Figures

Telecoder Group, Applied Signal Processing Assignment 109


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Part C:

M=64

SNR [dB]: 30

Antal koefficienter, M: 64

>> Q

Results

Q = 0.0026

>> plot(hhat,'b')

>> hold on

>> plot(h,'*r')

>> legend('hhat','h')

>> gtext('SNR=30 M=64 ')

Result:

Telecoder Group, Applied Signal Processing Assignment 110


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 111


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 5

Telecoder Group, Applied Signal Processing Assignment 112


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 5.1
Matlab Code

clear all; close all; clc;

N=512;

fs=512;

f=20;

t=0:1/fs:(N-1)/fs;

x=3*sin(2*pi*f*t);

X=xcorr(x);

noise=randn(1,N);

Nx=xcorr(x,noise);

fopt=X\Nx;

figure(1)

plot(fopt)

title('Optimal Filter')

Telecoder Group, Applied Signal Processing Assignment 113


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 114


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment 5.2
Matlab Code

clear all;close all; clc;

N=4096;

fs=512;

f=20;

t=0:1/fs:(N-1)/fs;

L=91; delay=25;

x=3*sin(2*pi*f*t);

d=randn(1,N);

meu_frac=0.35;

d=filter([zeros(1,delay) 1],1,d); % d= Desired Signal

w = zeros(L,1);

y = zeros(size(x)); %y = Output from the filter

e = zeros(size(x)); % e = Error Signal.

for n=L:length(x)

xn = x(n : -1 : n-L+1);

meu=meu_frac*(2/(((L+1) * mean(xn.*xn))));

y(n) = xn * w;

e(n) = d(n) - y(n);

w = w + meu * e(n)* xn';

end

plot(e)

title('Error Signal')

Telecoder Group, Applied Signal Processing Assignment 115


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 116


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment for
Grade 4

Telecoder Group, Applied Signal Processing Assignment 117


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.1


Matlab Code

clear all; close all; clc;

m = [51 71 91];

for k=1:3

M=m(k);

w=boxcar(M); %% Rectangular window

wvtool(w)

w=bartlett(M); %% Bartlett window

wvtool(w)

w=hamming(M); %% Hamming window

wvtool(w)

w=hanning(M); %% Hanning window

wvtool(w)

w=blackman(M); %% Blackman window

wvtool(w)

end

Results

Magnitude of the 1st


Window M Main Lobe width
side lobe
Rectangular 51 0.03125 -13.3
Bartlett 51 0.050781 -26.4
Hamming 51 0.050781 -42.3
Hanning 51 0.054688 -31.5
Blackman 51 0.0625 -58.1
Rectangular 71 0.023438 -13.3
Bartlett 71 0.035156 -26.5
Hamming 71 0.035156 -42.5
Hanning 71 0.039063 -31.5

Telecoder Group, Applied Signal Processing Assignment 118


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Blackman 71 0.046875 -58.1


Rectangular 91 0.017578 -13.3
Bartlett 91 0.027344 -26.5
Hamming 91 0.27344 -42.6
Hanning 91 0.03125 -31.5
Blackman 91 0.035150 -58.1

Telecoder Group, Applied Signal Processing Assignment 119


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 120


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 121


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 122


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 123


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 124


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 125


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 126


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.2


Matlab Code

clear all; close all; clc;

L = 50;

B = 1;

w1 = kaiser(L,B);

plot(w1,'b')

hold on

L = 50;

B = 5;

w2 = kaiser(L,B);

plot(w2,'r')

hold on

L = 50;

B = 9;

w3 = kaiser(L,B);

plot(w3,'g')

title('Kaiser window Time domain')

legend('Beta=1','Beta=5','Beta=9')

xlabel('Samples')

ylabel('Amplitude')

%%% Kaiser window in frequency domain

[W1,f] = freqz(w1/sum(w1),1,512,2);

[W2,f] = freqz(w2/sum(w2),1,512,2);

Telecoder Group, Applied Signal Processing Assignment 127


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

[W3,f] = freqz(w3/sum(w3),1,512,2);

figure(2)

plot(f,20*log10(abs([W1 W2 W3])));

grid;

xlabel('Normalized Frequency')

ylabel('Magnitude (dB)')

title('Kaiser Window in frequency domain')

legend('Beta = 1','Beta = 5','Beta = 9',3)

Telecoder Group, Applied Signal Processing Assignment 128


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Figures

Telecoder Group, Applied Signal Processing Assignment 129


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.3


Matlab Code

clear all; close all; clc;

w = ones(1,51); %% Rectangular window

b = fir1(50,0.25,w);

freqz(b,1,512)

title('FIR1 Window Design Method For Rectangular window, M=51 and wc=0.25')

figure(2)

zplane(b)

title('Poles and Zeros, M=51 and wc=0.25')

figure(3)

impz(b)

title('Impulse Response, M=51 and wc=0.25')

b = fir1(50,0.5,w);

figure(4)

freqz(b,1,512)

title('FIR1 Window Design Method For Rectangular window, M=51 and wc=0.5')

figure(5)

zplane(b)

title('Poles and Zeros, M=51 and wc=0.5')

figure(6)

impz(b)

title('Impulse Response, M=51 and wc=0.5')

Figures

Telecoder Group, Applied Signal Processing Assignment 130


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 131


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 132


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 133


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.4


Matlab Code

clear all; close all; clc;

w = ones(1,51); %% Rectangular window

b = fir1(50,0.25,w);

freqz(b,1,512)

m51 = ginput(2)

title('FIR1 Window Design Method For Rectangular window, M=51 and wc=0.25')

figure(2)

zplane(b)

title('Poles and Zeros, M=51 and wc=0.25')

figure(3)

impz(b)

title('Impulse Response, M=51 and wc=0.25')

%%% M = 71

w = ones(1,71); %% Rectangular window

b = fir1(70,0.25,w);

figure(4)

freqz(b,1,512)

m71 = ginput(2)

title('FIR1 Window Design Method For Rectangular window, M=71 and wc=0.25')

figure(5)

zplane(b)

title('Poles and Zeros, M=71 and wc=0.25')

Telecoder Group, Applied Signal Processing Assignment 134


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

figure(6)

impz(b)

title('Impulse Response, M=71 and wc=0.25')

%%% M = 91

w = ones(1,91); %% Rectangular window

b = fir1(90,0.25,w);

figure(7)

freqz(b,1,512)

m91 = ginput(2)

title('FIR1 Window Design Method For Rectangular window, M=91 and wc=0.25')

figure(8)

zplane(b)

title('Poles and Zeros, M=91 and wc=0.25')

figure(9)

impz(b)

title('Impulse Response, M=91 and wc=0.25')

Results

Transition Band Width (Normalize


M
frequency)
0.0389 51
0.0233 71
0.0169 91

Magnitude of 1st side lobe (dB) M


-20.2760 51
-21.6767 71
-20.7577 91

Figures

Telecoder Group, Applied Signal Processing Assignment 135


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 136


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 137


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 138


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 139


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 140


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.5


Matlab Code

clear all; close all; clc;

wrect = boxcar(71);

b = fir1(70,0.25,wrect);

freqz(b,1,512)

rec = ginput(3)

wbart = bartlett(71);

b = fir1(70,0.25,wbart);

freqz(b,1,512)

bart = ginput(3)

whamm = hamming(71);

b = fir1(70,0.25,whamm);

freqz(b,1,512)

hamm = ginput(3)

whann = hanning(71);

b = fir1(70,0.25,whann);

freqz(b,1,512)

hann = ginput(3)

wblack= blackman(71);

b = fir1(70,0.25,wblack);

freqz(b,1,512)

blac = ginput(3)

%% Kaiser window

Telecoder Group, Applied Signal Processing Assignment 141


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

L = 71;

B = 1;

w1 = kaiser(L,B);

b = fir1(70,0.25,w1);

freqz(b,1,512)

w1k = ginput(3)

B = 5;

w1 = kaiser(L,B);

b = fir1(70,0.25,w1);

freqz(b,1,512)

w5k = ginput(3)

B = 9;

w1 = kaiser(L,B);

b = fir1(70,0.25,w1);

freqz(b,1,512)

w9k = ginput(3)

M = 71

Results

Window Stop band Attenuation (dB) Transition width


Rectangular -20.4348 0.0246
Bartlett -26.3913 0.0688
Hamming -52.1304 0.0688

Telecoder Group, Applied Signal Processing Assignment 142


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Hanning -41.7391 0.0662


Blackman -73.3696 0.1051

Stopband Attenuation
Window Beta Transition width
dB
Kaiser 1 -22.9130 0.0272
Kaiser 5 -52.6957 0.0779
Kaiser 9 -87.5000 0.1025

Telecoder Group, Applied Signal Processing Assignment 143


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.6


Matlab Code

clear all; close all; clc;

wp = 0.2;

ws = 0.3;

Rp = 0.25;

As = 50;

[N,wn] = buttord(wp,ws,Rp,As);

[B,A] = butter(N,wn);

w = 0:pi/255:pi;

H = freqz(B,A,w);

plot(w/pi,20*log10(abs(H)))

M = N+1;

disp(['Filter length is ',int2str(M)])

title('Low pass Butterworth filter')

xlabel('Normalized Frequency')

ylabel('Magnitude dB')

figure(2)

zplane(H)

title('Poles and Zeros Plot')

poles = roots(B)

zeros = roots(A)

Results

Filter length is 17

Telecoder Group, Applied Signal Processing Assignment 144


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

poles =

-1.2204
-1.1956 + 0.0974i
-1.1956 - 0.0974i
-1.1300 + 0.1691i
-1.1300 - 0.1691i
-1.0443 + 0.2012i
-1.0443 - 0.2012i
-0.9597 + 0.1941i
-0.9597 - 0.1941i
-1.0139
-0.8906 + 0.1570i
-0.8906 - 0.1570i
-0.8432 + 0.1008i
-0.8432 - 0.1008i
-0.8195 + 0.0346i
-0.8195 - 0.0346i

zeros =

0.7303 + 0.5917i
0.7303 - 0.5917i
0.6554 + 0.5106i
0.6554 - 0.5106i
0.5977 + 0.4291i
0.5977 - 0.4291i
0.5538 + 0.3485i
0.5538 - 0.3485i
0.5212 + 0.2692i
0.5212 - 0.2692i
0.4982 + 0.1912i
0.4982 - 0.1912i
0.4835 + 0.1142i
0.4835 - 0.1142i
0.4763 + 0.0380i
0.4763 - 0.0380i

Figures

Telecoder Group, Applied Signal Processing Assignment 145


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 146


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.7


Matlab Code

clear all; close all; clc;

wp = [0.35 0.65];

ws = [0.2 0.8];

Rp = 1;

As = 60;

[N,wn] = buttord(wp,ws,Rp,As);

[B,A] = butter(N,wn);

w = 0:pi/255:pi;

H = freqz(B,A,w);

plot(w/pi,20*log10(abs(H)))

M = N+1;

disp(['Filter length is ',int2str(M)])

title('Low pass Butterworth filter')

xlabel('Normalized Frequency')

ylabel('Magnitude dB')

figure(2)

p = unwrap(angle(H));

plot(w/pi,p*180/pi)

title('Phase plot')

ylabel('Phase [Degrees]'), grid on

figure(3)

zplane(H)

Telecoder Group, Applied Signal Processing Assignment 147


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

title('Poles and Zeros Plot')

poles = roots(B)

zeros = roots(A)

Figures

Telecoder Group, Applied Signal Processing Assignment 148


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 149


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Zoomed View

Telecoder Group, Applied Signal Processing Assignment 150


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.8


Matlab Code

clear all; close all; clc;

wp=0.2;

ws=0.3;

rp=0.25;

As=50;

d1=(10^(rp/20)-1)/(10^(rp/20)+1);

d2=(1-d1)*(10^(-As/20));

wt=[d2/d1 1];

df=(ws-wp)/(2*pi);

M=ceil((-20*log10(sqrt(d1*d2))-13)/(14.6*df)+1);

h= firpm(M-1,[0 wp ws 1],[1 1 0 0],wt);

freqz(h,1,1024,2);

title('Magnitude for Equiripple Filter')

xlabel('Normalized frequency')

ylabel('Magnitude, dB')

figure(2)

zplane(h)

title('Plot for Poles and zeros ')

figure(3)

plot(h)

title('Impulse response of the filter');

Figures

Telecoder Group, Applied Signal Processing Assignment 151


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 152


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 153


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.9


Matlab Code

clear all; close all; clc;

Rp=1;

As=60;

k=(10^(-Rp/20));

d1=(1-k)/(1+k);

k=(10^(-As/20));

d2=k*(1+d1);

M=ceil((-20*log10(sqrt(d1*d2))-13)/(14.6*(.15/2)));

N=M-1;

wt=[1 d2/d1 1];

h= firpm(N,[0 0.2 0.35 0.65 0.8 1],[0 0 1 1 0 0],wt);

freqz(h,1,512,2);

title('Magnitude and Phase response of Equiripple Filter');

xlabel('Normalized Frequency')

ylabel('Magnitude dB')

figure(2)

zplane(h)

title('Poles and zeros of filer ');

figure(3)

stem(h)

title('Impulse response of filer');

Figures

Telecoder Group, Applied Signal Processing Assignment 154


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 155


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 156


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Assignment Grade 4.10


Matlab Code

clear all; close all; clc

fs = 200;

N = 8192;

%generating a synosoidal signal

t = 0:1/fs:(N-1)/fs;

sinus=cos(pi/2*t);

%Generating the noise signal

noise=randn(1,N);

%Generating 200 samples of signal to be filtered

x=sinus+noise;

x=x(1:200);

t=t(1:200);

% signal=signal(1:200);

Rp=.1; %Passband ripple

As=30; %stopband attenuation

d1=(10^(Rp/20)-1)/(10^(Rp/20)+1);

d2=(1-d1)*(10^(-As/20));

wt=[1 d2/d1 1];

M=51;

freq_band=[0,(.5-.08),(.5-.01),(.5+.01),(.5+.08),1];

b=firpm(M-1,freq_band,[0 0 1 1 0 0],wt);

fx=filter(b,1,x);

Telecoder Group, Applied Signal Processing Assignment 157


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

%plotting the results

freqz(b,1,512,2);

title('Amplitude and Phase response of filter');

figure(2)

plot(t(100:200),x(100:200));

title('Input Signal');

figure(3)

plot(t(100:200),fx(100:200));

title('Filtered Signal');

Figures

Telecoder Group, Applied Signal Processing Assignment 158


Blekinge Institute of Technology
Department of Telecommunication and Signal Processing

Telecoder Group, Applied Signal Processing Assignment 159

Das könnte Ihnen auch gefallen