Tuesday 26 December 2017

Signals And Wave Form Generation Using MTLAB

Signals: All the signals have to be either vectors (row or column), or matrices in MATLAB of
finite length. The index of the vector usually corresponds to time, and it always has to be 1 to N, if
N is assumed to be the length of the vector. MATLAB has the power to perform vector operations
quite efficiently, implying that processing of signals is easy.
As a general rule, discrete signals are viewed using ‘stem’ and indices must be plotted on the axis.
It’s always a good habit to label all the axes and title the figures properly.
Common basic signals are
▪ Discrete – Time signals:
▪ Unit impulse sequence.
▪ Unit step sequence.
▪ Unit ramp sequence.
▪ Sinusoidal sequence. .
▪ Exponential sequence. x(n) = A an, where A and a are constant.
▪ Continuous – time signals:
▪ Unit impulse signal.
▪ Unit step signal.
▪ Unit ramp signal.
▪ Sinusoidal signal. .
▪ Exponential signal. , where A and a are constant.
6. Procedure for Signal generation:
1. Start the program
2. Get the inputs for signal generation
3. Use the appropriate library function
4. Display the waveform
Source code:
%WAVE FORM GENERATION
%CT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
t1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
plot(t1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
t2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
plot(t2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
t3=-10:1:20;
x3=exp(-1*a*t3);
subplot(2,3,3);
plot(t3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
t4=-10:1:20;
x4=t4;
subplot(2,3,4);
plot(t4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
t5=-10:1:20;
x5=A*sin(2*pi*f*t5);
subplot(2,3,5);
plot(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
t6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
plot(t6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');
%WAVE FORM GENERATION
%DT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
n1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
stem(n1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
n2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
stem(n2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
n3=-10:1:20;
x3=power(a,n3);
subplot(2,3,3);
stem(n3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
n4=-10:1:20;
x4=n4;
subplot(2,3,4);
stem(n4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
n5=-10:1:20;
x5=A*sin(2*pi*f*n5);
subplot(2,3,5);
stem(n5,x5);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
n6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
stem(n6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');
Output Waveform (Discrete Time)
Problem 1: Creation of Signals
a) We will often need the functions for these general signals:
• a unit impulse: δ(n-n0) of desired length
• a unit step: u(n-n0) of desired length
• shifter: a function which gives the input signal an arbitrary shift of n0
b) Generate the following signals in MATLAB:
x1[n] = 2 δ(n + 2) - δ(n-4), -5 ≤ n ≤ 5
x2[n] = n(u[n] – u[n-10]) + 10 exp(-0.3(n-10)) (u[n-10]-u[n-20]) 0 ≤ n ≤ 20
x3[n] = cos(0.04πn) + 0.02w[n], for 0 ≤ n ≤ 50,
where w[n] is a gaussian random signal
x4[n] is signal of four periods of sequence [5,4,3,2,1], in the range -10 ≤ n ≤ 9
c) Sinusoids--- the most general category of signals. Yes, it’s true. Believe it or not, every signal in this universe contains nothing but sinusoids. We’ll explore this aspect in detail in our later labs, but for now, these signals are quite interesting and beautiful to be looked in detail.
x1[n] = sin (
17
π
n), 0 ≤ n ≤ 25
x2[n] = cos (17πn), -15 ≤ n ≤ 15
x3[n] = sin (3 π n), -10 ≤ n ≤ 10
x4[n] = cos (23πn), 0 ≤ n ≤ 50
See the figures for each of the signals and comment about each with the aspect of even and odd, periodic and aperiodic etc. Can you think of representing x3[n] without trigonometric functions?
We would be dealing with sinusoids quite frequently in future. It’s a good idea if we can understand the mathematics of a sinusoidal signal and write a general function for it.
(i) Write a function to generate a sinusoid of given specifications: it should take six parameters: Freq, Amplitude, Initial Phase, Sampling Freq., Start-Time, Stop Time.
(ii) Generate: s(t) = 50cos(2pi*1200*t + pi/4), using the above function.
If you are done with the simple practice session, Change the start and stop time in the above function to generate a cosine which appears to be a sine.
(iii) Complex Exponentials: Generate x0[n] = exp(j*n/3), for some range and see its
real and imaginary parts separately. Also make the following signals:
• x1[n] = e(-0.1+j0.3)n, -10 ≤ n ≤ 10
• x2[n] = an u[n], where a=0.9, and 1.1 for -50 ≤ n ≤ 100
• x3[n] = 3 sin (17πn) + j 4 cos (17πn), 0 ≤ n ≤ 25
You may like to listen to these sinusoids, or some of these. Use MATLAB’s ‘sound’ to play your signal at the sound card. What’s ‘fs’ in this sound? Explore ‘wavread’, ‘wavwrite’ also, and try to understand the phenomenon involved. Play some sinusoids of audible frequency range. What happens if we use our functions double, half, fliplr etc before playing the sinusoid?
Summary: This lab gives a tutorial about generating different continuous and discrete time signals in MATLAB.
Instructions:
1. Do it yourself.
2. Attach Extra sheets for the problems which should include the code and its results screen shots.
3. Submit it before leaving until been specified by teacher
4. After marking, these will be deposited with teacher for record.

0 comments:

Post a Comment