You are on page 1of 3

(1) Linear and circular convolution

clc;
clear all;
close all;
x=[2,4,3,7]
h=[7,3,4,2]
subplot(4,1,1);
stem(x);
xlabel('Time');
ylabel('Amplitude');
title('x(n)');
subplot(4,1,2);
stem(h);
xlabel('Time');
ylabel('Amplitude');
title('h(n)');
ln=conv(x,h)
subplot(4,1,3);
stem(ln);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convolution');
cr=cconv(x,h)
subplot(4,1,4);
stem(cr);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convolution');

(2) Fft
clc;
clear all;
close all;
x=[2,3,1,5,7,6,4,8]
N=8
t=0:1:N-1;
y=fft(x)
z=ifft(y)
mag_y=abs(y);
angle_y=angle(y);
mag_z=abs(z);
angle_z=angle(z);
subplot(5,1,1);
stem(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Plot of sequnce');

subplot(5,1,2);
stem(t,mag_y);
xlabel('Time');
ylabel('Amplitude');
title('Magnitude of DFT sequence');
subplot(5,1,3);
stem(t,angle_y);
xlabel('Time');
ylabel('Amplitude');
title('Phase response of DFT sequence');
subplot(5,1,4);
stem(t,mag_z);
xlabel('Time');
ylabel('Amplitude');
title('Magnitude of IDFT sequence');
subplot(5,1,5);
stem(t,angle_z);
xlabel('Time');
ylabel('Amplitude');
title('Phae response of IDFT sequence');

(3)

Butter fly

clc;
clear all;
close all;
alphap=0.4;
alphas=30;
fp=2*pi*35;
fs=2*pi*75;
F=2000;
omp=(2*fp)/F
oms=(2*fs)/F
%to find the cutoff frequency &order of filter%
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of filter%
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=abs(h);
an=angle(h);
subplot(2,1,1);
plot(om/pi,20*log(m));grid;
xlabel('Normalised frequency');
ylabel('Gain in dB');
title('Magnitude response of low pass Butterworth filter');
subplot(2,1,2);
plot(om/pi,an);grid;
xlabel('Normalised frequency');
ylabel('Phase in Radians');
title('Phase response of low pass Butterworth filter');

Chebyshev (4)
clc;
clear all;
close all;
alphap=1; %passband attenuation
alphas=15;
%stopband attenuation
Wp=0.2*pi
Ws=0.3*pi
[n,Wn]=cheb1ord(Wp/pi,Ws/pi,alphap,alphas); %To finad the cut off frequency
&order of filter
[b,a]=cheby1(n,alphap,Wn); %system function of filter
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);grid;
xlabel('Normalized frequency');
ylabel('Gain in ds');
title('Magnitude lowpass filter Chebyshev');
subplot(2,1,2);
plot(ph/pi,an);grid;
xlabel('Normalized frequency');
ylabel('Phase reponse');
title('Phase lowpass filter Chebyshev');

You might also like