0% found this document useful (0 votes)
18 views6 pages

Exp 6

Uploaded by

noorispoor0
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)
18 views6 pages

Exp 6

Uploaded by

noorispoor0
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/ 6

Experiment 6: Basic Operations on Signals

Objective: To learn and perform basic operations on signals in MATLAB,


including addition, subtraction, scaling, multiplication, differentiation, integra-
tion, noise addition, and various transformations.

Creating and Plotting Signals


Steps:

1. Create a time vector.


2. Generate a sine wave signal.
3. Generate a cosine wave signal.
MATLAB Code:
% Create a time vector
t = 0:0.01:2;

% Create a sine wave signal


x = sin (2* pi *5* t ) ;

% Create a cosine wave signal


y = cos (2* pi *3* t ) ;

Adding Signals
Explanation: Adding two signals combines their amplitudes at each point in
time.
Steps:
1. Add the sine and cosine wave signals.
2. Plot the resulting signal.
MATLAB Code:

1
z = x + y;
plot (t , z ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Addition of Sine and Cosine Waves ’) ;
grid on ;

Subtracting Signals
Explanation: Subtracting one signal from another takes the difference of their
amplitudes at each point in time.
Steps:

1. Subtract the cosine wave from the sine wave.


2. Plot the resulting signal.
MATLAB Code:
w = x - y;
plot (t , w ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Subtraction of Sine and Cosine Waves ’) ;
grid on ;

Scaling a Signal
Explanation: Multiplying a signal by a scalar changes its amplitude.
Steps:
1. Multiply the sine wave by a scalar.
2. Plot the resulting scaled signal.

MATLAB Code:
scaled_x = 2 * x ;
plot (t , scaled_x ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Scaled Sine Wave ’) ;
grid on ;

2
Element-wise Multiplication of Signals
Explanation: Element-wise multiplication multiplies corresponding elements
of two signals.
Steps:
1. Multiply the sine and cosine waves element-wise.

2. Plot the resulting signal.


MATLAB Code:
mult_signal = x .* y ;
plot (t , mult_signal ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Element - wise Multiplication of Sine and Cosine
Waves ’) ;
grid on ;

Numerical Differentiation
Explanation: Differentiation approximates the derivative of a signal.
Steps:
1. Differentiate the sine wave numerically.
2. Plot the resulting differentiated signal.
MATLAB Code:
dx = diff ( x ) / ( t (2) - t (1) ) ;
plot ( t (1: end -1) , dx ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Numerical Differentiation of Sine Wave ’) ;
grid on ;

Numerical Integration
Explanation: Integration approximates the cumulative sum of a signal.
Steps:
1. Integrate the sine wave numerically.

2. Plot the resulting integrated signal.

3
MATLAB Code:
integral_signal = cumsum ( x ) * ( t (2) - t (1) ) ;
plot (t , integral_signal ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Numerical Integration of Sine Wave ’) ;
grid on ;

Generating and Adding Noise


Explanation: Noise can be added to a signal to simulate real-world conditions.
Steps:

1. Generate random noise.


2. Add noise to the sine wave signal.
3. Plot the noisy signal.
MATLAB Code:
noise = randn ( size ( t ) ) ;
noisy_signal = x + noise ;
plot (t , noisy_signal ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Noisy Sine Wave ’) ;
grid on ;

Time Shifting a Signal


Explanation: Time shifting moves a signal in time.
Steps:

1. Calculate the shifted time vector.


2. Interpolate the original signal onto the shifted time vector.
3. Plot the original and shifted signals.
MATLAB Code:
time_shift = 0.5;
shifted_t = t - time_shift ;
shifted_signal = interp1 (t , x , shifted_t ) ;
plot (t , x , shifted_t , shifted_signal ) ;

4
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Time Shifted Sine Wave ’) ;
grid on ;

Time Scaling a Signal


Explanation: Time scaling changes the duration of a signal.
Steps:

1. Calculate the scaled time vector.


2. Interpolate the original signal onto the scaled time vector.
3. Plot the original and scaled signals.
MATLAB Code:
tim e_scal e_fact or = 2;
scaled_t = t * time _scale _facto r ;
scaled_signal = interp1 (t , x , scaled_t ) ;
plot (t , x , scaled_t , scaled_signal ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Time Scaled Sine Wave ’) ;
grid on ;

Time Inverting a Signal


Explanation: Time inversion reverses a signal in time.
Steps:

1. Invert the sine wave signal in time.


2. Plot the resulting time-inverted signal.
MATLAB Code:
t i m e _ i n v e r t e d _ s i g n a l = x ( end : -1:1) ;
plot (t , t i m e _ i n v e r t e d _ s i g n a l ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Time Inverted Sine Wave ’) ;
grid on ;

5
Amplitude Scaling a Signal
Explanation: Amplitude scaling changes the amplitude of a signal.
Steps:
1. Scale the amplitude of the sine wave.
2. Plot the resulting scaled signal.

MATLAB Code:
amplitude_scale = 2;
s c a l e d _ a m p l i t u d e _ s i g n a l = x * amplitude_scale ;
plot (t , s c a l e d _ a m p l i t u d e _ s i g n a l ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Amplitude Scaled Sine Wave ’) ;
grid on ;

Amplitude Inverting a Signal


Explanation: Amplitude inversion changes the sign of the amplitude of a
signal.
Steps:
1. Invert the amplitude of the sine wave.
2. Plot the resulting amplitude-inverted signal.
MATLAB Code:
a m p l i t u d e _ i n v e r t e d _ s i g n a l = -x ;
plot (t , a m p l i t u d e _ i n v e r t e d _ s i g n a l ) ;
xlabel ( ’ Time ’) ;
ylabel ( ’ Amplitude ’) ;
title ( ’ Amplitude Inverted Sine Wave ’) ;
grid on ;

You might also like