CSE 432 Fall 2019 Lab 4

October 15, 2019

Task 1

Generation of unit impulse function.

close all
clear
clc

fs=10;
a=1;

t=-5:1/fs:5;

impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=a;
    end
end

figure
plot(t,impl)
ylim([0 2])
figure
stem(t,impl)

Task 2

Generation of unit Ramp function.

close all
clear
clc

fs=10;
a=1;

t=-5:1/fs:5;

rmp=zeros(1,length(t));
for i=1:length(t)
    if t(i)>=0
        rmp(i)=t(i);
    end
end

figure
plot(t,rmp)
figure
stem(t,rmp)

Task 3

Generation of unit step and unit ramp function using unit impulse function.

close all
clear
clc

fs=10;
a=1;

t=-5:1/fs:5;

impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=a;
    end
end

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

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

figure;
stem(t,stp);
figure;
stem(t,rmp);

Task 4

Advanced plotting functionalities.

close all
clear
clc

fs=10;
a=1;

t=-5:1/fs:5;

impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=a;
    end
end

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

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

% figure;
% stem(t,impl);
% figure;
% stem(t,stp);
% figure;
% stem(t,rmp);

figure 
subplot 311  %1st number represents no of Rows. 2nd number represents no of cols and 3rd no represents index of the plot
stem(t,impl);
title('Impulse Signal');
ylabel('Amplitude');
xlabel('Time');
subplot 312
stem(t,stp);
title('Step function');
ylabel('Amplitude');
xlabel('Time');
subplot 313
stem(t,rmp);
title('Ramp function');
ylabel('Amplitude');
xlabel('Time');


figure
plot(t,rmp,'-.R')
figure
plot(t,stp,'--G')

Task 5

Generating different function using shifting of unit impulse function.

close all
clear
clc

fs=1;
a=1;

t=-5:1/fs:5;

impl=zeros(1,length(t));
for i=1:length(t)
    if t(i)==0
        impl(i)=a;
    end
end

figure;
stem(t,impl);

y=zeros(1,length(t));
y=y+0.5*circshift(impl,[0 -2]);
y=y+2*circshift(impl,[0 -1]);
y=y+circshift(impl,[0 0]);
y=y+2*circshift(impl,[0 1]);
y=y+-1*circshift(impl,[0 2]);

%y=[0 0 0 0.5 2 0 2 -1 0 0 0];

figure
stem(t,y)

Homework

  • Plotting multiple graphs in a single figure with different colors, and line-style. legends must be added also.
    Functions: sine, cos, exponential
  • Continuous and Discrete plot of the signals shown in figures 1-4 below using shifting, multiplication and other mathematical operation of impulse, step and ramp function
    • Repeat each case with sampling frequency of 4 ,10, and 20.
Figure 1
Figure 2
Figure 3
Figure 4

 

Print Friendly, PDF & Email

Leave a Reply