Beruflich Dokumente
Kultur Dokumente
Group Members
Adnan Saleem
E-mail:electropall@hotmail.com
Student Personal No: 810524-P510
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
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
Assignment 1
Assignment 1.1
Matlab Code
t=0:99;
delta=zeros(1,100);
delta(1,1)=1;
plot(t,delta,'*b')
figure(2)
UnitS=ones(1,100);
plot(t,UnitS,'*r')
figure(3)
stem(t,delta)
figure(4)
stem(t,UnitS)
Figures
Assignment 1.2
Matlab Code
n=0:99;
UnitS=ones(1,100);
func= a.^n.*UnitS;
S_matlab=sum(func)
Geom_sum= (1 - a^100) /( 1 - a )
plot(n,func)
Results
a=0.5
Sum by Matlab= 2
Geometric sum = 2
a=0.9
a=1
a=1.1
a=2
Figures
Assignment 1.3
Matlab Code
fs=2;
n=0:1/fs:(8192-1)/fs;
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
Assignment 1.4
Matlab Code
fs=2;
n=0:1/fs:(8192-1)/fs;
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.
Assignment 1.5
Matlab Code
fs=512;
n=0:1/fs:(8192-1)/fs;
for k=1:3
x(:,k)=cos(2*pi*f(k)*n);
figure(k)
if k==1
plot(n,x(:,k),'b')
end
if k==2
plot(n,x(:,k),'r')
end
if k==3
plot(n,x(:,k),'g')
end
end
Figures
Assignment 1.6
Matlab Code
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')
sound(x);
pause
sound(abs(x));
pause
sound(real(x))
pause
sound(imag(x))
Figures
Assignment 1.7
Matlab Code
fs=1024;
t1=0:1/fs:(16384*5-1)/fs;
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')
delay = 2;
[y,ty] = rcosflt(y,1,2,'fir',.3,delay);
sound(y)
figure(4)
plot(ty,y)
Figures
Assignment 1.8
Matlab Code
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)
Figures
Assignment 1.9
Matlab Code
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)
Figures
Assignment 1.10
Matlab Code
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)
gtext(' 1 + cos(2*pi*0.0625*n)')
Figures
Assignment 1.11
Matlab Code
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)
Figures
Assignment 1.12
Matlab Code
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;
Y(1,k-3)=median(yy);
End
figure(1)
plot(n(1:length(Y)),Y)
Figures
Assignment 1.13
Matlab Code
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
Assignment 1.14
Matlab Code
load assign1_9
conv1_9=conv(x,y);
figure(1)
stem(conv1_9(1:50))
load assign1_10
conv1_10=conv(x,y);
figure(2)
stem(conv1_10(1:50))
load assign1_11
conv1_11=conv(x,y);
figure(3)
stem(conv1_11(1:50))
Figures
Assignment 1.15
Matlab Code
load assign1_9
filt1_9=filter(x,1,y);
figure(1)
stem(filt1_9(1:50))
load assign1_10
filt1_10=filter(x,1,y);
figure(2)
stem(filt1_10(1:50))
load assign1_11
filt1_11=filter(x,1,y);
figure(3)
stem(filt1_11(1:50))
Figures
Assignment 1.16
Matlab Code
load handel;
yy=y;
N=25;
n=zeros(1,N);
p1=n;
p1(1,1)=1;
conv1_9=conv(x,y);
p2=[1];
y1=filter(conv1_9,p2,yy);
sound(y1)
conv1_11=conv(x,y);
y2=filter(conv1_11,p2,yy);
sound(y2)
Assignment 1.17
Matlab Code
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')
Figures
Assignment 1.18
Matlab Code
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')
[h r]= deconv(y,x);
figure
plot(h)
Figures
Assignment 1.19
Matlab Code
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
sound(yy)
yyy=yy';
sound(Y)
Assignment 2
Assignment 2.1
Matlab Code
a=[1 -1 0.5];
Poles=roots(a)
Zeros=roots(b)
[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')
Figures
Assignment 2.2
Matlab Code
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')
[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)
plot(t,H,'*r')
Figures
Assignment 2.3
Matlab Code
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')
[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;
plot(t,uu,'*r')
Figures
Assignment 2.4
Matlab Code
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')
[h,t] = impz(b,a,length(ecg));
figure(3)
plot(t,h)
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')
Figures
Assignment 2.5
Matlab Code
[Hr,w] = zerophase(b,a);
HR=abs(Hr.*Hr);
plot((HR))
figure(2)
phi = angle(Hr);
plot(phi)
Figures
Assignment 2.6
Matlab Code
a = [1 -0.8];
[h,t]=impz(b,a);
[H,W]=freqz(h);
figure(1)
semilogy(W,abs(H),'b')
hold on
semilogy(W,abs(H_th),'--r')
figure(2)
y = angle(H);
plot(y)
title('Phase function')
Figures
Assignment 2.7
Matlab Code
a = [1 -0.8];
%% using 4 points
[H,W]=impz(b,a,4);
figure(1)
stem(W,abs(H))
%% using 8 points
[H,W]=impz(b,a,8);
figure(2)
stem(W,abs(H))
%% using 16 points
[H,W]=impz(b,a,16);
figure(3)
stem(W,abs(H))
%% using 32 points
[H,W]=impz(b,a,32);
figure(4)
stem(W,abs(H))
%% Untruncated filter
[H,W]=impz(b,a);
figure(5)
stem(W,abs(H))
Figures
Assignment 2.8
Matlab Code
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')
Figures
Assignment 2.9
Matlab Code
format long
tic
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
Figures
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
format long
tic
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
Figures
Assignment 2.11
Matlab Code
A = fft(a,4);
B = fft(b,4);
AB = A .* B;
A = fft(a,8);
B = fft(b,8);
AB = A .* B;
Results
Assignment 2.12
Matlab Code
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)
Assignment 3
Assignment 3.1
Matlab Code
A = 1;
N = 256;
k = 50;
x = A * sin(2*pi*k/N*(0:255));
plot(x)
Figures
Assignment 3.2
Matlab Code
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')
figure(2)
[Pxx,w] = periodogram(x);
periodogram(x)
Figures
Assignment 3.3
Matlab Code
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')
figure(2)
[Pxx,f] = periodogram(x,w,256,fs);
Pxx = sqrt(2*2*abs(Pxx));
plot(f,(Pxx))
Figures
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.
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
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,
Matlab Code
N=64;
wvtool(bartlett(N));
wvtool(hamming(N));
wvtool(hanning(N));
wvtool(blackman(N));
Assignment 3.6
Matlab Code
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
Figures
Assignment 3.7
Matlab Code
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')
figure(2)
[Pxx,f] = periodogram(x,w,256,fs);
Pxx = sqrt(2*2*abs(Pxx));
plot(f,(Pxx))
Figures
Assignment 4
Assignment 4.1
Command Window
plot(h,'ob')
>> hold on
>> plot(hhat,'r')
>> legend('h','hhat')
>> Q
Results
Q = 0.1056
Figures
Assignment 4.2
Part A:
SNR [dB]: 25
>> Q
Results
Q = 7.2169e+097
>> plot(hhat,'r')
>> hold on
>> plot(h,'ob')
>> legend('hhat','h')
Part B:
SNR [dB]: 25
>> Q
Results
Q = 6.9789e+045
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Assignment 4.3
Part A: corr64
Results
Q = 0.0304
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
Part B: corr128
Results
Q = 0.0148
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Result:
Part C: corr256
Results
Q = 0.0157
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
Assignment 4.4
Part A: corr 64
SNR [dB]: 25
Results
Q = 0.0302
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
SNR [dB]: 25
Results
Q = 0.0160
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
SNR [dB]: 25
Results
Q = 0.0293
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
Assignment 4.5
Part A: M=256
Results
Q = 0.0280
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
Part B:
M=128;
>> Q
Results
Q = 0.0024
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Part C:
M=64
Antal koefficienter, M: 64
>> Q
Results
Q = 0.0010
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Assignment 4.6
Part A:
M=256
SNR [dB]: 30
>> Q
Results
Q = 0.0031
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
Part B:
M=128
SNR [dB]: 30
>> Q
Results
Q = 8.7188e-004
>> plot(hhat,'b')
>> hold on
>> plot(h,'*r')
>> legend('hhat','h')
Figures
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')
Result:
Assignment 5
Assignment 5.1
Matlab Code
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')
Figures
Assignment 5.2
Matlab Code
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;
w = zeros(L,1);
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;
end
plot(e)
title('Error Signal')
Figures
Assignment for
Grade 4
m = [51 71 91];
for k=1:3
M=m(k);
wvtool(w)
wvtool(w)
wvtool(w)
wvtool(w)
wvtool(w)
end
Results
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')
legend('Beta=1','Beta=5','Beta=9')
xlabel('Samples')
ylabel('Amplitude')
[W1,f] = freqz(w1/sum(w1),1,512,2);
[W2,f] = freqz(w2/sum(w2),1,512,2);
[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)')
Figures
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)
figure(3)
impz(b)
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)
figure(6)
impz(b)
Figures
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)
figure(3)
impz(b)
%%% M = 71
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)
figure(6)
impz(b)
%%% M = 91
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)
figure(9)
impz(b)
Results
Figures
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
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
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
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;
xlabel('Normalized Frequency')
ylabel('Magnitude dB')
figure(2)
zplane(H)
poles = roots(B)
zeros = roots(A)
Results
Filter length is 17
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
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;
xlabel('Normalized Frequency')
ylabel('Magnitude dB')
figure(2)
p = unwrap(angle(H));
plot(w/pi,p*180/pi)
title('Phase plot')
figure(3)
zplane(H)
poles = roots(B)
zeros = roots(A)
Figures
Zoomed View
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);
freqz(h,1,1024,2);
xlabel('Normalized frequency')
ylabel('Magnitude, dB')
figure(2)
zplane(h)
figure(3)
plot(h)
Figures
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;
freqz(h,1,512,2);
xlabel('Normalized Frequency')
ylabel('Magnitude dB')
figure(2)
zplane(h)
figure(3)
stem(h)
Figures
fs = 200;
N = 8192;
t = 0:1/fs:(N-1)/fs;
sinus=cos(pi/2*t);
noise=randn(1,N);
x=sinus+noise;
x=x(1:200);
t=t(1:200);
% signal=signal(1:200);
d1=(10^(Rp/20)-1)/(10^(Rp/20)+1);
d2=(1-d1)*(10^(-As/20));
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);
freqz(b,1,512,2);
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