# CSE 432 Spring 2019 Lab 3

February 10, 2019

### Task 1

Plotting a Sine Graph

```% Sine curve
close all
clear
clc

fs=20; %Sampling frequency in hz. Sampling time is 1/fs
f=1; %frequency of sine wave is 30 hz
phi=-pi/4; % initial phase
w=2*pi*f; %Omega(angular velocity)
a=2; %amplitude

t=0:1/fs:2*pi;
y=a*sin(w*t+phi);

figure;
plot(t,y);
figure;
stem(t,y);

//Another way```
```% Sine curve
close all
clear
clc

fs=1; %Sampling frequency in hz. Sampling time is 1/fs
f=1; %frequency of sine wave is 30 hz
phi=-pi/4; % initial phase
w=2*pi*f; %Omega(angular velocity)

for i=0:5
fs= fs+2;
t=0:1/fs:2*pi;
y=sin(w*t+phi);

figure;
plot(t,y);

end```

### Task 2

Plotting a cosine graph

```% Cosine curve
close all
clear
clc

fs=10; %Sampling frequency in hz. Sampling time is 1/fs
f=1; %frequency of sine wave is 30 hz
phi=-pi/4; % initial phase
w=2*pi*f; %Omega(angular velocity)
a=3; %amplitude

t=0:1/fs:2*pi;
y=a*cos(w*t+phi);

figure;
plot(t,y);
figure;
stem(t,y);```

### Task 3

Combination of Sine and cosine (addition and subtraction)

```% Combination of sine and Cosine curve
close all
clear
clc

fs=100; %Sampling frequency in hz. Sampling time is 1/fs
f1=2; %frequency of sine wave is 30 hz
phi1=-pi/4; % initial phase
w1=2*pi*f1; %Omega(angular velocity)
a1=2; %amplitude

f2=3; %frequency of sine wave is 30 hz
phi2=pi/2; % initial phase
w2=2*pi*f2; %Omega(angular velocity)
a2=3; %amplitude

t=0:1/fs:2;
y1=a1*sin(w1*t+phi1);
y2=a2*cos(w2*t+phi2);
y=y1+y2;

% figure;
% plot(t,y1);
% figure;
% plot(t,y2);

figure;
plot(t,y)```

### Task 4

Plotting an exponential graph

```% Exponential curves
close all
clear
clc

fs=100; %Sampling frequency in hz. Sampling time is 1/fs
a=2; %amplitude

t=-20:1/fs:2;
y=a*exp(t);

figure;
plot(t,y);

figure;
stem(t,y);```

### Task 5

Plotting a Unit Step Function

```% Unit Step function
close all
clear
clc

fs=10; %Sampling frequency in hz. Sampling time is 1/fs
a=1; %amplitude

t=-20:1/fs:20;

y=zeros(length(t));
for i=1:length(t)
if t(i)<0
y(i)=0;
else
y(i)=a;
end
end

figure;
plot(t,y);
ylim([-1 3])

figure;
stem(t,y);```