[go: up one dir, main page]

0% found this document useful (0 votes)
157 views14 pages

DSP Lab 1: To Simulate The Generation of Continuous Time and Discrete Time Signals

The document describes a MATLAB code that simulates various continuous and discrete time signals. It allows the user to generate sine, cosine, unit impulse, unit step, ramp, and exponential signals. It also defines two custom signals and plots their continuous and discrete time representations. The code takes user input to select the desired signal type and format. It uses functions like unit_step and ramp to define the custom signals.

Uploaded by

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

DSP Lab 1: To Simulate The Generation of Continuous Time and Discrete Time Signals

The document describes a MATLAB code that simulates various continuous and discrete time signals. It allows the user to generate sine, cosine, unit impulse, unit step, ramp, and exponential signals. It also defines two custom signals and plots their continuous and discrete time representations. The code takes user input to select the desired signal type and format. It uses functions like unit_step and ramp to define the custom signals.

Uploaded by

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

DSP LAB 1

Aim: To Simulate the Generation of Continuous Time and Discrete Time


Signals.

Software: MATLAB

Group Number 1:
1. Omkar Bhilare 191060901
2. Omkar Sargar 181060047
3. Om Fuke 181060046
4. Lukesh Ankamwar 181060038

Code:
clc;
clear all;
x =[-40:.01:40];
no = input('Enter the wave you want\n1 : Sine Wave \n2 : Cos
Wave\n3 : Unit Impulse Function\n4 : Unit Step Function\n5 :
Ramp function\n6 : Exponential function\n');

switch no
case 1
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
amp = input("Enter the amplitude of the signal: ");
fc = input("Enter the frequency of the signal: ");
y = amp*sin(2*pi*x*1/fc);
%subplot(2,1,1);
if z ==1
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Sine Signal');
elseif z ==2
stem(x,y);grid on;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Sine Signal');
else
display("Wrong input for type of signal");
end

case 2
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
amp = input("Enter the amplitude of the signal: ");
fc = input("Enter the frequency of the signal: ");
y = amp*cos(2*pi*x*1/fc);
if z ==1
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Cos Signal');
elseif z ==2
stem(x,y);grid on;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Cos Signal');
else
display("Wrong input for type of signal");
end

case 3

N=15;
x=-N:1:N;
y=[zeros(1,N),ones(1,1),zeros(1,N)];
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
if z ==1
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Unit Impulse Signal ');
elseif z ==2
stem(x,y);grid on ;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Unit Impulse Signal');
else
display("Wrong input for type of signal");
end
case 4
N=20;
x=0:1:N-1;
y=ones(1,N);
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
if z ==1
plot(x,y); grid on;
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Unit Impulse Signal');
elseif z ==2
stem(x,y);grid on;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Unit Impulse Signal');
else
display("Wrong input for type of signal");
end

case 5
N=20;
x=-N:1:N-1;
amp = input("Enter the amplitude of the signal: ");
y=amp*x.*[x>=0];
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
if z ==1
plot(x,y); grid on;
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Unit Ramp Signal');
elseif z ==2
stem(x,y);grid on;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Unit Ramp Signal');
else
display("Wrong input for type of signal");
end
case 6
N=10;
x=0:0.5:N;
amp = input("Enter the amplitude of the signal: ");
y=exp(amp*x);
z = input('Input the type of signal\n1 : Continuous
\n2 : Discrete\n');
if z ==1
plot(x,y); grid on;
plot(x,y); grid on;
plot(x,y);grid on;
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Exponential Signal');
elseif z ==2
stem(x,y);grid on;
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Exponential Signal');
else
display("Wrong input for type of signal");
end

otherwise
disp('Wrong input');
end

%%
clc;
clear all;
t = -5:0.01:5;
t1 = -5:0.1:5;

Graph1_continuous = unit_step(t)+unit_step(t-1)-unit_step(t-
2)-unit_step(t-3);
Graph1_discrete = unit_step(t1)+unit_step(t1-1)-unit_step(t1-
2)-unit_step(t1-3);

z = input('Input the type of signal\n1 : Continuous \n2 :


Discrete\n');
if z==1
plot(t, Graph1_continuous)
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Time Customized Signal 1');
else if z ==2
stem(t1, Graph1_discrete)
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Time Customized Signal 1');
end
end

%%
clc;
clear all;
t = -5:0.01:5;
t1 = -5:0.1:5;

Graph2_continuous = -unit_step(t+3) +
2*unit_step(t+2)+ramp(t+1)-...
2*ramp(t)+ramp(t-1)-2*unit_step(t-2)+unit_step(t-3);
Graph2_discrete = -unit_step(t1+3) +
2*unit_step(t1+2)+ramp(t1+1)-...
2*ramp(t1)+ramp(t1-1)-2*unit_step(t1-2)+unit_step(t1-3);
z = input('Input the type of signal\n1 : Continuous \n2 :
Discrete\n');
if z==1
plot(t, Graph2_continuous)
xlabel('Time t');
ylabel('x(t)');
grid on;
title('Continuous Time Customized Signal 2');
ylim([-3,3])
else if z ==2
stem(t1, Graph2_discrete)
xlabel('Time n');
ylabel('x[n]');
grid on;
title('Discrete Time Customized Signal 2');
ylim([-3,3])
end
end

function out = unit_step(t)


x1 = 1;
x0 = 0;
out = x1.*(t>=0) + x0.*(t<0);
end

function out = ramp(t)


x1=t;
x0=0;
out = x1.*(t>=0) + x0.*(t<0);
end
Outputs:
Conclusion: Continuous Time and Discrete Time Signals were simulated in
MATLAB successfully. The code written is capable of simulating sine, cosine
unit impulse, unit step, ramp and exponential signals both in continuous and
discrete time. Also, custom signals can also be simulated.

You might also like