Professional Documents
Culture Documents
EXPERIMENT 1
GENERATION AND OPERATION ON SIGNALS
1.1. AIM
1.2. SIGNAL
1
Experiment 1 Generation and Operations on Signals
All real-world signals are continuous in nature. They are also called as Analog Signals
The x(t) represents the continuous time signal. Continuous time signals are defined at every
instant of time i.e. for every value of independent variable there exists the value for the function
or output then it is called Continuous time signals. Independent variable is not necessarily to
be time it may be anything.
2
Experiment 1 Generation and Operations on Signals
The MATLAB code to generate the sinusoidal signal with constant frequency and
phase with varying Amplitude and corresponding output is shown in fig 1.2.
%To generate Sinusoidal Signal with Varying Amplitude
clc
clear all
close all
A=[5 10 15 20]; % Amplitude Vector
t=linspace(0,1,100); % time index
F=3; % Frequency; phase=0; % Phase
for i =1:length(A)
X=A(i)*sin((2*pi*F*t)+phase);
subplot(2,2,i);
plot(t,X);
xlabel('Time');
ylabel('Amplitude');
title(['Amplitude:',num2str(A(i))]);
end
Fig 1.3. MATLAB code to generate Sinusoidal Wave with Varying Amplitude
3
Experiment 1 Generation and Operations on Signals
The MATLAB code to generate the sinusoidal signal with constant Amplitude and
phase with varying Frequency and corresponding output is shown in fig 1.3.
Fig 1.5. MATLAB code to generate Sinusoidal Wave with Varying Frequency
The MATLAB code to generate the sinusoidal signal with constant Amplitude and
Frequency with varying Phase and corresponding output is shown in fig 1.4.
4
Experiment 1 Generation and Operations on Signals
INFERENCE
From Sine wave generation using MATLAB it is observed that,
1) linspace (start, end, number of sample points) built-in function is used to generate
the time index for the specified function, therefore it takes number of sample points
between start and end value. Or lese colon operator can also be used to generate the
time index.
2) Plot function is used to plot the graph between dependent and independent variables.
3) Xlabel, ylabel and title built-in functions are used to label the x-axis, y-axis and to
give title for the plot respectively.
4) Equation 1.1. is used to generate the sinusoidal wave.
5) In which amplitude A, frequency F and phase can be varied. The result is shown in
figure 1.2, 1.3, 1.4.
e2jΩ +e−2jΩ
6) Sin wave can also be generated using 2j
The MATLAB code to generate the square waveform without and with MATLAB axis
built-in function figure 1.5 and 1.6 shows corresponding output waveforms.
Fig 1.9. MATLAB code to generate Square Wave form Without Axis Function
5
Experiment 1 Generation and Operations on Signals
Fig 1.10. MATLAB code to generate Square Wave form With Axis Function
Fig 1.11. Generation of Square waveform without Fig 1.12. Generation of Square waveform
INFERENCE
From the Square wave generation, it is observed that
1) Square(2*pi*f*t) mathematical expression with square built-in function is used to
generate square waveform.
2) Axis ([x-limit y-limit]) built-in function is used to alter the limits of x-axis and y-axis
if axis function is not used square wave form will be seen as in figure 1.5 it is no longer
a square wave therefore when axis function is used a clear square wave form is
observed in figure 1.6.
3) Other functions are as same as the functions in sinewave generation.
6
Experiment 1 Generation and Operations on Signals
Fig 1.13. MATLAB Code to generate Sawtooth Fig 1.14. Generation of Sawtooth output
waveform Waveform
The MATLAB code to generate the cosine waveform and the corresponding output
waveform is shown in figure 1.8.
Fig 1.15. MATLAB Code to generate Cosine Fig 1.16. Generation of Cosine output
waveform waveform
INFERENCE
From the Sawtooth and cosine waveform generation, it is observed that
1) Sawtooth (2*pi*f*t) mathematical expression with sawtooth built-in function is used
to generate sawtooth waveform.
2) Cos (2*pi*f*t) mathematical expression with cos built-in function is used to generate
cos waveform.
e2jΩ −e−2jΩ
3) Cosine wave can also be generated using 2j
7
Experiment 1 Generation and Operations on Signals
INFERENCE
1) There exist built-in function for generating sinhx and coshx functions like sinh(x)
and cosh(x).
2) Such many Hyperbolic functions can also be generated using MATLAB built-in
functions.
8
Experiment 1 Generation and Operations on Signals
The functional form of unit sample sequence or delta sequence is given by,
1, n = 0
( n ) = …………………………………………..(1.2)
0, n 0
(n+k) is the advanced version of (n)
(n-k) is the delayed version of (n)
Unit step sequence(u(n))
The functional form of unit step sequence u(n) is given by,
1, n 0
u[n] = ……………………………………….. (1.3)
0, n 0
The significance of unit step sequence is the generation of causal signal or unilateral
signal.
n, n 0
r[n] = …………………………………………… (1.4)
0, n 0
Exponential sequence
The mathematical expression for the exponential sequence is given by,
x(n)=e^jΩn……………………………………………… (1.5)
9
Experiment 1 Generation and Operations on Signals
The MATLAB code to generate the standard DT sequences and the corresponding
plot is shown in the figures 1.9.
INFERENCE
1) The unit sample sequence takes a value of one only when n=0
2) The unit step sequence takes a value of one for n=0 and n>0
3) The unit ramp sequence takes the value of n for n>0
4) Filled Built-in function is used to fill the colour at the value of x (n).
5) Stem function is used to plot the discrete time sequence signals in MATLAB.
10
Experiment 1 Generation and Operations on Signals
Fig 1.21. MATLAB code to Generate unit Sample Sequence from Unit Step Sequence
Fig 1.22. Generation of unit Sample Sequence from Unit step Sequence
INFERENCE
1) Subtracting the unit step sequence with shifted unit step sequence then the resulting
discrete time signal will Unit Sample Sequence.
Task 2: Generation of unit Step Sequence using Ramp Sequence
% To Generate Unit Step Sequence Using Ramp Sequence
clc
clear all
close all
n=-10:10;
x1=(n+1).*(n>=-1);
x2=n.*(n>=0);
y=x1-x2;
subplot(3,1,1),stem(n,x1,'Filled','r'),xlabel('n');
ylabel('Amplitude');title('r(n+1)');
subplot(3,1,2),stem(n,x2,'Filled','r'),xlabel('n');
ylabel('Amplitude');title('r(n)');
subplot(3,1,3),stem(n,y,'Filled','r'),xlabel('n');
ylabel('Amplitude'); title('step(n)');
Fig 1.23. MATLAB code to Generate of unit Step Sequence from Unit Ramp Sequence
11
Experiment 1 Generation and Operations on Signals
INFERENCE
1) Subtracting the unit step sequence with shifted unit step sequence then the
resulting discrete time signal will Unit Sample Sequence.
The MATLAB code to generate the standard DT Exponential sequences and the
corresponding plot is shown in the figures 1.9.
12
Experiment 1 Generation and Operations on Signals
INFERENCE
1) In Complex exponential Sequence it is observed that maximum change in frequency
will be from -1 to 1 therefore the minimum frequency will be 0 and maximum frequency
will be π.
1.5. OPERATIONS ON CONTINUOUS TIME SIGNALS
13
Experiment 1 Generation and Operations on Signals
INFERENCE
1. Soundsc built-in function is used in order to hear the sine wave as note and also to
differentiate the signals based on different frequencies.
2. And Aliasing of can also be observed Aliasing occurs When it violates Sampling theorem
i.e. fs>=2fmax.
3. Here 920Hz frequency Will be heard as 80Hz frequency because it violates the Sampling
theorem hence the heard frequency will be 1000Hz i.e. Sampling Frequency minus Signal
Frequency 1000Hz-920Hz = 80Hz.
1.5.2. THRESHOLDING
% To generate Sine Wave From Square Wave or it is to perform
Thresholding
clc
clear all
close all
A=2; F=3;
t=linspace(0,1,100);
x=A*sin(2*pi*F*t); y1=(x>=0); y2=(x<=0);
subplot(3,1,1),plot(t,x);
xlabel('time'),ylabel('Amplitude'),title('SineWave');
subplot(3,1,2),plot(t,y1);
xlabel('time'),ylabel('Amplitude'),title('Positive
Thresholding');axis([0 1 -1.5 1.5]);
subplot(3,1,3),plot(t,y2);
xlabel('time'),ylabel('Amplitude'),title('Negative
Thresholding');axis([0 1 -1.5 1.5]);
14
Experiment 1 Generation and Operations on Signals
INFERENCE
1) condition 1: y1=(x>=0) in which the input signal above zero reference output
becomes 1 and below zero reference output becomes 0
2) condition 2: y2=(x<=0) in which the input signal above zero reference output
becomes 0 and below zero reference output becomes 1
Fig 1.30. MATLAB code to Generate Full wave and Half wave rectifier
15
Experiment 1 Generation and Operations on Signals
INFERENCE
1) condition 1: abs(x) built-in function gives the absolute value of output therefore the
negative half of sine wave also becomes the positive therefore full-wave rectifier is
formed
2) condition 2: (x+ abs(x))/2 gives the output of Half-wave rectifier.
1.5.4. AMPLITUDE MODULATION
%Amplitude modulation of continuous wave without using Built-in
function
clc
clear all
close all
Ac=input('enter the Carrier Wave Signal Amplitude');
Am=input('enter the Message Wave Signal Amplitude');
Fc=input('enter the Carrier Wave Signal Frequency');
Fm=input('enter the Message Wave Signal Frequency');
m=Am/Ac; t1=input('Enter the time period');
t=linspace(0,t1,1000); y1=sin(2*pi*Fm*t); y2=sin(2*pi*Fc*t);
x=((1+m.*y1).*(Ac.*y2));
subplot(3,1,1),plot(t,y1),xlabel('time'),ylabel('Amplitude');
title('Message Signal');
subplot(3,1,2),plot(t,y2),xlabel('time'),ylabel('Amplitude');
title('Carrier Signal');
subplot(3,1,3),plot(t,x),xlabel('time'),ylabel('Amplitude');
title('Modulated Signal');
Fig 1.32. MATLAB code to Perform Amplitude Modulation
16
Experiment 1 Generation and Operations on Signals
1.6.1. FOLDING
Folding operation or time reversal is the operation of replacing the expression for time
with the negative, such that actions are reversed. The folding operation on unit ramp and unit
step sequences are done.
INFERENCE
1. Folding refers to reversing the axis here the axis of unit step and unit
ramp sequences are reversed.
2. Filplr() built-in function can also be used to reverse the x-axis.
17
Experiment 1 Generation and Operations on Signals
1.6.2. SHIFTING
The shifting operation on DT sequences moves the sequence either to the left
or right. The shift can be either advanced or delayed.
INFERENCE
Shifting means origin is shifted by the specified units either it can be
advanced or delayed here both the unit step and ramp sequences are shifted
advanced of 2 steps and delayed of 2 steps and they are implemented and plotted.
18
Experiment 1 Generation and Operations on Signals
1.6.3. SCALING
Fig 1.38. MATLAB code to perform Scaling Operation on Standard Discrete time Sequence
INFERENCE
Scaling means Amplifying the amplitude greater than one based on our
requirement. Here Sample Sequence is amplified by the factor 5 and step sequence
is amplified by the factor 6 and Ramp sequence with amplified by 2. According to that
the Amplitude is amplified respectively.
19
Experiment 1 Generation and Operations on Signals
Fig 1.40. MATLAB code to Generate 2-D signal Fig 1.41. Generation of 2-D signals
Fig 1.43. 2-D points before Taking FFT Fig 1.44. 2-D points before Taking FFT
INFERENCE: The resultant picture shows they are 2-D discrete Signals therefore it
requires 2 independent variables. It is specified as row and column. If the points in 2-
D plane are taken FFT then the result will be pure white spectrum
20
Experiment 1 Generation and Operations on Signals
Fig 1.46. Vertical line before FFT Fig 1.47. Vertical line after FFT
INFERENCE
If the vertical line in 2-D plane are taken FFT then the result will be horizontal line in
2-D plane and vice versa
RESULT
Thus, the generation and operation on continuous signals and discrete time
sequences are observed and analysed using the various built in functions of MATLAB.
21
Experiment 1 Generation and Operations on Signals
PRE-LAB QUESTIONS
1. Define signal?
❖ It is variable which either carries or contains information that is to be conveyed.
❖ It is basically a record of physical Quantity.
❖ It is function of one or more independent variable.
2. What is the difference between continuous time signal and discrete time signal?
❖ Continuous Time Signal
It is an analog representation of a natural signal. Continuous time signals
are defined at every instant of time i.e. for every value of independent variable
there exists the value for the function or output then it is called Continuous time
signals. Independent variable is not necessarily to be time it may be anything.
❖ Discrete time Signal
The discrete time signal is got by sampling the continuous time signal and
the digital signal is got by quantizing the discrete time signal. x(nt) represents the
discrete time sequence and x(n) represents the digital signal.
3. What is the difference between analog and digital frequency?
❖ Analog Frequency
❖ Digital Frequency
22
Experiment 1 Generation and Operations on Signals
Axis function is mainly used to adjust the limits of x and y axis of the plot and
the importance of axis function is discussed with MATLAB program in section 1.3.2.
When the Sampling frequency is less than twice the signal frequency
Aliasing effect will get into picture.
i.e. when It violates the Sampling theorem Fs = 2 Fmax
8. How unit step sequence can be generated from a unit ramp sequence?
U (n) = r (n+1) – r (n) this is the condition to generate unit step sequence
into unit ramp sequence.
For any value of Ω, ejΩ tells us how the system responds to an input frequency
hence Fourier transform always interrelated with frequency domain analysis i.e. the reason
why it is called basis function of Fourier transform
23