Question

PLEASE USE MAT LAB ONLY. THANK YOU

(a) Create and plot the signals listed below and save your Matlab code in a script file.

i) Cosine signal of frequency 100 Hz over the range [0,0.1] seconds and samples spaced 10^- 4 seconds apart with a phase of pi/2 and an amplitude of 1.

PLEASE USE MAT LAB ONLY. THANK YOU

ii) A square wave that oscillates between 0 and 1 every five samples, plot 3 periods of the waveform.

iii) x(t) = 3 * e-2*t *u(t) over the range [-1,3] with a sampling frequency of 0.1 sec.

(b) Plotting Sunspots Load the Matlab data file, sunspot.dat, and experiment with making plots and subplots. The file is a simple 288 row by 2 column matrix where the first column has consecutive years from 1700 until 1987 and the second column has the mean sunspot number for that year. Then we will construct year and spots vectors from the two columns and plot spots as a function of year.

load sunspot.dat;

year = sunspot(:,1); %puts year data in a vector

spots = sunspot(:,2); %puts spot data in a vector plot(year,spots); This gives a 2-D plot displayed as a solid blue line going through the points.To add point markers, add a third string argument, e.g., 'r*' for data points being displayed as red asterisks. There is a toggle for getting a new plot (hold off) and for superimposing on an existing plot (hold on). hold on; plot(year,spots, 'r*') xlabel("Year") ylabel("Number of Spots") title("Sunspots vs. Time")

For the exercise, create a subplot grid of (3,1) (3 plots arranged vertically). The plots should be a stem plot, an area plot, and a line plot. Each plot should be labeled on the x and y axes.

Answer #1

a) i)

**MATLAB Program:**

%the range [0,0.1] seconds and samples spaced 0.0001
seconds

t=0:0.0001:0.1

f=100 %frequency =100Hz

A=1 %Amplitude =1

p=pi/2 %phase =pi/2

x=A*cos(2*pi*f*t+p)

plot(t,x)

title('cosine signal of frequency 100Hz')

xlabel('t')

ylabel('x(t)')

Plot:

ii)

t = linspace(-pi,2*pi,150);

x = (1+square(2*t))./2

plot(10*t/pi,x)

xlabel('t ')

grid on

title('square waveform')

plot:

iii)

%x(t) = 3 * e-2*t *u(t)

t=-1:0.1:3%%x(t) over the range [-1,3] with a sampling frequency of
0.1 sec

u=(t>=0) % Define unit step function u(t) =1 for t>=0

x=3*exp(-2*t).*u

plot(t,x)

title('x(t) = 3 * e-2*t *u(t)')

xlabel('t')

ylabel('x(t)')

Plot:

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 8 minutes ago

asked 17 minutes ago

asked 17 minutes ago

asked 17 minutes ago

asked 22 minutes ago

asked 35 minutes ago

asked 45 minutes ago

asked 50 minutes ago

asked 52 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago