0% found this document useful (0 votes)
71 views

11.instructional Manual Sample Program Output

Uploaded by

Hayyan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

11.instructional Manual Sample Program Output

Uploaded by

Hayyan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

JSPM

NARHE TECHNICAL CAMPUS,NARHE

DEPARTMENT OF ELECTRONICS & TELECOMMUNICATION ENGINEERING

Lab Conduction Report


Class: T.E.(E & TC) Subject: DSP

Prerequisite Practical (MATLAB)


Aim:
Generation of various basic signals like unit impulse, unit step, ramp, exponential,
sinusoidal and cosine sequence using MATLAB

% Program for the generation of unit impulse signal


clc;
clear all;
close all;
t = 2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];subplot(2,2,1);
stem(t,y);
ylabel(‘Amplitude --.’);
xlabel(‘(a) n --.’);
% Program for the generation of unit step sequence [u(n)2 u(n 2 N]
N=input(‘enter the N value’);
T=0:1:n-1;
y1=ones(1,n);
subplot(2,2,2);
stem(t,y1);
ylabel(‘Amplitude --.’);
xlabel(‘(b) n --.’);
% Program for the generation of ramp sequence
n1=input(‘enter the length of ramp sequence’);
t=0:n1;
subplot(2,2,3);
stem(t,t);
ylabel(‘Amplitude --.’);
xlabel(‘(c) n --.’);

% Program for the generation of exponential sequence


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 --.’);
% Program for the generation of sine sequence
t=0:.01:pi;
y=sin(2*pi*t);
figure(2);
subplot(2,1,1);plot(t,y);
ylabel(‘Amplitude --.’);
xlabel(‘(a) n --.’);

% Program for the generation of cosine sequence


t=0:.01:pi;
y=cos(2*pi*t);
subplot(2,1,2);
plot(t,y);
ylabel(‘Amplitude --.’);

xlabel(‘(b) n --.’);

Command window input:


enter the N value 7
enter the length of ramp sequence 7
enter the length of exponential sequence 7
enter the a value 1

Output:
Practical 1:

Aim:
To verify the sampling theorem and aliasing effects with various sampling
frequencies.

Algorithm:
1. Take modulating frequency Fm
2. Take amplitude A
3. Plot modulating signal x
4. Take sampling frequency Fs such that Fs>2Fm
5. Plot this sampled signal as Y1
6. Take sampling frequency Fs such that Fs=2Fm
7. Plot this sampled signal as Y2
8. Take sampling frequency Fs such that Fs<2Fm
9. Plot this sampled signal as Y3
10. Observe aliasing effect which occurs at Fs<2Fm

MATLAB program:
clc;
close all;
clear all;
disp('sampling Theorem and observe aliasing effect')
Fm=input('Enter the modulating frequency Fm='); % print original
modulating signal
A=input('Enter the amplitude A=');
t=0:0.1:10;
x=A*sin(2*3.14*Fm*t);
subplot(2,2,1);
plot(t,x);
title('Modulating signal');
xlabel('Time');
ylabel('Amplitude');
Fs1=input('Enter the sampling frequency Fs1(Fs>2Fm)='); % print
oversampled discret signal
n=0:0.2:5;
y1=A*sin(2*3.14*Fm*n/Fs1);
subplot(2,2,2);
stem(n,y1);
title('Fs>=2Fm');
xlabel('n');
ylabel('Amplitude');
Fs2=input('Enter the sampling frequency Fs2(Fs=2Fm)=='); % print sampled
discrete signal
n=0:0.2:5;
y2=A*sin(2*3.14*Fm*n/Fs2);
subplot(2,2,3);
stem(n,y2);
title('Fs=2Fm');
xlabel('n');
ylabel('Amplitude');
Fs3=input('Enter the sampling frequency Fs3(Fs<2Fm)=='); % print sampled
discrete signal
n=0:0.2:5;
y3=A*sin(2*3.14*Fm*n/Fs3);
subplot(2,2,4);
stem(n,y2);
title('Fs<2Fm');
xlabel('n');
ylabel('Amplitude');

Output:

Practical: 2
Aim:
Write a programs to study and verify DFT properties
Algorithm:
1. Take input sequence
2. Obtain its DFT using traditional formula method (use for loop for k and n)
3. Plot magnitude response (use ‘abs’)
4. Plot phase response (use ‘angle’)
5. Obtain inverse IDFT using formula method

Program:
clc;
close all;
clear all;
xn=input('Enter the input sequence=');
ln=length(xn);
xk=zeros(1,ln);
ixk=zeros(1,ln);

%obtain DFT
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
end
end
t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel('amplitude');
xlabel('time index');
title('input sequence');

