You are on page 1of 13

EXPERIMENT NO:1

Date : 23-06-2010

GENERATION OF VARIOUS SIGNALS

AIM : Generation of various signals


a) Sine wave
b) Square wave
c) Triangular wave

%generation of sine wave


f= input('enter the frequency');
t=linspace(1,10,100);
y=sin(2*pi*f*t);
subplot(2,2,1);
plot(t,y);
title('sine wave');
xlabel('time');
ylabel('amplitude');
%generation of square wave
f= input('enter the frequency');
duty=0.5;
t=linspace(1,10,1000);
y=square((2*pi*f*t),(duty*100));
subplot(2,2,2);
plot(t,y);
title('square wave');
xlabel('time');
ylabel('amplitude');
%generation of triangular wave
f= input('enter the frequency');
t=linspace(1,10,100);
width=0.5;

1
y=sawtooth((2*pi*f*t),(width));
subplot(2,2,3);
plot(t,y);
title('triangular wave');
xlabel('time');
ylabel('amplitude');

RESULT

enter the frequency 1


enter the frequency 1
enter the frequency 1

sine wave square wave


1 1

0.5 0.5
amplitude

amplitude

0 0

-0.5 -0.5

-1 -1
0 5 10 0 5 10
time time
triangular wave
1

0.5
amplitude

-0.5

-1
0 5 10
time

2
EXPERIMENT NO:2
Date : 30-06-2010

AM , FM AND PWM

AIM : To generate AM, FM and PWM signals.

% Amplitude modulation
clear all;clc;clf;
Ec=input('amplitude of carrier signal')'
Em=input('amplitude of modulating signal');
Fc=input('frequency of carrier signal');
Fm=input('frequency of modulating signal');
t=linspace(0,1,100);
ec=Ec*cos(Fc*t);
em=Em*cos(Fm*t);
e=(Ec+Em*cos(Fm*t)).*cos(Fc*t);
subplot(2,2,1);
plot(ec);
xlabel('time');
ylabel('amplitude');
title('carrier signal');
grid on
subplot(2,2,2);
plot(em);
xlabel('time');
ylabel('amplitude');
title('modulating signal');
grid on
subplot(2,2,3);

3
plot(e);
xlabel('time');
ylabel('amplitude');
title('modulated signal');

RESULT

amplitude of carrier signal 5


amplitude of modulating signal 1
frequency of carrier signal 75
frequency of modulating signal 20

carrier signal modulating signal


5 1

0.5
amplitude

amplitude

0 0

-0.5

-5 -1
0 50 100 0 50 100
time time
modulated signal
10

5
amplitude

-5

-10
0 50 100
time

4
% Frequency Modulation

clear all;clc;clf;
Ec=input('amplitude of carrier signal=');
Em=input('amplitude of modulating signal=');
Fc=input('frequency of carrier signal=');
Fm=input('frequency of modulating signal=');
f=input('frequency deviation=');
t=linspace(0,1,100);
ec=Ec*cos(Fc*t);
em=Em*cos(Fm*t);
e=Ec*cos((Fc*t)+((f/Fm).*sin(Fm*t)));
subplot(2,2,1);
plot(ec);
xlabel('time');
ylabel('amplitude');
title('carrier signal');
grid on
subplot(2,2,2);
plot(em,'g');
xlabel('time');
ylabel('amplitude');
title('modulating signal');
grid on
subplot(2,2,3);
plot(e,'r');
xlabel('time');
ylabel('amplitude');
title('modulated signal');

5
RESULT

amplitude of carrier signal=5


amplitude of modulating signal=1
frequency of carrier signal=75
frequency of modulating signal=20
frequency deviation=50

carrier signal modulating signal


5 1

0.5
amplitude

amplitude

0 0

-0.5

-5 -1
0 50 100 0 50 100
time time
modulated signal
5
amplitude

-5
0 50 100
time

