DSP PRACTICAL

0

 %Practical 1

clc; 
clear all; 
close all; 
n=-10:1:10; 
L=length(n); 
for i=1:L 
% to generate a discrete time impulse function 
if n(i)==0 
x1(i)=1; 
else 
x1(i)=0; 
end; 
% to generate a discrete time unit step signal 
if n(i)>=0 
x2(i)=1; 
% to generate a discrete time ramp signal 
x3(i)=n(i); 
else 
x2(i)=0; 
x3(i)=0; 
end; 
end; 
% to generate exponential sequence 
a=0.85; 
x4=a.^n; 
figure; 
subplot(3,2,1); 
stem(n,x1); 
xlabel('discrete time n ---->'); 
ylabel('amplitude---->'); 
title('Discrete time unit impulse signal'); 
subplot(3,2,2); 
stem(n,x2);xlabel('discrete time n ---->'); 
ylabel('amplitude---->'); 
title('Unit step sequence') 
subplot(3,2,3); 
stem(n,x3); 
xlabel('discrete time n ---->'); 
ylabel('amplitude---->'); 
title(' Unit ramp sequence'); 
subplot(3,2,4); 
stem(n,x4);xlabel('discrete time n ---->'); 
ylabel('amplitude---->'); 
title('discrete time exponential signal'); 
% to generate a discrete time signum function 
a=sign(n); 
subplot(3,2,[5,6]); 
stem(n,a); 
xlabel('discrete time n ------>'); 
ylabel('amplitude ---->'); 
title('discrete time signum function'); 
% to generate a discrete time sinc function 
Ts=.2; 
n=-30:1:30; 
t=n*Ts 
Wn=sinc(t); 
figure; 
stem(n,Wn); 
xlabel('discrete time n ------->'); 
ylabel('amplitude ---->'); 
title('discrete time sinc function');















%practical 2
clc; 
t=0:0.025:1; 
A=1;f1=1;f2=2; 
s1=A*sin(2*pi*f1*t); 
s2=A*sin(2*pi*f2*t); 
fprintf('\n 1.operations on continuous time signals \n'); 
fprintf('\n 2.operations on discrete time signals \n'); 
ch=input('\n \n enter your choice :'); 
switch ch 
case 1 
figure 
subplot(5,2,1); 
plot(t,s1); 
grid; 
title('original signal with frequency 1'); 
xlabel('time t'); 
ylabel('amplitude'); 
subplot(5,2,2); 
plot(t,s2); 
grid; 
title('original signal with frequency2'); 
xlabel('time t'); 
ylabel('amplitude'); 
subplot(5,2,3); 
plot(t,s1+s2); %Signals and Systems Lab 
grid; 
xlabel('time t'); 
ylabel('amplitude'); 
title('sum of 2 signals'); 
subplot(5,2,4); 
plot(t,s1.*s2); 
grid; 
xlabel('time t'); 
ylabel('amplitude'); 
title('multiplication of s1 and s2'); 
p=t+0.2; 
subplot(5,2,5); 
plot(p,s1); 
axis([0 1.3 -1 1]); 
grid; 
xlabel('time t'); 
ylabel('amplitude'); 
title('time delayed signal'); 
p=t-0.2; 
subplot(5,2,6); 
plot(p,s1); 
axis([-0.3 1 -1 1]); 
grid; 
xlabel('time t'); 
ylabel('amplitude'); 
title('time advanced signal'); 
p=t/2; 
subplot(5,2,7); 
plot(p,s1); 
grid; 
%axis([0 10 -1 1]); 
xlabel('time t'); 
ylabel('amplitude'); 
title('compressed signal'); 
p=2*t; 
subplot(5,2,8); 
plot(p,s1); 
%axis([0 10 -1 1]); 
grid; 
xlabel('time t'); 
ylabel('amplitude'); 
title('expanded signal'); 
p=-1*t; 
subplot(5,2,9); 
plot(p,s1); 
grid; 
ylabel('amplitude'); 
title('reflected signal'); 
subplot(5,2,10); 
plot(t, 3*s1); 
axis([0 1 -4 4]); 
grid; 
xlabel('time'); 
ylabel('amplitude'); 
title('amplitude scaled signal'); 
%sx=s1.^2;sx 
%syms sx t; 
%zx=int(sx,t);zx 
case 2 
n=-10:1:10; 
l=length(n); 
f1=0.1; 
f2=0.125; 
x1=sin(2*pi*f1*n); 
x2=sin(2*pi*f2*n); 
figure; 
subplot(4,2,1); 
stem(n,x1); 
title('discrete sine wave x1(n) with time period=10'); 
grid on; 
subplot(4,2,2); 
stem(n,x2); 
title(' discrete sine wave x2(n) with time period=8'); 
grid on; 
x3=x1+x2; 
subplot(4,2,3); 
stem(n,x3); 
title('sum of two discrete time signals'); 
grid on; 
x4=x1.*x2; 
subplot(4,2,4); 
stem(n,x4); 
title('multiplication of two discrete time signals'); 
grid on; 
no=2; 
x5=sin(2*pi*f1*(n-no)); 
subplot(4,2,5); 
stem(n,x5); 
title(' time shifted signal of x1(n)'); 
grid on;x6=fliplr(x1); 
subplot(4,2,6); 
stem(n,x6); 
title(' time folded signal of x1(n)'); 
grid on; 
x7=x2.*2; 
subplot(4,2,[7 8]); 
stem(n,x7); 
title(' amplitude scaled discrete time signal of x2(n) '); 
grid on; 
e=sum(abs(x7).^2);e 
l=length(n); 
p=e/l; 
p 
end

















