Professional Documents
Culture Documents
File DSP2
File DSP2
DSP Kit
Serial no. Program Date Remarks
INDEX
MATLAB
Serial no. Program Date Remarks
1 WAP for amplitude scaling of a signal and sequence 2/AUG/2019
2 WAP to generate odd and even part of a signal 5/AUG/2019
3 WAP to generate sine cardinal signal 5/AUG/2019
4 WAP to perform time reversal of a signal & 5/AUG/2019
sequence
5 WAP to perform convolution of two signals 7/AUG/2019
6 WAP to add and multiply two sequences 5/AUG/2019
7 WAP to add and multiply two signals 5/AUG/2019
8 WAP to generate Unit step and unit impulse 5/AUG/2019
functions
9 WAP to find real and imaginary part of a complex 5/AUG/2019
number.
10 WAP to generate sine and square wave 5/AUG/2019
1
Aim : WRITE A PROGRAMM for addition and subtraction of two 32 bit no.
Code :
Output :
Output :
2
Aim : WRITE A PROGRAMM to find sum of first ‘n’ natural numbers.
Code :
Output :
3
Output :
Output :
4
Aim : WRITE A PROGRAMM to generate a square wave.
Code :
Output :
5
Aim : WRITE A PROGRAMM to generate a sine wave.
Code :
Output :
6
Aim : WRITE A PROGRAMM to generate a ramp wave.
Code :
Output :
7
Aim : WRITE A PROGRAMM to generate a amplitude modulated wave.
Code :
Output :
8
Aim : WRITE A PROGRAMM to divide 2=two nos. using 2’s compliment method.
Code :
#include<stdio.h>
void main()
{
int divs,divd,q,r,temp;
printf("\nEnter divisor: ");
scanf("%d",&divs);
temp = divs;
divs = ~divs + 1;
printf("\nEnter divident: ");
scanf("%d",&divd);
r = divd;
for(q=0;r >= temp;q++)
{
r += divs;
}
printf("\n%d / %d = %d",divd,temp,q);
printf("\n%d mod %d = %d",divd,temp,r);
}
Output :
9
Aim : WAP for amplitude scaling of a signal and sequence.
Code :
X = linspace(0,2*pi,100)';
a=input('enter scaling factor ');
Y = [cos(X), a.*cos(X)];
subplot(2,1,1)
stem(Y)
title('Amplitude scaling of a sequence');
xlabel('x -->');
ylabel('cos(x) , a*cos(x)')
subplot(2,1,2)
plot(Y,'--')
title('Amplitude scaling of a signal');
xlabel('x -->');
ylabel('cos(x) , a*cos(x)')
Input :
Output :
10
Aim : WAP to generate odd and even part of a signal.
Code :
clc;
syms x
y(x)= piecewise(x<-20, 20, -20<x<20, x, x>20, 20);
subplot(3,1,1)
fplot(y(x),[-50 50]);
title('Subplot 1: Function')
xlabel('x --->');
ylabel('y(x)');
oy=(y(x)-y(-x))/2;
subplot(3,1,2)
fplot(oy,[-50 50]);
title('Subplot 2: odd part of function ')
xlabel('x --->');
ylabel('odd y(x)');
ey=(y(x)+y(-x))/2;
subplot(3,1,3)
fplot(ey,[-50 50]);
title('Subplot 3: even part of function)')
xlabel('x --->');
ylabel('even y(x)');
Output :
Ps: ‘fplot’ is a function to plot y(x) over default interval of [-5,5] and here it is used instead of plot to define
limits of x-axis.
11
Aim : WAP to generate Sine Cardinal (Sinc) function.
Code :
clc;
syms x
y(x)= piecewise(x==0,1,sin(x)/x);
fplot (y,[-30 30])
title('sine cardinal');
xlabel('x --->')
ylabel('Sinc')
Output :
Ps: Sine cardinal function is defined as 1 for x=0 a=nd sin(x)/x for every other value of x.
12
Aim : WAP to perform time reversal of a signal.
Code :
clc;
x=linspace(-5,5,100);
y=sin(x);
subplot(2,2,1)
plot(x,y); title('orignal siggnal'); grid on;
xlabel('x -->'); ylabel('Sin (x)')
subplot(2,2,2)
y=sin(-x);
plot(x,y); title('time reversed signal'); grid on;
xlabel('x -->')
x=linspace(-5,5,100);
subplot(2,2,3)
y=sin(x);
stem(x,y); title('orignal sequence');
xlabel('n -->'); ylabel('Sin [x]')
grid on;
subplot(2,2,4)
y=sin(-x);
stem(x,y); title('time reversed sequence'); grid on;
xlabel('n -->')
Output :
13
Aim : WAP to perform convolution of 2 signals.
Code :
clc;
t=-pi:0.01:pi;
a=exp(t);
b=cos(t);
subplot(3,1,1)
plot(t,a)
title('Signal-1'); xlabel('time -->'); ylabel('exp(t)');
subplot(3,1,2)
plot(t,b)
title('Signal-2'); xlabel('time -->'); ylabel('cos (t)')
c=conv(a,b);
subplot(3,1,3)
plot(c)
title('Convoluted signal') ;
Output :
14
Aim : WAP toad and multiply two sequences.
Code :
clc;
x=1:100;
y1(x)=20+(x-1)*2;
y2(x)=100+(x-1)*-4;
subplot(4,1,1)
stem(x,y1); title('sequence 1');
xlabel('x -->');
subplot(4,1,2)
stem(x,y2); title('sequence 2');
xlabel('x -->');
subplot(4,1,3)
y3=y1+y2;
stem(x,y3); title('sequence 1 + Sequence 2');
xlabel('x -->');
subplot(4,1,4)
y4=y1.*y2;
stem(x,y4); title('sequence 1 * sequence 2');
xlabel('x -->'
Output :
15
Aim : WAP to add and multiply two signals.
Code :
clc;
x=linspace(-100,100,300);
y1=10*sin(x);
y2=x;
subplot(4,1,1)
plot(x,y1); title('signal 1');
xlabel('x -->'); ylabel('10*sin(x)')
subplot(4,1,2)
plot(x,y2); title('signal 2');
xlabel('x -->'); ylabel('x')
subplot(4,1,3)
y3=y1+y2;
plot(x,y3); title('signal 1 + signal 2');
xlabel('x -->');
subplot(4,1,4)
y4=y1.*y2;
plot(x,y4); title('signal 1 * signal 2');
xlabel('x -->');
Output :
16
Aim : WAP to generate unit step and unit impulse signals.
Code :
clc;
syms x
subplot(2,1,1)
y= piecewise(x<=0,0,1);
Output :
17
Aim : WAP to find real and imaginary part of a complex number.
Code :
clc;
a= input('Enter complex no. \n');
Real_part =real(a)
Imaginary_part =imag(a)
Output :
18
Aim : WAP to generate square and sine wave.
Code :
%sine and square wave
clc;
t=(-15:.1:15);
x=sin(t);
x1=square(t);
subplot(2,1,1)
plot(t,x)
title('sine wave')
xlabel('x -->');
subplot(2,1,2)
plot(t,x1)
title('square wave')
xlabel('x -->');
Output :
19
20