You are on page 1of 2

MATLAB code for problem A (1-4):

clc; clear all; close all;


t=0:.001:.2; %very tiny increment of variable is needed to approximate
%continuous-time signal
f=10;
x=sin(2*pi*f*t); %the continuous-time signal
subplot(5,1,1), plot(t,x);
title('The Generated Signal');
%Sampling frequencies are represented by Fs
Fs1=10;
ts1=0:(1/Fs1):.2; %the sampling period is given by 1/Fs1 which is used as the
interval in time axis
xs1=sin(2*pi*f*ts1); %sampling the original signal at Fs1 Hz
subplot(5,1,3), stem(ts1,xs1);
title('Sampled at 10Hz');

Fs2=20;
ts2=0:(1/Fs2):.2; % the sampling period is 1/Fs2
xs2=sin(2*pi*f*ts2); %sampling the original signal at Fs2 Hz
subplot(4,1,4), stem(ts2,xs2);
hold on;
yi2=interp1(ts2,xs2,t);
subplot(5,1,2),plot(t,yi2,'r');
title('Sampled at 20Hz and then Interpolated');

Fs3=50;
ts3=0:(1/Fs3):.2; % the sampling period is 1/Fs3
xs3=sin(2*pi*f*ts3); %sampling the original signal at Fs3 Hz
subplot(5,1,4), stem(ts3,xs3);
title('Sampled at 50Hz');
Fs4=100;
ts4=0:(1/Fs4):.2; % the sampling period is 1/Fs4
xs4=sin(2*pi*f*ts4); %sampling the original signal at Fs4 Hz
subplot(5,1,5), stem(ts4,xs4);
title('Sampled at 100Hz');

MATLAB code for problem A(5):


clc; clear all; close all;
t=0:.001:.1;
x=sin(2*pi*10*t)+sin(2*pi*50*t)+sin(2*pi*100*t); %the continuous-time signal
plot(t,x);
title('The Generated Signal');

You might also like