%magnitude plot
magnitude=abs(xk);
t=0:ln-1;
subplot(222);
stem(t,magnitude);
ylabel('amplitude');
xlabel('k');
title('magnitude responce');

%phase responce
phase=angle(xk);
t=0:ln-1;
subplot(223);
stem(t,phase);
title('phase responce');
% inverse DFT
ixk=ixk./ln;
t=0:ln-1;
subplot(224);
stem(t,xn);
ylabel('amplitude');
xlabel('time index');
title('input sequence obtained after DFT and IDFT');

output:

Practical : 3
Aim:
Write a program to find 4 point circular convolution and compare the result with 8
point circular convolution to study aliasing effect in time domain

Algorithm:
1. Take input sequence x
2. Take input sequence h
3. Find length of input sequence x=N1
4. Find length of input sequence h=N2
5. Take number of point of DFT=N
6. Pad necessary number of zeros in both sequence to make it equal to length N
7. Calculate samples using circular convolution
8. Plot sequence x
9. Plot sequence h
10. Plot circular convolution

Program:
% Program for Computing Circular Convolution with zero padding
clc;
close all;
clear all;
x=input('enter the first sequence(length should be 4 or less than
4),x=');
h=input('enter the 2nd sequence (length should be 4 or less than
4),h=');
N1=length(x);
N2=length(h);
N=input('enter the no. of DFT points(4 or 8),N=');
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
y=zeros(1,N);

for m=0:1:N-1
for n=0:1:N-1
k1=(m-n);
k=mod(k1,N);
y(m+1)=y(m+1)+x(n+1)*h(k+1);
end
end
%plot sequences

n1=0:1:N-1;
subplot(311);
stem(n1,x);
title('first sequence,x');
xlabel('samples');
ylabel('magnitude');
subplot(312); stem(n1,h);
title('second sequence,h');
xlabel('samples'); ylabel('magnitude');

subplot(313); stem(n1,y);
disp('output sequence,y=');
disp(y);
title('circular convolution,y');
xlabel('samples');ylabel('magnitude');

Output for N=4

Output for N=8


Practical 4:
Aim:
(a) To find Z and inverse Z transform and pole zero plot of Z-transfer
function.
(b)To solve the difference equation and find the system response using Z
transform.

Flowchart
(a) pole zero plot of Z-transfer function
1. Take numerator coefficient
2. Take denominator coefficient
3. Calculate poles and zeros
4. Display poles and zeros
5. Plot pole zeros on Z plane

Program:
clc;
clear all;
close all;
%enter the numerator and dinominator coeff. in square brackets
num=input('num coeff=');
den=input('den coeff=');
H=filt(num,den);
z=zero(H);
disp('zero are at');
disp(z);
[r p k]=residuez(num,den);
disp('poles are at');
disp(p);
zplane(num,den);
title('pole zero plot of LTI system in Z plane');

output
Flowchart
(b) Z Transform
1. Take x(n) input signal
2. Calculate its Z transform
3. Display x(Z)
4. Simplify it if required

% Z trnasform of given sequences

clc;
clear all;
close all;
syms a n;
% Z trnasform of xn=1^n
xn=1^n;
Xz=ztrans(xn);
disp('x(n)=');
pretty(xn);
disp('X(z)=');
pretty(Xz);

% Z trnasform of xn=a^n
xn=a^n;
Xz=ztrans(xn);
disp('x(n)=');
pretty(xn);
disp('X(z)=');
pretty(Xz);
disp('X(z)=');
pretty(simplify(Xz));
Output:

Flowchart
(c) Inverse Z Transform
1. Take x(n) as input signl
2. Find its Z transform
3. Display x(n0 and X(z)
4. Calculate its inverse Z transform
5. Display x(n)
6. Simplify it if required

% Invert Z transform of x(n)=(1/2)^n+ (-1/3)^n)


clc;
clear all;
close all;
syms n;
xn=(1/2)^n+ (-1/3)^n;
Xz=ztrans(xn);
disp('x(n)=');
pretty(xn);
disp('X(z)=');
pretty(Xz);
% inverse Z trnasform
disp('X(z)=');
[rXz,how]=simple(Xz);
disp('X(z)=');
pretty(simplify(Xz));

B) solve difference equation and find system response (using C)

PROGRAM FOR DIFFERENCE EQUATION:-

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

void main()

clrscr();

printf("\tIMPLEMENTATION OF GENERAL DIFFERENCE EQN. BASED ON ARRAY MAPPING\n\n");


int a[10],b[10],sumc,sumd;

int x[10],y[10],N,M,L,k,n;

printf("\nenter the no. of coeff. a");

scanf("\n%d",&N);

printf("\nenter the coeff.");

for(k=1;k<=N;k++)

scanf("%d",&a[k]);

