Documente Academic
Documente Profesional
Documente Cultură
The if, for, switch and while statements need to terminate with an end statement.
Syntax:
while expression
statements
end
Syntax:
While <expression1>
While <expression2>
<statements>
end
end
1.2 IF LOOP
Syntax:
if expression
statements
elseif expression
statements
else
statements
end
1.3 FOR Loop:
Syntax:
For m=1:j
For n=1:k
<statements>;
end
end
1.4 SWITCH STATEMENTS:
Execute one of several groups of statements
Syntax:
switch switch_expression
case case_expression
statements
case case_expression
statements
...
otherwise
statements
end
1.5 Break:
The break statement lets you exit early from a for or a while loop.
Syntax:
while expression
statements
break expression
break
end
Example:
x = -10;
while x < 0
x = x + 2;
if x = = -2
break;
end
2. SOME FUNDAMENTAL SIGNAL SEQUENCE
2.1 UNIT STEP:
The Heaviside step function, or the unit step function, usually denoted by u, is a discontinuous
function whose value is zero for negative argument and one for positive argument
[n] = {10,,nn<0 0
Unit Impulse sequence is very important to characterize the impulse response of the system.
Mathematically an impulse sequence is represented as:
[n] = {10,,n=0
n 0
3. SINUSOIDAL SEQUENCE:
A matlab function cos (or sin) is used to generate sinusoidal sequences.
To generate x(n) = 3cos(0.1n + /3) + 2sin(0.5 n), 0<= n<=10, we will need the following
script:
n = [0:10];
x = 3*cos(0.1*pi*n+pi/3) + 2*sin(0.5*pi*n);
ACTIVITY:
Q1. Determine a value falls within a specified range using IF Else statements.
Q2. Initialize a vector A having 20 rows. Replace the values of this vector from row 5 to row 15
by this equation 5*(n-1) using For loop.
Q5. Use switch-case statements to categorize the 12 months into 3 seasons i.e
summer,spring,winter.
Q6. Implement a unit step function in MATLAB and plot it, Provide the snapshot
Q7. Implement a unit impulse sequence in MATLAB and plot it, Provide the snapshot
Q8. Provide the snapshot of the following pulses using built-in MATLAB commands.
a. Rectangular pulse
b. Saw tooth
c. Trianglular
d. Square
x = sin(2*pi*f*n) + 2*sin(2*pi*f*n)
x1 = cos(2*pi*f*n) + 2*cos(2*pi*f*n)