%practical 3
%z transform frequency domain exp3

clc;
syms z n p; 
x=input('ENTER X(N):');
y= ztrans(x);
disp('Z TRANSFORM :');
disp(y);

p=iztrans(y);
disp(p);

nr=[4 8 0]
dr=[1 6 8]
[r,p,k]=residuez(nr,dr);
zplane(nr,dr);
title('POLES AND ZEROES');

%to enter the output 
%Enter X(n)
% z^n







%experiment no 4
%code for linear convolution 

clc;
x1=[1 2 3 4];
x2=[1 1 1 1];
%time domain
x3=x1+x2;
dft_x3=fft(x3,4)
%frequency Domain
dft_x1=fft(x1,4);
dft_x2=fft(x2,4);
z=dft_x1+dft_x2;






%EXP4 4POINT DFT
%Code 4POIT DFT and ifft

x= [1 2 3 1];
h= [4 3 2 2];
z= cconv (x, h, 4)
dft_x = fft (x, 4);
dft_h = fft (h, 4);
w= ifft (dft_x .* dft_h







%exp 5
%linear and circular convolution exp5

clc;
x=[ 1 2 3 4 ];
h=[ 1 1 1 0 ];
z1=conv(x,h);
disp('linear convolution');
disp(z1);
x1=fft(x);
h1=fft(h);
for i=1:4
z(i)=x1(i)*h1(i);
end
w=ifft(z);
disp('circular convolution');
disp(abs(w));
x=[1 2 3 4 0 0 0 0];
h=[1 1 1 0 0 0 0 0];
x1=fft(x,8);
h1=fft(h,8);
for i=1:8
 z2(i)=x1(i).*h1(i);
end
w1=ifft(z2);
disp('circular convolution usig zero padding m ethod');
disp(abs(w1));









%exp 6
N=input('Enter Order Of Filter');
fc=input('Enter cutoff    freq in hz');
fs=input('Enter sampling freq in Hz');
wc=2*fc/fs;
[b,a]=butter(N,wc);
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,abs(h));
xlabel('Normalized freq');
ylabel('abs of h');
title('Design of IIR filter using BLT');
subplot(2,1,2);
zplane(b,a);
title('pole zero plot');

%enter order of filter 5
%enter cut off frequency 1000
%enter sampling frequency 2500








%exp 7

m = input('enter interpolation and decimation factor');
N = 50;
n = 0:N-1;
x = sin(2*pi*0.04*n);
subplot(3, 1, 1);
stem(n, x (1:N));
p = 0:N/m-1;
y = decimate(x, m);
subplot(3, 1, 2);
stem(p, y(1:N/m));
q = 0:N*m-1;
z = interp(x, m);
subplot(3, 1, 3);
stem(q, z(1:N*m));

Post a Comment

0Comments
Post a Comment (0)