printf("\nenter the no. of coeff. b");

scanf("\n%d",&M);

printf("\nenter the coeff.");

for(k=0;k<M;k++)

scanf("%d",&b[k]);

printf("\nenter the no. of samples");

scanf("%d",&L);

printf("\nenter the samples");

for(k=0;k<L;k++)

scanf("%d",&x[k]);

for(k=0;k<L;k++)

printf("\n%d",x[k]);

printf("\noutput sequence is:");

for(n=0;n<L;n++)

sumc=0;

sumd=0;

for(k=1;(k<=n)&&(k<=N);k++)
{ sumc+=a[k]*y[n-k]; }

for(k=0;(k<=n)&&(k<M);k++)

{ sumd+=b[k]*x[n-k]; }

y[n]=-sumc+sumd;

printf("\ny[%d]=%d",n,y[n]);

getch();

OUTPUT:-

IMPLEMENTATION OF GENERAL DIFFERENCE EQN. BASED ON ARRAY MAPPING

enter the no. of coeff. a2

enter the coeff.2 1

enter the no. of coeff. b2

enter the coeff.1 1

enter the no. of samples2

enter the samples1 1

output sequence is:

y[0]=1

y[1]=0

Practical 5:
Aim:
To plot the poles and zeros of a transfer function when the coefficients of the
transfer function are given, study stability of different transfer functions.
%stability test
clc;
clear all;
close all;
num=input('enter the numerator coefficients of the filter');
den=input('enter the denominator coefficients of the filter');
H=filt(num,den);
z=zero(H);
disp('zeros are at ');
disp(z);
[r p k]=residuez(num,den);
disp('poles are at ');
disp(p);

zplane(num,den);
title('pole sero map of LTI system in Z plane');
if (p<=1)

disp('stable system');
else
disp('Non-stable system');
end
Practical 6:
Aim:
To study the effect of different windows on FIR filter response and see the effect
on the filter response.

Algorithm:
1. Declare n-order of filter, Fp-passband frquency, Fs-stopband frequency
2. Compute fn-normalized frequency
3. Calculate n+1 filter coefficients using various window functions to for Low Pass Filter.
4. Calculate frequency response vector h and the corresponding angular frequency vector w for
the digital filter for length n;
5. Calculate magnitude and phase response using frequency response vector h.
6. Plot magnitude and phase response for all window functions.

Programme:
clc;
clear all;
close all;
n=1000;
fp=300;
fs=1000;
fn=2*fp/fs;
%recatlgular window
window= rectwin(n+1);
b=fir1(n,fn,'low', window);
[h,w]=freqz(b,1,128);
figure (1);
subplot(411);
plot(w/pi,abs(h));
xlabel('normalized frequency');
ylabel('gain');
title('magnitude responce of LPF-reactangular window');
subplot(412);
plot(w/pi,angle(h));
xlabel('normalized frequency');
ylabel('angle');
title('phase responce of LPF-reactangular window');

%hamming window
window= hamming(n+1);
b=fir1(n,fn,'low', window);
[h,w]=freqz(b,1,128);
subplot(413);
plot(w/pi,abs(h));

xlabel('normalized frequency');
ylabel('gain');
title('magnitude responce of LPF-Hamming window');
subplot(414);
plot(w/pi,angle(h));
xlabel('normalized frequency');
ylabel('angle');
title('phase responce of LPF-Hamming window');

%hanning window
window= hanning(n+1);
b=fir1(n,fn,'low', window);
[h,w]=freqz(b,1,128);
figure (2);
subplot(411);
plot(w/pi,abs(h));
xlabel('normalized frequency');
ylabel('gain');
title('magnitude responce of LPF-Hanning window');
subplot(412);
plot(w/pi,angle(h));
xlabel('normalized frequency');
ylabel('angle');
title('phase responce of LPF-Hanning window');

%triangular window
window= triang(n+1);
b=fir1(n,fn,'low', window);
[h,w]=freqz(b,1,128);
subplot(413);
plot(w/pi,abs(h));
xlabel('normalized frequency');
ylabel('gain');
title('magnitude responce of LPF-Traingular window');
subplot(414);
plot(w/pi,angle(h));
xlabel('normalized frequency');
ylabel('angle');
title('phase responce of LPF-Traingular window');

OUTPUT:
Practical 7:
Aim:
Design Butterworth filter using Bilinear transformation method for LPF and
write a program to draw the frequency response of the filter.

Algorithm:
1. Take passband edge frequency in rad/sec
2. Take stopband edge frequency in rad/sec
3. Take passband ripple in db=
4. Take stopband ripple in db=
5. Take sampling frequency
6. Calculate order of filter using Butterworth Approximation
7. Compute coefficient using bilinear transformation method.

