You are on page 1of 5

CONVOLUTION

%program for the generation of first sequence[x(n)]


N=input('enter the length of I sequence:');
n=-N:1:N;
X=input('enter the first sequence:');
subplot(3,1,1);
stem(n,X);
xlabel('time index');
ylabel('x(n)');
title('Iinputpsequence');
%program for the generation of second sequence[h(n)]
K=input('enter the length of II sequence:');
k=-K:1:K;
H=input('enter the second sequence:');
subplot(3,1,2);
stem(k,H);
xlabel('time index');
ylabel('h(k)');
title('IIinputpsequence');
%program for the generation of first sequence[y(n)=x(n)*h(n)]
p=(-N-K):1:(K+N);
y=conv(X,H)
subplot(3,1,3);
stem(p,y);
xlabel('time index');
ylabel('y(p)');
title('convolution');


FREQUENCY RESPONSE OF DISCRETE TIME SYSTEM

%program to plot frequency response of first order system
%y(n)-0.8y(n-1)=x(n)
clear all;
a=[1,-0.8];
b=[1];
w=-(2*pi):0.001:(2*pi);
[h]=freqz(b,a,w);
subplot(2,1,1);
plot(w/pi,abs(h));grid;
title('frequency response in pi');
xlabel('normalised frequency');
ylabel('magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h));grid;
xlabel('normalised frequency');
ylabel('phase response');

DFT USING FFT
%program to compute DFT using FFT
clear all;
N=input('enter length of FFT:');
k=0:N-1;
x=input('enter the sequence:');
D=fft(x,N);
subplot(2,1,1);
stem(k,abs(D));
xlabel('k');
ylabel('real part of D');
title('magnitude part');
subplot(2,1,2);
stem(k,angle(D));
xlabel('k');
ylabel('imaginary part of D');
title('phase part');

BUTTERWORTH LPF
%program to design a butterworth low pass filter for the given
%specifications
clear all;
alphap=4;%pass band attenuation in dB
alphas=30;%stop band attenuation in dB
fp=400;%pass band frequency in hz
fs=800;%stop band frequency in hz
F=2000;%sampling frequency in hz
omp=2*fp/F; oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn)
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);grid;
xlabel('gain in dB');
ylabel('normalised frequency');
title('magnitude response');
subplot(2,1,2);
plot(om/pi,an);grid;
ylabel('phase in radians')
xlabel('normalised frequency');
title('phase response');

BPF
%program to design a butterworth band pass filter for the
given
%specifications
clear all;
alphap=2;%pass band attenuation in dB
alphas=20;%stop band attenuation in dB
wp=[0.2*pi,0.4*pi];%pass band frequency in hz
ws=[0.1*pi,0.5*pi];%stop band frequency in hz
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn)
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('gain in dB');
ylabel('normalised frequency');
title('magnitude response');
subplot(2,1,2);
plot(ph/pi,an);grid;
ylabel('phase in radians')
xlabel('normalised frequency');
title('phase response');

HPF
%program to design a butterworth high pass filter for the
given
%specifications
clear all;
alphap=4;%pass band attenuation in dB
alphas=30;%stop band attenuation in dB
fp=400;%pass band frequency in hz
fs=800;%stop band frequency in hz
F=2000;%sampling frequency in hz
omp=2*fp/F; oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn,'high')
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);grid;
xlabel('gain in dB');
ylabel('normalised frequency');
title('magnitude response');
subplot(2,1,2);
plot(om/pi,an);grid;
ylabel('phase in radians')
xlabel('normalised frequency');
title('phase response');

DISCRETE
%program for generation of unit impulse sequence[$(n)]
k=input('enter the length of sequence of k=');
n=-k:1:k;
x=[zeros(1,k),ones(1,1),zeros(1,k)];
subplot(5,1,1);
stem(n,x);
xlabel('time index');
ylabel('$(n)');
title('unit impulse');
%program for generation of unit step function[U(n)]
L=input('enter length of sequence of L:');
n=-L:1:L;
x=[zeros(1,L),ones(1,(L+1))];
subplot(5,1,2);
stem(n,x);
xlabel('time index');
ylabel('U(n)');
title('unit step');
%program for generation of exponential function[c*(a.^n)]
N=input('Enter the duration of the signal N = ');
a=input ('Enter the scaling factor a = ');
c=input('enter the coefficient c=');
n=0:n-1;
y=c*(a.^n);
subplot(5,1,3);
stem(n,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Exponential Signal');
%program for generation of sinusoidal sequence[S(n)]
N=input('enter length of sequence of N:');
n=0:N;
x=sin(2*pi/10*n);
subplot(5,1,4);
stem(n,x);
xlabel('time index');
ylabel('S(n)');
title('sinusoidal');
%program for generation of ramp function[Z(n)]
O=input('enter length of sequence of O:');
L=0:O;
x=L;
subplot(5,1,5);
stem(L,x);
xlabel('time index');
ylabel('Z(n)');
title('ramp function');

FOURIER TRANSFORM

%program for fourier transform of discete time
n=-10:10;
x=(-0.9).^n;
k=-200:200;
w=(pi/100)*k;
x=x*(exp(-1j*(pi/100)*(n'*k)));
magx=abs(x);
angx=angle(x);
subplot(2,1,1);
plot(w/pi,magx);grid;
xlabel('frequency in pi');
ylabel('modx');
title('magnitude port');
subplot(2,1,2);
plot(w/pi,angx/pi);grid;
xlabel('frequency in pi');
ylabel('phase part');

You might also like