Wednesday, September 4, 2013

TITLE:  Generation of Different Basic Signals Using Matlab 

Software Used: Matlab Version 7.6.0

Initial Command

clc; %clear command window
close all;% close all opened window
clear all; %clear all the previously stored values

Generation of Impulse Sequence

continuous time impulse sequence

N = 50; % the variablel N is given a value to be used for the size of t and n
t = -N:1:N; % range of t extends from -N to N
x = zeros(1,length(t)); % an array x is taken such that it has a row of zeroes eqal to the length of t
x(1,51) = 1; % 51st element of the array is taken as 1, that lies at t =0.
figure(1)
subplot(2,1,1) %
plot(t,x,'r') % the continuous unit step funtion plotted with red colored line
xlabel('Time'); %labelling of x-axis
xlabel('Amplitude'); % labelling of y-axis
title('continuous time unit impulse sequence'); % giving title to the graph

% discrete time impulse sequence
n = -N:1:N; % range of N extends from -N to N with a gap of 1 between them
xn = zeros(1,length(n)); % an array is taken such that it has a row of zeroes equal to the lenght of sample 'n'
xn(1,51) = 1; % 51st sample is taken as 1 which is at n=0
subplot(2,1,2)
stem(n,xn); % discrete stem plot of the impulse sequence
xlabel('discrete samples'); %labelling x-axis
ylabel('Amplitude'); % labelling y-axis
title('discrete time unit impulse sequence'); % title to the graph



Inference:

Unit Impulse function is a function which is zero at all other places except at 0. The function was realized using the matlab for both the continuous and discrete time domain plot. The graph in both the cases had same properties except for the fact that one was discrete and the other continuous.

Generation of Unit Step Sequence

continuous time unit step sequence

x = ones(1,length(t)); % an array x is taken such that it has a row of ones eqal to the length of t
x(1,1:51) = 0; % 51st sample is taken as 0 which is at t=0
figure(2)
subplot(2,1,1)
plot(t,x, 'r'); %plotting of the continuous unit step sequence with red color
xlabel('Time'); % labelling of x-axis
xlabel('Amplitude'); %labelling y-axis
title('continuous time unit step sequence'); % title to the graph

% continuous time unit step sequence
xn = ones(1,length(t)); % an array is taken such that it has a row of 0nes equal to the lenght of sample 'n'
xn(1,1:51) = 0; % 51st sample is taken as 0 which is at n=0
subplot(2,1,2)
stem(n,xn); % discrete plot of the unit step sequence
xlabel('discrete samples'); %labelling x-axis
ylabel('Amplitude'); % labelling y-axis
title('discrete time unit step sequence'); % title to the graph



Inference:

Unit Step function has value 0 for all the negative arument and one for the positive argument. This function was implemented successfully using the matlab code for both the continuous time and discrete time domain.

Generation of ramp function

continuous time ramp function

t = 0:0.1:N; % time interval for the ramp function choosen from 0 to N with a interval of 0.1
m = 1; %slope of the ramp function
x = m*t; % equation depicting ramp function
figure(3)
subplot(2,1,1)
plot(t,x); % continuous plotting of ramp function
xlabel('time'); %labelling x-axis
ylabel('Amplitude'); % labelling y-axis
title('continuous time ramp function') % title to the graph

% discrete time ramp function
n =0:1:N; % samples for the discrete time ramp function from 0 to N.
xn = m*n; % equation depicting discrete time ramp function
subplot(2,1,2)
stem(n,xn); % discrete plot
xlabel('discrete samples'); % labelling x-axis
ylabel('Amplitude'); % labelling y-axis
title('Discrete time ramp function') % title of the graph



Inference:

Ramp funtion can be represented by a simple linear equation passing through the origin. Its value is always zero in negative x-axis. The equation was successfully represented and plotted in the matlab in both
 continuous time and discrete time domain.

Generation of Sinusoidal Function

continuous time sinusoidal function

t = 0:0.01:1; % time range for the sinusoidal function
x = sin(2*pi*5*t); % equation depicting sinusoidal signal
figure(4)
subplot(2,1,1)
plot(t,x); % continuous plot of signal x with respect to t.
xlabel('time');% labelling x-axis
ylabel('Amplitude'); %labelling y-axis
title('continuous time sinusoidal function') % title of the graph

