Sei sulla pagina 1di 13

% Exp 2 unit step, unit impulse, unit ramp, exponnetial and addition of two

sinusiodal
% sequences
close all; clear all;
%%%%%%%%%%%%%%%%%%unit step%%%%%%%%%%
n=input('enter the N value');
t=0:1:n-1;
y1=ones(1,n);
figure(1)
subplot(2,2,1)
stem(t,y1); ylabel('Amplitude--------->');
xlabel('(a)n--->');
%%%%%%%%%%%%%unit impulse%%%%%%%%%
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(2,2,2)
stem(t,y); ylabel('Amplitude--------->');
xlabel('(b)n--->');
%%%%%%%%%%%%%unit ramp%%%%%%%%%
n1=input('enter the length of ramp sequence');
t=0:n1;
subplot(2,2,3)
stem(t,t); ylabel('Amplitude--------->');
xlabel('(c)n--->');
%%%%%%%%%%%%%exponential %%%%%%%%%
n2=input('enter the length of exponential sequence');
t=0:n2;

a=input('Enter the a value')


y2=exp(a*t);
subplot(2,2,4)
stem(t,y2); ylabel('Amplitude--------->');
xlabel('(d)n--->');
%%%%%%%%%%%%%sine sequence %%%%%%%%%
t=0:.1:pi;
y4=sin(2*pi*t);
figure(2)
subplot(3,1,1)
stem(t,y4); ylabel('Amplitude--------->');
xlabel('(a)n--->');
%%%%%%%%%%%%%cosine sequence %%%%%%%%%
t=0:.1:pi;
y5=cos(2*pi*t);
subplot(3,1,2)
stem(t,y5); ylabel('Amplitude--------->');
xlabel('(b)n--->');
%%%%%%%%%%%%%cosine + sine sequence %%%%%%%%%
y6=y4+y5;
subplot(3,1,3)
stem(t,y6); ylabel('Amplitude--------->');
xlabel('(c)n--->');

%Exp 3 Convolution sum of discrete signals


% x=[1 2]

%h=[1 2 4]
% y=[1 4 8 8]
close all; clear all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=conv(x,h)
figure;
subplot(3,1,1)
stem(x);ylabel('Amplitude--------->');
xlabel('(a)n--->');
subplot(3,1,2)
stem(h);ylabel('Amplitude--------->');
xlabel('(b)n--->');
subplot(3,1,3)
stem(y);ylabel('Amplitude--------->');
xlabel('(c)n--->');

%Exp 4 Cross-Correlation of two sequences


% x=[1 2 3 4]
%h=[4 3 2 1 ]
% y=[1.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000]
close all; clear all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=xcorr(x,h)
figure;
subplot(3,1,1)
stem(x);ylabel('Amplitude--------->');
xlabel('(a)n--->');
subplot(3,1,2)
stem(h);ylabel('Amplitude--------->');
xlabel('(b)n--->');
subplot(3,1,3)
stem(fliplr(y));ylabel('Amplitude--------->');
xlabel('(c)n--->');

%Exp 6 DFT of the given sequence


% x=[1 2 3 4 4 3 2 1]
%enter the length of FFT 8
close all; clear all;
x=input('enter the sequence');
n=input('enter the length of FFT');
X=fft(x,n);
figure;
stem(X);ylabel('Imaginary Axis--------->');
xlabel('Real Axis--->');
X

% Exp 7 poles, zeroes and gain of transfer function


% input the numerator polynomial [ 2 3 1]
% input the denomenator polynomial 1
close all; clear all;
num= input('input the numerator polynomial:');
den=input('input the denomenator polynomial:');
tranf=tf(num,den)
[zeros poles gain]=tf2zp(num,den);
disp('poles of transfer function are:');
disp(poles);
disp('zeros of transfer function are:');
disp(zeros);
disp('gain of transfer function are:');
disp(gain);
zplane(num,den);

% Exp 8 Magnitude and phase of DFT


%input the length of DFT (for best result in powers of 2):8
close all; clear all;
length=input('input the length of DFT (for best result in powers of 2):');
theta=0:pi/length:pi;
num=[0.05 0.033 0.008];
den=[0.06 4 1];
transfer=tf(num,den)
[freq,w]=freqz(num,den,length);
grid on;
figure(1)
subplot(2,1,1)
disp(abs('freq'));
plot(abs(freq),'k');
title('magnitude response');
xlabel('frequency index');
ylabel('magnitude');
grid on;

subplot(2,1,2)
disp(angle('freq'));
plot(angle(freq),'k');
title('phase response');
xlabel('frequency index');
ylabel('phase');

grid on;

% EXP 9 FIR filter design through rectangular window


% enter the passband ripple 0.05
% enter the stopband ripple 0.04
% enter the passband frequncey 1500
% enter the stopband frequncey 2000
% enter the sampling frequncey 9000
close all; clear all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequncey');
fs=input('enter the stopband frequncey ');
f=input('enter the sampling frequncey');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=boxcar(n1);
%low pass filter
b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('(a) normalised frequency--->');
%high pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('(b) normalised frequency--->');
%band pass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('(c) normalised frequency--->');
%band stop filter
b=fir1(n,wp,'stop',y);
[h,o]=freqz(b,1,256);

m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('(d) normalised frequency--->');

%Exp 10 IIR filter design


% enter the passband ripple 0.15
% enter the stopband ripple 60
% enter the passband frequncey 1500
% enter the stopband frequncey 3000
% enter the sampling frequncey 7000
close all; clear all;
format long
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequncey');
ws=input('enter the stopband frequncey ');
fs=input('enter the sampling frequncey');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]=butter(n,wn);
[b,a]=zp2tf(z,p,k);
[b,a]=butter(n,wn,'s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);

ylabel('gain in db---->');
xlabel('(a) normalised frequency--->');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians---->');
xlabel('(b) normalised frequency--->');

Potrebbero piacerti anche