File Digital Signal Processing
File Digital Signal Processing
MATLAB
Programming File
B.Sc.(H)Electronics
SNO PROGRAM
.
1. DTFT of X[N]=(0.5)^N.U[N] using DTFT Formula.
ROLL.NO.:9043/18
PROGRAM:01
AIM: Write a Program to find DTFT of x[N]= 0.5^NU[N] using
DTFT Formula
CODE:
OUTPUT:
NAME:Jasvinder kour
ROLL.NO.:9043/18
PROGRAM:02
AIM: Write a Program to find DTFT of x[N]= 0.5^NU[N] using
frequency function.
CODE:
OUTPUT:
ROLL.NO.:9043/18
PROGRAM:03
AIM: Write a Program to to plot the frequency response of a
system
CODE:
OUTPUT:
PROGRAM:04
AIM: PROGRAM TO FIND DTFT OF COSINE FUNCTIONS.
PROGRAM:
%Program to find DTFT of Cosine Function
w = -pi:0.1:pi;
N = 0:2:5;
Xn = cos(pi*N/4);
Xw = Xn*exp(-i*N'*w);
abs(Xw); %Magnitude
angle(Xw); %Phase
real(Xw); %Real Part
imag(Xw); %Imaginary Part
subplot(2,2,1);
plot(w,abs(Xw));
grid on;
xlabel('\omega');
ylabel('Magnitude');
subplot(2,2,2);
plot(w,angle(Xw));
grid on;
xlabel('\omega');
ylabel('Magnitude');
subplot(2,2,3);
plot(w,real(Xw));
grid on;
xlabel('\omega');
ylabel('Real');
subplot(2,2,4);
plot(w,imag(Xw));
grid on;
xlabel('\omega');
ylabel('Imaginary');
OUTPUT:
CALCULATIONS:
Formula used –
For Real: (𝝎) = 1 + 0.707(cos 𝝎 − 𝑗. sin 𝝎) − 0.707(cos 𝟑𝝎 − 𝑗. sin 𝟑𝝎)
− (cos 𝟒𝝎 − 𝑗. sin 𝟒𝝎) − 0.707(cos 𝟓𝝎 − 𝑗. sin 𝟓𝝎)
For Real: (𝝎) = 1 + 0.707(cos 𝝎 − cos 𝟑𝝎 − cos 𝟓𝝎) − cos 𝟒𝝎
For Imaginary: (𝝎) = 0.707(sin 𝟑𝝎 + sin 𝟓𝝎 − sin 𝝎) + 𝑗. sin 𝟒𝝎
Calculating Phase –
𝒕𝒂𝒏−𝟏 = 𝒃 /𝒂
Calculating Magnitude –
Magnitude 𝒃 𝟐
PROGRAM:05
AIM: WRITE A PROGRAM TO PLOT FREQUENCY RESPONSE OF A GIVEN
ANALOG SIGNAL.
PROGRAM:
%Program to plot Frequency Response of an Analog
Signal
Fs = 8000;
N = 1000;
n = 0:N-1;
Xn = cos(2000*pi*n/Fs);
Xw = exp((-i*2*pi/N)*n'*n);
Xk = Xn*Xw;
Xf = abs(Xk)/N;
f = n*Fs/N;
subplot(2,1,1);
plot(f,Xf);
grid on;
xlabel('Frequency');
ylabel('Normalized Magnitude');
subplot(2,1,2);
plot(f(1:N/2+1),Xf(1:N/2+1));
grid on;
xlabel('Frequency');
ylabel('Normalized Magnitude');
CALCULATIONS:
X(t)=2*cos(2000*pi*t)
Sampling rate, Fs=8000Hz;
Frequency resolution , F=8Hz;
Number of data points , N=FsF =1000.
Now,
X(k) = ∑(n=0,N-1) x[n]*exp(-i*wo*kn) , { where, wo=2piN and k=0,1,…,N-1}
OUTPUT:
PROGRAM:06
AIM: WRITE A PROGRAM TO PLOT N-POINT DFT AND IDFT USING IN-BUILT
FUNCTION.
PROGRAM:
%DFT and IDFT using matlab functions
clc;
close all;
clear all;
x=input('Please enter the sequence x(n)=');
N=input('Please enter the length of the DFT N=');
X=fft(x,N);
n=0:length(x)-1;
subplot(311);
stem(n,x);
title('Input Sequence');
subplot(323);
n=0:length(X)-1;
stem(n,X);
disp('DFT of input sequence is ');
disp(X);
title('DFT');
subplot(324);
stem(n,abs(X));
title('Magnitude spectrum');
subplot(325);
stem(n,angle(X));
title('Phase spectrum');
xr=ifft(x,N);
subplot(326);
stem(n,abs(xr));
title('IDFT');
disp('IDFT of input sequence is ');
disp(xr);
OUTPUT:
GRAPH:
RESULT: HENCE, WE SUCCESSFULLY PLOT N-POINT DFT AND IDFT USING IN-
BUILT FUNCTION.
Name:Jasvinder kour
RollNo:9043/18
PROGRAM:07
AIM: WRITE A PROGRAM TO PLOT N-POINT DFT AND IDFT WITHOUT USING IN-BUILT FUNCTION.
PROGRAM:
clc;
clear all;
N = input('Number of DFT points = ');
xn = input('Enter the sequence xn = '); %Get the sequence from user
ln = length(xn); %find the length of the sequence
xn = [xn zeros(1,N-ln)];
xk = zeros(1,N); %initialize an array of same size as that of input
sequence
ixk = zeros(1,N); %initialize an array of same size as that of input
sequence
%code block to find the DFT of the sequence
for k = 0:N-1
for n = 0:N-1
xk(k+1) = xk(k+1)+(xn(n+1)*exp((-1i)*2*pi*k*n/N));
end
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,xn);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence ---->');
grid on;
magnitude = abs(xk); %Find the magnitudes of individual DFT points
disp('DFT Sequence = ');
disp(magnitude);
%code block to plot the DFT sequence
t = 0:N-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude ---->');
xlabel('K ---->');
title('DFT Sequence ---->');
grid on;
phase = angle(xk); %Find the phases of individual DFT points
disp('Phase = ');
disp(phase);
%code block to plot the Phase Response
t = 0:N-1;
subplot(2,2,3);
stem(t,phase);
ylabel('Phase ---->');
xlabel('K ---->');
title('Phase Response');
grid on;
% Code block to find the IDFT of the sequence
for n = 0:N-1
for k = 0:N-1
ixk(n+1) = ixk(n+1)+(xk(k+1)*exp(1i*2*pi*k*n/N));
end
end
ixk = ixk./N;
%code block to plot the IDFT sequence
t = 0:N-1;
subplot(2,2,4);
stem(t,ixk);
disp('IDFT Sequence = ');
disp(ixk);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IDFT sequence ---->');
grid on;
OUTPUT:
Phase =
0 -0.7854 -1.5708 0.7854
IDFT Sequence =
1.0000 - 0.0000i 1.0000 + 0.0000i -0.0000 + 0.0000i
0.0000 + 0.0000i
GRAPH:
RESULT: HENCE,SUCCESSFULLUY PLOT N-POINT DFT AND IDFT WITHOUT USING IN-
BUILT FUNCTION.
Name: Jasvinder kour
Roll No:9043/18
PROGRAM:08
AIM: WRITE A PROGRAM TO PLOT INPUT AND OUTPUT OF FIRST ORDER DIFFERENCE
EQUATIONS.
PROGRAM:
n = -1:10;
a = [8 -2 -1]; % left hand side of difference equation
b = [1 1 0]; % right hand side of difference equation
yi = [1 0];
xi = 0;
x=2*n;
zi = filtic(b,a,yi,xi)
y = filter(b,a,2*n,zi)
subplot(2,1,1)
plot(n,y)
xlabel('--------n----------->')
ylabel('-------Values------->')
title(' Plot of output signal y over the range from n=-1 to n=10')
subplot(2,1,2)
plot(n,x)
xlabel('--------n----------->')
ylabel('-------Values------->')
title(' Plot of input signal x over the range from n=-1 to n=10')
OUTPUT:
GRAPH:
RESULT: HENCE ,PLOT OF INPUT AND OUTPUT OF FIRST ORDER DIFFERENCE EQUATIONS
NAME: Jasvinder kour
ROLL.NO:9043/18
PRATICAL:09
AIM: To generate Impulse, Unit-Step & Ramp Function.
Impulse function
unit step function
rampfunction
CODES:
1.
Input: output:
2.
Input: output:
3.
Input: output:
ROLL.NO:9043/18
PRATICAL:10
AIM:Generation of different discrete time signals.
sine wave
cos wave
sine wave using sampling
cos wave using sampling
exponential increasing and decreasing
multiplication function
CODE:
1.
Input: output:
2.
Input: output:
3.
Input: output:
4.
Input: output:
5.
Input: output:
6.
Input: output:
PRATICAL:11
AIM: Program for Convolution of 2 signals using inbuilt function
'conv'.
CODES:
OUTPUT:
RESULT: Convolution has been successfully implemented using ‘conv’
Function.
NAME: Jasvinder kour
ROLL.NO:9043/18
PRATICAL:12
AIM: Progrgam to find convolution using for loop.
CODES:
OUTPUT:
RESULT:Hence,successfully find out convolution using for loop.
PRATICAL:13
AIM: Program to find z transform of discrete series.
CODES:
Input:
OUTPUT:
PRATICAL:14
AIM:
CODES:
Input:
OUTPUT:
RESULT: hence,successfully