% discrete time sinusoidal function
n = 0:0.01:1; % number of samples for the sinusoidal wave
figure(4)
xn = sin(2*pi*5*n); % equation depicting discrete sinusoidal equation
subplot(2,1,2);
stem(n,xn); % discrete plot of the sine wave
xlabel('discrete samples'); % labelling x-axis
ylabel('amplitude'); % labelling y-axis
title('discrete time sinusoidal function'); %title to the graph



Inference:

Sinusoidal  sine waves were also successfully coded in continuous and discrete time domain using matlab and the graphs were obtained. The behaviour of the graph was as expected

Generation of exponential signal

continuous time exponential function

a = 2; %coeffficient of exponential function
t = 0:0.01:2; % time range for exponential funtion
x =exp(a*t); % equation depicting exponential function
figure(5)
subplot(2,1,1)
plot(t,x) % continuous plot of exponential funtion
xlabel('time'); % labelling x-axis
ylabel('amplitude') % labelling y-axis
title('continuous exponential function'); % title to the graph

% discrete time exponential function
a = 2; %coeffficient of exponential function
x =exp(a*t);% equation depicting exponential function
figure(5)
subplot(2,1,2)
stem(t,x) % discrete plot of the exponential function
xlabel('time'); % labelling x-axis
ylabel('amplitude') % labelling y-axis
title('discrete time exponential function'); % title to the graph



Inference:

Exponential signals were also represented in discrete and continuous time domain using matlab code. The behavior of the graphs obtained was as expected.The above graph was obtained for positive exponential functiom and the same code can generate the negative exponential function by simply changing the coefficient of exponential funtion to some negative value.

Generation of Triangular wave

continuous triangular wave generation

y = 0:0.1:1; % the amplitude of the triangular wave limited between 0 and 1.
figure(6)
subplot(2,1,1)
for i = 0:3  % for loop implemented for the first half of the ramp signal in triangular wave
    x = y +(2*i); % generalized equation found using two point formula for the positive ramp of the triangular wave
    plot(x,y) % plotting the graph for the above generalized equation
  hold on % the plotted value of x and y is kept on hold
end % end of for loop
for i = 1:3 % for loop implemented for the second half of the ramp signal in triangular wave

    x = (2*i)-y;  % generalized equation found using two point formula for the negative ramp of the triangular wave
    plot(x,y) %plotting the graph for the above generalized equation
    hold on; % the plotted value of x and y is kept on hold
end % end of for loop
xlabel('time'); % labelling x-axis
ylabel('amplitude'); % labelling y-axis
title('Continuous triangular wave signal') % title of the graph
hold off; % the hold is removed.

% discrete triangular wave generation
y = 0:0.1:1; % the amplitude of the triangular wave limited between 0 and 1.
figure(6)
subplot(2,1,2)
for i = 0:3  % for loop implemented for the first half of the ramp signal in triangular wave
    x = y +(2*i); % generalized equation found using two point formula for the positive ramp of the triangular wave
   stem(x,y) % discrete plotting the graph for the above generalized equation
  hold on % the plotted value of x and y is kept on hold
end % end of for loop
for i = 1:3 % for loop implemented for the second half of the ramp signal in triangular wave

    x = (2*i)-y;  % generalized equation found using two point formula for the negative ramp of the triangular wave
    stem(x,y) %discrete plotting the graph for the above generalized equation
    hold on; % the plotted value of x and y is kept on hold
end % end of for loop
xlabel('time'); % labelling x-axis
ylabel('amplitude'); % labelling y-axis
title('Discrete triangular wave signal') % title of the graph
hold off; % the hold is removed.



Inference:

Triangular wave was also obtained using the matlab code. To obtain the graph for triangular wave, for loop was extensively used. The behaviour of the graph was as expected. Discrete plot was also obtained using the stem function.

Generation of sawtooth wave

sawtooth wave generation

figure(7)
subplot(2,1,1)
y = 0:1; % the amplitude of the sawtooth wave limited between 0 and 1
for i = 0:5 %  for loop implemented for the first half of the ramp signal in sawtooth wave
    x = y -i; % generalized equation for the positive ramp of the sawtooth wave.
    plot(x,y) % plotting of the above generalized equation
    hold on; % the values of x and y and the plot is kept on hold
end % end of for loop
x = -4:1:1; % value of x-axis limited between -4 and 1
for j = 0:0.001:1; % for loop implemented for the other half of the sawtooth wave
    y = j; % all the value of j between 0 and 1 is assigned as y with a small interval of 0.001
    plot(x,y); % plotting of the graph of x and y to obtain a straight line connecting the ramp to the x-axis
    hold on; % the plotted values ar kept on hold
