Title:write a program to find linear convolution and circular convolution with
and without zero padding
Roll No:48
clc;
clear all;
close all;
%Sampling therom in frequency domain
x = [1 2 2 1];
h = [1 2 1 0];
y_linear = conv(x,h)%linear convolution
x1 = fft(x);
h1 = fft(h);
for i= 1:4
z(i) = x1(i)*h1(i);
end
display(z);
w_circular = ifft(z);% output of circular convolution
display(w_circular);
x = [1 2 2 1 0 0 0 0];
h = [1 2 1 0 0 0 0 0];
y_linear = conv(x,h);%linear convolution
x1 = fft(x,8);
h1 = fft(h,8);
for i = 1:8
z(i) = x(i)*h(i);
end
display(z);
w_circular = ifft(z);%output of circular convolution
display(w_circular);
OUTPUT OF COMMAND WINDOW:
y_linear =
1 4 7 7 4 1 0
z =
24.0000 -2.0000 + 2.0000i 0
-2.0000 - 2.0000i
ans =
5 5 7 7
y_linear =
1 4 7 7 4 1 0 0 0 0
0 0 0 0 0
z =
Columns 1 through 4
24.0000 -5.8284 -14.0711i -2.0000 + 2.0000i
-0.1716 - 0.0711i
Columns 5 through 8
0 -0.1716 + 0.0711i -2.0000 - 2.0000i
-5.8284 +14.0711i
w_circular =
1.0000 4.0000 7.0000 7.0000 4.0000 1.0000
0 -0.0000
ans =
1.0000 4.0000 7.0000 7.0000 4.0000 1.0000
0 0.0000
Title: Design Butterworth filter using bilinear transformation method for LPF
and HPF and write a program to draw the frequency response of the filter
Roll No:48
High Pass Filter
clc;
clear all;
close all;
fp = input('Enter the pass band frequency:');
fs = input('Enter the stop band frequency:');
rp = input('Enter the stop band ripple:');
rs = input('Enter the stop band ripple:');
f = input('Enter the sampling frequency:');
wp = 2*fp/f;
ws = 2*fs/f;
[N, wn] = buttord(wp, ws, rp, rs)%% returns lowest
order to filter
[b, a] = butter(N, wn, 'high');%% returns TF
coefficients
Hs = tf(b, a) %% computes the transfer
function(TF)
[h , ph] = freqz(b,a);
m = 20*(log10 (abs(h)));
y = angle(h);
subplot(2,2,1);
plot(ph/pi, m);
title('Fig. 1 Magnitude Plot of Analog Butterworth
Filter IIR LPF');
grid on;
subplot(2,2,2);
plot(ph/pi, y);
title('Fig.2 Phase Plot of Analog Butterworth Filter
IIR HPF');
grid on;
[bz, az] = bilinear(b,a,f)%% Matches the frequency to
normalized frequency
T = 1/f;
Hz = tf(bz, az, T)
[h1, ph1] = freqz(bz, az, 512,f);
m1 = 20*(log10 (abs(h1)));
y1 = angle(h1);
subplot(2,2,3);
plot(ph/pi, m1);
title('Fig. 3 Magnitude Plot of Digital Butterworth
Filter IIR HPF');
grid on;
%
subplot(2,2,4);
plot(ph/pi, y1);
title('Fig. 4 Phase Plot of Digital Butterworth Filter
IIR HPF');
grid on;
zplane(bz, az)
OUTPUT OF COMMAND WINDOW:
Enter the pass band frequency:2500
Enter the stop band frequency:1200
Enter the stop band ripple:1
Enter the stop band ripple:40
Enter the sampling frequency:8000
N=5
wn = 0.5778
Transfer function:
0.02716 s^5 - 0.1358 s^4 + 0.2716 s^3 - 0.2716 s^2 + 0.1358 s - 0.02716
-----------------------------------------------------------------------
s^5 + 0.7659 s^4 + 0.8389 s^3 + 0.2841 s^2 + 0.0883 s + 0.007964
bz =0.0272 -0.1358 0.2716 -0.2716 0.1358 -0.0272
az =1.0000 -4.9999 9.9996 -9.9994 4.9996 -0.9999
Transfer function:
0.02715 z^5 - 0.1358 z^4 + 0.2716 z^3 - 0.2716 z^2 + 0.1358 z - 0.02717
-----------------------------------------------------------------------
z^5 - 5 z^4 + 10 z^3 - 9.999 z^2 + 5 z - 0.9999
Sampling time: 0.000125
OUTPUT WAVEFORM:
Low Pass Filter:
clc;
clear all;
close all;
fp = input('Enter the pass band frequency:');
fs = input('Enter the stop band frequency:');
rp = input('Enter the pass band ripple:');
rs = input('Enter the stop band ripple:');
f = input('Enter the sampling frequency:');
wp = 2*fp/f;
ws = 2*fs/f;
[N, wn] = buttord(wp, ws, rp, rs) %% returns lowest order to
filter
[b, a] = butter(N, wn); %% returns TF coefficients
Hs = tf(b, a) %% computes the transfer function(TF)
[h , ph] = freqz(b,a);
m = 20*(log10 (abs(h)));
y = angle(h);
subplot(2,2,1);
plot(ph/pi, m);
title('Fig. 1 Magnitude Plot of Analog Butterworth Filter IIR
LPF');
grid on;
subplot(2,2,2);
plot(ph/pi, y);
title('Fig.2 Phase Plot of Analog Butterworth Filter IIR LPF');
grid on;
[bz, az] = bilinear(b,a,f) %% Matches the frequency to normalized
frequency
T = 1/f;
Hz = tf(bz, az, T)
[h1, ph1] = freqz(bz, az, 512,f);
m1 = 20*(log10 (abs(h1)));
y1 = angle(h1);
subplot(2,2,3);
plot(ph/pi, m1);
title('Fig. 3 Magnitude Plot of Digital Butterworth Filter IIR
LPF');
grid on;
subplot(2,2,4);
plot(ph/pi, y1);
title('Fig. 4 Phase Plot of Digital Butterworth Filter IIR LPF');
grid on;
zplane(bz, az)
OUTPUT OF COMMAND WINDOW:
Enter the pass band frequency:1200
Enter the stop band frequency:2500
Enter the pass band ripple:1
Enter the stop band ripple:40
Enter the sampling frequency:8000
N=5
wn = 0.3421
Transfer function:
0.01177 s^5 + 0.05887 s^4 + 0.1177 s^3 + 0.1177 s^2 + 0.05887 s + 0.01177
-------------------------------------------------------------------------
s^5 - 1.558 s^4 + 1.488 s^3 - 0.7379 s^2 + 0.2092 s - 0.02445
bz =0.0118 -0.0589 0.1178 -0.1177 0.0589 -0.0118
az = 1.0000 -5.0002 10.0008 -10.0012 5.0008 -1.0002
Transfer function:
0.01178 z^5 - 0.05889 z^4 + 0.1178 z^3 - 0.1177 z^2 + 0.05886 z - 0.01177
-------------------------------------------------------------------------
z^5 - 5 z^4 + 10 z^3 - 10 z^2 + 5.001 z - 1
Sampling time: 0.000125
>> fdatool
OUTPUT WAVEFORM:
Title: To study the effect of different windows on FIR filter response.
Roll No:48
Rectangular Window
clc;
close all;
clear all;
%%PROGRAM TO DESIGN RECTANGULAR WINDOW
rp=input('enter passband ripples:');
rs=input('enter stopband ripples:');
fp=input('enter passband frequency:');
fs=input('enter stopband frequency:');
f=input('enter sampling frequncy:');
wp=2*fp/f
ws=2*fs/f
num=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(num/den)%% reconstructs the original image
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=boxcar(n1);%% impulse response of the filter
subplot(2,1,1);
plot(y);
title('fig.1 magnitude plot of rectangular window');
grid on;
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);%%returns the complex frequency response
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
grid on;
title('fig.2 magnitude response of digital LP FIR filter');
xlabel('normalized frequncy in dB');
ylabel('normalized gain in dB');
OUTPUT OF COMMAND WINDOW:
enter passband ripples:0.05
enter stopband ripples:0.03
enter passband frequency:1200
enter stopband frequency:2500
enter sampling frequncy:8000
wp = 0.3000
ws = 0.6250
num = 15.2391
den =2.3725
n= 7
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Kaiser Window
clc;
clear all;
close all;
%%PROGRAM TO DESIGN KAISER WINDOW
rp = input('enter the passband ripple = ');
rs = input('enter the stopband ripple =');
fp = input('enter the passband frequency = ');
fs = input('enter the stopband frequency = ');
f = input('enter the sampling frequency = ');
B = input(enter the value of B);
wp = 2*fp/f
ws = 2*fs/f
num = -20*log10(sqrt(rp*rs))-13
den = 14.6*(fs-fp)/f
n = ceil(num/den) %% reconstructs the original image
n1 = n+1
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
y = kaiser(n1,B)%% returns a Kaiser window
subplot(2,1,1);
plot(y);
title('fig. Magnitude response')
grid on;
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256)
m = 20*log10(abs(h));
subplot(2,1,2)
plot(o/pi,m)
grid on;
title('Fig1. : Magnitude response')
xlabel('Normalized Frequency')
ylabel('Normalized gain in Db')
OUTPUT:
OUTPUT OF COMMAND WINDOW:
enter the passband ripple = 0.04
enter the stopband ripple =0.02
enter the passband frequency = 1500
enter the stopband frequency = 2500
enter the sampling frequency = 7000
enter the value of B0.6
wp = 0.4286
ws =0.7143
num = 17.9691
den =2.0857
n= 9
n1 = 10
y= 0.9157
0.9521
0.9786
0.9946
1.0000
0.9946
0.9786
0.9521
0.9157
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Hanning Window
clc;
clear all;
close all;
%%PROGRAM TO DESIGN HANNING WINDOW
rp = input('enter the passband ripple = ');
rs = input('enter the stopband ripple =');
fp = input('enter the passband frequency = ');
fs = input('enter the stopband frequency = ');
f = input('enter the sampling frequency = ');
wp = 2*fp/f
ws = 2*fs/f
num = -20*log10(sqrt(rp*rs))-13
den = 14.6*(fs-fp)/f
n = ceil(num/den) %% reconstructs the original image
n1 = n+1
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
y = hanning(n1)%%returns a hanning window
subplot(2,1,1);
plot(y);
title('fig. Magnitude response')
grid on;
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256)
M = 20*log10(abs(h));
subplot(2,1,2)
plot(o/pi,m)
grid on;
title('Fig1. : Magnitude response')
xlabel('Normalized Frequency')
ylabel('Normalized gain in dB')
OUTPUT:
OUTPUT OF COMMAND WINDOW:
enter the passband ripple = 0.04
enter the stopband ripple =0.02
enter the passband frequency = 1500
enter the stopband frequency = 2500
enter the sampling frequency = 7000
wp = 0.4286
ws =0.7143
num = 17.9691
den = 2.0857
n=9
n1 = 10
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Hamming Window
clc;
clear all;
close all;
%%PROGRAM TO DESIGN HAMMING WINDOW
rp = input('enter the passband ripple = ');
rs = input('enter the stopband ripple =');
fp = input('enter the passband frequency = ');
fs = input('enter the stopband frequency = ');
f = input('enter the sampling frequency = ');
wp = 2*fp/f
ws = 2*fs/f
num = -20*log10(sqrt(rp*rs))-13
den = 14.6*(fs-fp)/f
n = ceil(num/den) %% reconstructs the original image
n1 = n+1
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
y = hamming(n1)%%returns a hamming window
subplot(2,1,1);
plot(y);
title('fig. Magnitude response')
grid on;
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256)
M = 20*log10(abs(h));
subplot(2,1,2)
plot(o/pi,m)
grid on;
title('Fig1. : Magnitude response')
xlabel('Normalized Frequency')
ylabel('Normalized gain in dB')
OUTPUT:
OUTPUT OF COMMAND WINDOW:
enter the passband ripple = 0.04
enter the stopband ripple =0.02
enter the passband frequency = 1500
enter the stopband frequency = 2500
enter the sampling frequency = 7000
wp =0.4286
ws =0.7143
num = 17.9691
den =2.0857
n=9
n1 = 10
y=
0.0800
0.2147
0.5400
0.8653
1.0000
0.8653
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Bartlet Window
clc;
close all;
clear all;
%%PROGRAM TO DESIGN BARTLETT WINDOW
rp = input('enter the passband ripple = ');
rs = input('enter the stopband ripple =');
fp = input('enter the passband frequency = ');
fs = input('enter the stopband frequency = ');
f = input('enter the sampling frequency = ');
wp = 2*fp/f
ws = 2*fs/f
num = -20*log10(sqrt(rp*rs))-13
den = 14.6*(fs-fp)/f
n = ceil(num/den) %% reconstructs the original image
n1 = n+1
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
y = bartlett(n1)%%returns a bartlet window
subplot(2,1,1);
plot(y);
title('fig. Magnitude response')
grid on;
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256)
m = 20*log10(abs(h));
subplot(2,1,2)
plot(o/pi, m)
grid on;
title('Fig1. : Magnitude response')
xlabel('Normalized Frequency')
ylabel('Normalized gain in dB')
OUTPUT:
OUTPUT OF COMMAND WINDOW:
enter the passband ripple = 0.04
enter the stopband ripple =0.02
enter the passband frequency = 1500
enter the stopband frequency = 2500
enter the sampling frequency = 7000
wp = 0.4286
ws =0.7143
num =17.9691
den =2.0857
n =9
n1 =10
y= 0
0.2500
0.5000
0.7500
1.0000
0.7500
0.500
0.2500
H=
1.0000
0.9988 - 0.0491i
0.9951 - 0.0980i
0.9889 - 0.1467i
0.9803 - 0.1950i
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Blackman Window
clc;
close all;
clear all;
%%PROGRAM TO DESIGN BLACKMAN WINDOW
rp = input('enter the passband ripple = ');
rs = input('enter the stopband ripple =');
fp = input('enter the passband frequency = ');
fs = input('enter the stopband frequency = ');
f = input('enter the sampling frequency = ');
wp = 2*fp/f
ws = 2*fs/f
num = -20*log10(sqrt(rp*rs))-13
den = 14.6*(fs-fp)/f
n = ceil(num/den) %% reconstructs the original image
n1 = n+1
if(rem(n,2)~=0)
n1 = n;
n = n-1;
end
y = blackman(n1)%%returns blackman window
subplot(2,1,1);
plot(y);
title('fig. Magnitude response')
grid on;
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256)
m = 20*log10(abs(h));
subplot(2,1,2)
plot(o/pi, m)
grid on;
title('Fig1. : Magnitude response')
xlabel('Normalized Frequency')
ylabel('Normalized gain in dB')
OUTPUT:
OUTPUT OF COMMAND WINDOW:
enter the passband ripple = 0.04
enter the stopband ripple =0.02
enter the passband frequency = 1500
enter the stopband frequency = 2500
enter the sampling frequency = 7000
wp =0.4286
ws =0.7143
num = 17.9691
den = 2.0857
n=9
n1 =10
y =
-0.0000
0.0664
0.3400
0.7736
1.0000
0.7736
0.3400
0.0664
-0.0000
h=
1.0000
0.9988 - 0.0491i
0.9950 - 0.0980i
0.9888 - 0.1467i
0.9801 - 0.1949i
0.9689 - 0.2427i
OUTPUT WAVEFORM:
%% Output Of Figure Window:
%% Output Of fdatool :
Title:To Design and implement two stage sampling rate
converter.
Roll No:48
%% PROGRAM TODESIGN & IMPLEMENT 2-STAGE SAMPLING RATE CONVERTOR
fm=input('Enter the frequency of DT signal:');
Fs=input('Sampling frequency of DT sinusoid:');
M=input('Down sampling factor=');
L=input('Up sampling factor=');
t=0:1/Fs:0.5;
x=sin(2*pi*fm*t);%%equation of sine wave
figure(1);
subplot(4,1,1);
stem(x); %% plots discrete data sequence
xlabel('No. of samples');
ylabel('Amplitude');
title('Input discrete sinusoidal sequence');
xd=decimate(x,M);%% reduction in sampling rate
subplot(4,1,2);
stem(xd); %% plots discrete data sequence
xlabel('No. of samples');
ylabel('Amplitude');
title('Decimated sinusoidal sequence');
xi=interp(x,L);%%increase in sampling rate
subplot(4,1,3);
stem(xi);%% plots discrete data sequence
xlabel('No. of samples');
ylabel('Amplitude');
title('Interpolated sinusoidal sequence');
xi=interp(xd,L); %%increase in sampling rate
subplot(4,1,4);
stem(xi); %% plots discrete data sequence
xlabel('No. of samples');
ylabel('Amplitude');
title('Original signal obtained after interpolating the decimated sequence');
OUTPUT OF COMMAND WINDOW:
Enter the frequency of DT signal:30
Sampling frequency of DT sinusoid:300
Down sampling factor=3
Up sampling factor=3
OUTPUT WAVEFORM:
Title: To find Z and inverse Z transform and pole zero plot
of Z-transfer function.
Roll No:48
clc;
close all;
clear all;
%% PROGRAM TO FIND THE Z TRANSFORM
syms n a w;%%creates symbolic representation of data
xn=input('Enter sequence:');
y=ztrans(xn) %%obtains ztransform
num=input('Enter num coeff:');
den=input('Enter the den coeff:');
figure;
zplane(num,den);%%plots the zeros and poles
figure;
freqz(num,den);%%returns the complex frequency response
EXAMPLE 1:
OUTPUT OF COMMAND WINDOW:
Enter sequence:n^2
y =(z^2 + z)/(z - 1)^3
Enter num coeff:[1 1 0]
Enter the den coeff:[1 -3 3 -1]
OUTPUT WAVEFORM:
Pole Zero Plot:
Frequency Response:
EXAMPLE 2:
OUTPUT OF COMMAND WINDOW:
Enter sequence:n*(-1)^n
y =-z/(z + 1)^2
Enter num coeff:[-1 0]
Enter the den coeff:[1 2 1]
OUTPUT WAVEFORM:
Pole Zero Plot:
Frequency Response:
Title: Computation of DCT and IDCT of a discrete time
signal
Roll No:48
clc;
clear all;
close all;
fp = fopen('watermark.wav', 'r');%%o pen file, or obtain
information about open files
fseek(fp, 44, -1)%% Set file position indicator
a = fread(fp, 1024);%% Read binary data from file
plot(a);
hold on;
title('Plot of Original speech signal');
xlabel('sample number');
ylabel('Amplitude');
figure;
c = dct(a);%% Discrete cosine transform
plot(c);
hold on
title('Plot of frequency contents of speech signal in
DCT domain');
xlabel('DCT Coefficient number');
ylabel('Amplitude');
for i = 1:104
d1(i)= c(i);
end
for i = 105:1023
d1(i)= 0;
end
figure;
plot(d1);
title('Plot of frequency contents of speech signal
after LPF WINDOW TO PASS 1 TO 104 dct samples');
xlabel('DCT Coefficient number');
ylabel('Amplitude');
d2 = idct(d1);%% Inverse discrete cosine transform
figure;
plot(d2);
title('Plot of LPF (DCT domain) speech signal');
xlabel('Sample number');
ylabel('Amplitude');
OUTPUT WAVEFORM: