Anda di halaman 1dari 7

1.

Let a signal x(t) be:


x(t) = 5t+3 , -2<t<0, elsewhere
As shown above

TASKS
1. Sketch y1(t) = x(-t)
2. Sketch y2(t) = x(-5-t)
3. Sketch y2(t) = x(2+t)
4. Sketch y3(t) = x(t/2)
5. Sketch y3(t) = x(4*t)
6. Find even and odd parts of x(t) and sketch them.

TASK NO: 1
Sketch y1(t) = x(-t)

t=[-2:0.05:0];
x=5*t+3;
ft=-fliplr(t);
fv=fliplr(x);
subplot(3,2,1);
plot(t,x,'*')
ylabel('x(t)');
subplot(3,2,2);
plot(ft,fv,'*')
ylabel('x(-t)');
TASK NO: 2
Sketch y2(t) = x(-5-t)
st=ft-5;
sv=fv;
subplot(3,1,3);
plot(st,sv,'*')
ylabel('x(-5-t)');

TASK NO: 3
Sketch y2(t) = x(2+t)
t_3=2+t;
subplot(4,1,4);
plot(t,t_3,'*')
ylabel('x(2+t)');
TASK NO: 4
Sketch y3(t) = x(t/2)

t_4=t*2;
subplot(3,2,5);
plot(t,t_4,'*')
ylabel('x(t/2)');

TASK NO: 5

Sketch y3(t) = x(4*t)


t_4=t/4;
subplot(3,2,5);
plot(t,t_4,'*')
ylabel('x(t*4)');

TASK NO: 6

Find even and odd parts of x(t) and sketch them.


veven=1/2*[x fv];
subplot(7,1,6);
plot([t ft],veven,'*')
ylabel('veven(t)');
vodd=1/2*[x -fv];
subplot(7,1,7);
plot([x -fv],vodd,'*')
ylabel('vodd(t)');
Q2.Define commands “sprintf” and “fprintf” with example?
ANS:

Fprintf:
Write data to text file

Syntex
fprintf(fileID,formatSpec,A1,...,An)
fprintf(formatSpec,A1,...,An)

Description
fprintf(fileID,formatSpec,A1,...,An) applies the formatSpec to all elements of arrays A1,...An in
column order, and writes the data to a text file. fprintfuses the encoding scheme specified in
the call to fopen.
fprintf(formatSpec,A1,...,An) formats data and displays the results on the screen.
EXAMPLES:
1.To insert a single quotation mark in a string, use two single quotation marks together. For
example,
 fprintf(1,'It''s Friday.\n')

displays on the screen

 It's Friday.

2.The commands

 B = [8.8 7.7; 8800 7700]


 fprintf(1, 'X is %6.2f meters or %8.3f mm\n', 9.9, 9900, B)

display the lines

 X is 9.90 meters or 9900.000 mm


 X is 8.80 meters or 8800.000 mm
 X is 7.70 meters or 7700.000 mm
Sprintf:
Format data into string or character vector

Syntax:
[s,errmsg] = sprintf(format,A,...)

Description :
str = sprintf(formatSpec,A1,...,An) formats the data in arrays A1,...,An using the formatting
operators specified by formatSpec and returns the resulting text in str. The sprintf function
formats the values in A1,...,An in column order. If formatSpec is a string, then so is the
output str. Otherwise, str is a character vector.
EXAMPLES:

1. Successive values are printed as long as they are integers and in the range of a valid
character. The first invalid character terminates the printing for this %s specifier and is
used for a later specifier.
For example, pi terminates the string below and is printed using %f format.
 Str = [65 66 67 pi];
 sprintf('%s %f', Str)
 ans =
 ABC 3.141593

2. If the first value to print is not a valid character, then just that value is printed for
this %s specifier using an e conversion as a warning to the user. For example, pi is formatted
by %s below in exponential notation, and 65, though representing a valid character, is
formatted as fixed-point (%f).

 Str = [pi 65 66 67];


 sprintf('%s %f %s', Str)
 ans =
 3.141593e+000 65.000000 BC
Q3:Write below commands and comment on the plot obtained.
t = 0:0.0001:0.05;
x = cos(2*pi*50*t);
y = sin(2*pi*50*t);
plot3(t,x,y), xlabel('Time'), ylabel('cosine axis'),zlabel('sine axis'); % Plots 3-D curve\

COMMENT
The above graph is obtained by plotting cosine and sine wave against time. At any instant 't'
the wave has covered some distance on both the y and z axes respectively. Thus the position
vector is rotating simultaneously on both the axes y and z and forming both cosine and sine
waves thus forming a spiral like 3-d plot.

Anda mungkin juga menyukai