end % end of for loop
xlabel('time'); %labelling x-axis
ylabel('amplitude'); % labelling y-axis
title('Continuous sawtooth wave signal'); % title of the graph
hold off; % the hold is removed

figure(7)
subplot(2,1,2)
y = 0:0.1:1; % the amplitude of the sawtooth wave limited between 0 and 1
for i = 0:5 %  for loop implemented for the first half of the ramp signal in sawtooth wave
    x = y -i; % generalized equation for the positive ramp of the sawtooth wave.
    stem(x,y) % discrete plotting of the above generalized equation
    hold on; % the values of x and y and the plot is kept on hold
end % end of for loop
x = -4:1:1; % value of x-axis limited between -4 and 1
for j = ones(length(x)); % for loop implemented for the other half of the sawtooth wave
    y = j; % all the value of j between 0 and 1 is assigned as y with a small interval of 0.001
    stem(x,y); % discrete plotting of the graph of x and y to obtain a straight line connecting the ramp to the x-axis
    hold on; % the plotted values ar kept on hold
end % end of for loop
xlabel('time'); %labelling x-axis
ylabel('amplitude'); % labelling y-axis
title(' Discrete sawtooth wave signal'); % title of the graph
hold off; % the hold is removed



Inference:

Sawttooth wave obtained using the matlab coding was as expected. Limiting of the value of amplitude to calculate the time period was used here as in the triangualr wave above.

Generation of square wave

continuous square wave

m = 0:0.001:1; % variable m assigned value from 0 to 1 with a intrval of 0.001
figure(8)
subplot(2,1,1)
for i = 0:1:10; % for loop implemented to assign the value of the square wave funtion at x = 0 to 10 with a interval of 1
    x = i;
    y = m; % amplitude assigned with a value increasing from 0 to 1.
    plot(x,y); % continous plot of x and y
    hold on; % the plotted value is kept on hold
end % end of foor loop

for j = 0:2:10;  % another for loop implemented to assign the maximum value to the square wave at fixed time intervals
    x = j + m; % the square wave function from 0 to 1, 2 to 3, 4 to 5 and so on taken into consideration
    y = 1; % functional value at those points assigned as one
    plot(x,y) % obtained value of y and x is plotted
    hold on; % value kept on hold for further use
end % end of for loop
for k = 1:2:10; %for loop implemented to assign the minimum value to the sqare wave at fixed time intervals
    x = k + m; %the square wave function from 1 to 2, 3 to 4, 5 to 6 and so on taken into consideration
    a = 0; % functional value at those point assigned as zero
    plot(x,a) %plot of x and y is done
    hold on; % obtained plot is kept on hold
end % end of for loop
hold off; % hold is called off
xlabel('time'); % labelling of x-axis
ylabel('amplitude'); % labelling of y-axis
title('Continuous square wave signal') % title to the graph
axis ([-5 15 -0.5 1.5]); % axis of the plot is fixed

% Discrete Square Wave
m = 0:0.2:1; % variable m assigned value from 0 to 1 with a intrval of 0.001
figure(8)
subplot(2,1,2)
for j = 0:2:10;  % another for loop implemented to assign the maximum value to the square wave at fixed time intervals
    x = j + m; % the square wave function from 0 to 1, 2 to 3, 4 to 5 and so on taken into consideration
    y = ones(length(x)); % functional value at those points assigned as one
    stem(x,y) % obtained value of y and x is discrete plotted
    hold on; % value kept on hold for further use
end % end of for loop
for k = 1:2:10; %for loop implemented to assign the minimum value to the sqare wave at fixed time intervals
    x = k + m; %the square wave function from 1 to 2, 3 to 4, 5 to 6 and so on taken into consideration
    a = zeros(length(x)); % functional value at those point assigned as zero
    stem(x,a) % discrete plot of x and y is done
    hold on; % obtained plot is kept on hold
end % end of for loop
hold off; % hold is called off
xlabel('time'); % labelling of x-axis
ylabel('amplitude'); % labelling of y-axis
title('Discrete square wave signal') % title to the graph
axis ([-5 15 -0.5 1.5]); % axis of the plot is fixed



Inference:

square waves are periodic in nature whose amplitude varies between two fixed values and the time period in each value is equal. Sqaure wave was obtained just as explained by the defination using the matlab code. For loop was used to achieve the wave.Similarly Square wave was also obtained in discrete time, using the stem function.



1 comment:

Anonymous said...

nice work...
keep it up.