6
%Pulse width modulation
clc;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
PWM(i)=1;
elseif (m(i)<=s(i))
PWM(i)=0;
end
end
plot(t,PWM,'b',t,m,'r',t,s,'m');
title('pulse width modulated signal');
xlabel('time');
ylabel('amplitude');

RESULT

pulse width modulated signal


1

0.8

0.6

0.4

0.2
am plitude

-0.2

-0.4

-0.6

-0.8

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time

7
EXPERIMENT NO:3
Date : 07-07-2010
LINEAR CONVOLUTION , CIRCULAR CONVOLUTION,
AND LINEAR CONVOLUTION USING CIRCULAR
CONVOLUTION

AIM : Implementation of linear convolution, circular convolution and circular


convolution using linear convolution.
%linear convolution without function
x=input('Enter first sequence');
y=input('Enter second sequence');
m=length(x);
n=length(y);m
l=max(m,n);
if l==m;
c=m-n;
v=n;
e=x;
f=y;
else
c=n-m;
v=m;
e=y;
f=x;
end;
a=fliplr(f);
g=[zeros(1,v-1),e];
s=0;
c=0;
for i=1:m+n-1;

8
h=[zeros(1,i-1),a];
p=[g,zeros(1,i-1)];
for j=1:i;
c=c+(p(j+v-1)*h(j+v-1));
end;
s(i)=c;
c=0;
end;
stem(s,'r');
xlabel('time');
ylabel('amplitude');
title('convoluted sequence');

RESULT

Enter first sequence [1 2 3]


Enter second sequence [2 3 4]

convoluted sequence
18

16

14

12
amplitude

10

0
1 1.5 2 2.5 3 3.5 4 4.5 5
time

9
%linear convolution with function

clear all;
clc;
clf;
x=input('input sequence x[n]=');
lx=input('starting time index of x[n]=');
h=input('impulse response h[n]=');
lh=input('starting time index of h[n]=');
y=conv(x,h);
n=lx+lh:length(y)+lx+lh-1;
stem(n,y);
title(‘convoluted sequence’);
ylabel('amplitude');
xlabel('time index');

RESULT

input sequence x[n]=[1 2 3]


starting time index of x[n]=-2
impulse response h[n]=[2 3 4]
starting time index of h[n]=-2

10
convoluted sequence
18

16

14

12

amplitude
10

0
-4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0
time index

%Circular convolution without function


clc;
clf;clear all;
x=input('enter the sequence x[n]=');
h=input('enter the sequence h[n]=');
N1=length(x);
N2=length(h);
N=max(N1,N2);
x=[x zeros(1,N-N1)];
h=[h zeros(1,N-N2)];
for n=0:N-1
y(n+1)=0;
for i=0:N-1
j=mod(n-i,N);
y(n+1)=y(n+1)+x(i+1)*h(j+1);
end;
end;
stem(y);

11
title('circular convolution');
xlabel('time index');
ylabel('amplitude');

RESULT
enter the sequence x[n]=[1 2 3]
enter the sequence h[n]=[2 3 4]
circular convolution
20

18

16

14

12
amplitude

10

0
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
time index

%linear convolution using circular convolution

clc;
clf;clear all;
a=input('enter the sequence x[n]=');
b=input('enter the sequence h[n]=');
na=length(a);
nb=length(b);
c=[a zeros(1,nb-1)];
d=[b zeros(1,na-1)];
N1=length(c);
N2=length(d);
N=max(N1,N2);

12
c=[c zeros(1,N-N1)];
d=[d zeros(1,N-N2)];
for n=0:N-1
y(n+1)=0;
for i=0:N-1
j=mod(n-i,N);
y(n+1)=y(n+1)+c(i+1)*d(j+1);
end;
end;
stem(y);
title('linear convolution using circular convolution');
xlabel('time index');
ylabel('amplitude');

RESULT

enter the sequence x[n]=[1 2 3]


enter the sequence h[n]=[2 3 4]
linear convolution using circular convolution
18

16

14

12
amplitude

10

0
1 1.5 2 2.5 3 3.5 4 4.5 5
time index

13

You might also like