%Design Butterworth filter using Bilinear transformation


%method for LPF and write a program
%to draw the frequency response of the filter.
clc;
close all;
clear all;
wp=input('passband edge frequency in rad/sec=');
ws=input('stopband edge frequency in rad/sec=');
Ap=input('passband ripple in db=');
As=input('stopband ripple in db=');
fs=input('sampling frequency=');
[N wn]=buttord(wp,ws,Ap,As,'s');
disp('order of filter is N=');
disp(N)
[num, den]=butter(N,wn,'s')
[b, a]=bilinear(num,den,fs)
freqz(b,a,512,fs)

Output:
Practical 8:
Aim:
Design and implement two stage sampling rate converter.
Algorithm:

1.take input signal


y=3.*cos(2*pi*50.*t/200)+1.*cos(2*pi*100.*t/200)
2.plot this signal
3. decimate this signal using function decimate
4. interpolate this decimated signal using function interp
5. plot both signals.

%Generate the input sequence for Fs5200Hz, f1550Hz and f25100 Hz


clc;
clear all;
close all;
t=0:1/200:10;
y=3.*cos(2*pi*50.*t/200)+1.*cos(2*pi*100.*t/200);
figure(1)
stem(y);
xlabel('Times in Seconds');
ylabel('Amplitude');
%Generate the decimated and interpolated signals
figure(2)
stem(decimate(y,20));
xlabel('Times in Seconds');
ylabel('Amplitude');
figure(3)
stem(interp(decimate(y,20),2));
xlabel('Times in Seconds');
ylabel('Amplitude');
Output:
Second Program:

clc;
close all;
clear all;
fm = 10;
Fs = 140; % sampling frequency
t = 0:1/Fs:0.5; % time range for the input sequence
x = sin(2*pi*fm*t); % input sinusoidal signal
figure(1)
subplot(4,1,1)
stem(x);
xlabel('No. of samples');
ylabel('Amplitude');
title('input discrete sinusoidal sequence');
M = 2; % factor by which the input sequence is decimated
xd = decimate(x,M);
subplot(4,1,2)
stem(xd)
xlabel('No. of samples');
ylabel('Amplitude');
title('Decimated Sinusoidal Sequence');
L = 2; % factor by which the input sequence is interpolated
xI = interp(x,L);
subplot(4,1,3);
stem(xI);
xlabel('No. of samples');
ylabel('Amplitude');
title('Interpolated Sinuoidal Sequence')
L = 2; % coefficient by which the singal is interpolated
xI = interp(xd,L);
subplot(4,1,4)
stem(xI);
xlabel('No. of samples');
ylabel('Amplitude');
title('Original Signal Obtained After Interpolating the Decimated Signal');

Output:
Design Experiment:
Aim:
Computation of FFT for given function/ user defined function using inbuilt function and with pout using
inbuilt function

USING INBUILT FUNCTION

n = 0:6;
x = [4 6 2 1 7 4 8]; % function is given
a = fft(x);
mag = abs(a);
pha = angle(a);
subplot(2,1,1);
plot(mag);
grid on
title('Magnitude Response');
subplot(2,1,2);
plot(pha);
grid on
title('phase Response');

OUTPUT:
N-POINT FFT WITHOUT USING INBUILT FUNCTION OF USER DEFINED FUNCTION
clear all;
close all;
clc;
x=input('Enter the sequence x[n]= ');
N=input('Enter the value N point= ');
L=length(x);
x_n=[x,zeros(1,N-L)];
for i=1:N
for j=1:N
temp=-2*pi*(i-1)*(j-1)/N;
DFT_mat(i,j)=exp(complex(0,temp));
end
end
X_k=DFT_mat*x_n';
disp('N point DFT is X[k] = ');
disp(X_k);
mag=abs(X_k);
phase=angle(X_k)*180/pi;
subplot(2,1,1);
stem(mag);
xlabel('frequency index k');
ylabel('Magnitude of X[k]');
axis([0 N+1 -2 max(mag)+2]);
subplot(2,1,2);
stem(phase);
xlabel('frequency index k');
ylabel('Phase of X[k]');
axis([0 N+1 -180 180]);

Output:
For user defined sequence :
clc;
clear all;
close all;
tic;
x=input('enter the sequence');
n=input('enter the length of fft'); %compute fft
disp('fourier transformed signal');
X=fft(x,n)
subplot(1,2,1);stem(x); title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
subplot(1,2,2);stem(X);
title('fft of i/p x(n) is:');
xlabel('Real axis --->');
ylabel('Imaginary axis -->');grid;
OUTPUT:-
enter the sequence[1 .25 .3 4]
enter the length of fft4
fourier transformed signal

You might also like