CSE 432 Spring 2019 Lab 4

February 18, 2019

Task 1

Plotting a Unit Impulse Function

% Unit Impulse function
close all
clear
clc

a=1;   %Defining amplitude
fs=1;

t=-10:1/fs:10;
impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=1;
    else
        impl(i)=0;
    end
end

figure ;
stem(t,impl)

Task 2

Plotting a Unit Ramp Function

 % Unit ramp function
close all
clear
clc 

a=1;   %Defining amplitude
fs=1;

t=-10:1/fs:10;
rmp=zeros(1,length(t));
for i=1:length(t)
    if t(i)>=0
        rmp(i)=t(i);
    else
        rmp(i)=0;
    end
end

figure ;
stem(t,rmp)

Task 3

Unit Step and Ramp function using Unit Impulse function

% Unit Step and Ramp function using Unit Impulse function
close all
clear
clc

a=1;   %Defining amplitude
fs=1;

t=-10:1/fs:10;
impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=1;
    else
        impl(i)=0;
    end
end

figure;
stem(t,impl);
%y=circshift(impl,[0 1]);

stp=zeros(1,length(t));
for i=0:max(t)
    y=circshift(impl,[0 i]);
    stp=stp+y;
end
figure ;
stem(t,stp)

rmp=zeros(1,length(t));
for i=0:max(t)
    y=circshift(impl,[0 i]);
    rmp=rmp+i*y;
end
figure ;
stem(t,rmp)

Task 4

More details on Plotting

% Unit Step and Ramp function using Unit Impulse function
close all
clear
clc

a=1;   %Defining amplitude
fs=1;

t=-10:1/fs:10;
impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=1;
    else
        impl(i)=0;
    end
end

figure;
subplot 131
stem(t,impl);
title('Impulse Function');
xlabel('Time');
ylabel('Aplitude');

stp=zeros(1,length(t));
for i=0:max(t)
    y=circshift(impl,[0 i]);
    stp=stp+y;
end

subplot 132
stem(t,stp)
title('Step Function');
xlabel('Time');
ylabel('Aplitude');

rmp=zeros(1,length(t));
for i=0:max(t)
    y=circshift(impl,[0 i]);
    rmp=rmp+i*y;
end

subplot 133
stem(t,rmp)
title('Ramp Function');
xlabel('Time');
ylabel('Aplitude');

figure

plot(t,stp,'--r')

Task 5

Different functions using Shifting of Unit Impulse function

%Different functions using Shifting of Unit Impulse function
close all
clear
clc

a=1;   %Defining amplitude
fs=1;

x=[4 -2 3 2 0 2 -1 2 1 2 0];

t=-floor(length(x)/2):1/fs:floor(length(x)/2);
impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=1;
    else
        impl(i)=0;
    end
end

func=zeros(1,length(t));

for i=1:length(t)
    y=circshift(impl,[0, t(i)]);
    func=func+x(i)*y;
end
    

figure;
subplot 211
stem(x)
subplot 212
stem(t,func);
%y=circshift(impl,[0 1]);

Homework

  • Plotting multiple graphs in a single figure with different colors and legends. Functions: sine, cos, exponential
  • Discrete plot (Stem) several functions into 1 figure.

Submit your homework here

Leave a Reply