Experiment 1 - DSP
Experiment 1 - DSP
Results:
b. Generate discrete unit step, unit impulse, unit ramp signals and plot the same.
MATLAB Code:
clc; close all; clear all;
n = (-10:10);
u = n>=0;
i = n==0;
r = n.*u;
subplot(311); stem(n,u);
xlabel('n'); ylabel('Amplitude'); title('Unit Step');
subplot(312); stem(n,i);
xlabel('n'); ylabel('Amplitude'); title('Unit Impulse');
subplot(313); stem(n,r);
xlabel('n'); ylabel('Amplitude'); title('Unit Ramp');
Results:
Observations: In this question we observed the plots of unit step, unit ramp and unit
impulse signal in MATLAB.
c. Generate a sine wave of 100Hz, sampled at 8KHz for a duration of 20ms. Repeat the
experiment for different sampling rates like 100Hz, 200Hz, 500Hz and 1KHz and
comment on results.
MATLAB Code:
clc; clear all; close all;
f = 100;
fs1 = 8000;
t1 = 0:1/fs1:0.02;
x1 = sin(2*pi*f*t1);
fs2 = 100;
t2 = 0:1/fs2:0.02;
x2 = sin(2*pi*f*t2);
fs3 = 200;
t3 = 0:1/fs3:0.02;
x3 = sin(2*pi*f*t3);
fs4 = 500;
t4 = 0:1/fs4:0.02;
x4 = sin(2*pi*f*t4);
fs5 = 1000;
t5 = 0:1/fs5:0.02;
x5 = sin(2*pi*f*t5);
subplot(511); stem(t1,x1);
xlabel('time(sec)');
ylabel('amplitude');
title('sine wave sampled at fs = 8KHz');
subplot(512); stem(t2,x2);
xlabel('time(sec)');
ylabel('amplitude');
title('sine wave sampled at fs = 100Hz');
subplot(513); stem(t3,x3);
xlabel('time(sec)');
ylabel('amplitude');
title('sine wave sampled at fs = 200Hz');
subplot(514); stem(t4,x4);
xlabel('time(sec)');
ylabel('amplitude');
title('sine wave sampled at fs = 500Hz');
subplot(515); stem(t5,x5);
xlabel('time(sec)');
ylabel('amplitude');
title('sine wave sampled at fs = 1KHz');
Results:
Results:
Observations: In this question we observed how the sum of given signals will look like.
e. In the previously generated signal, add iid Gaussian noise with SNR of 20dB and plot the
signal. Hint: Use randn() function in MATLAB to generate noise.
MATLAB Code:
clc; clear all; close all;
fs = 5000;
as = 5;
snr_db = 20;
snr = 10^(snr_db/10);
an = as/snr;
t=0:1/fs:0.01;
x1 = as.*cos(2*pi*500*t);
x2 = as.*cos(2*pi*1200*t + 0.25*pi);
x3 = as.*cos(2*pi*1800*t + 0.5*pi);
x = x1+x2+x3;
n1 = an*randn(size(x));
n1 = n1/max(n1);
n = an*n1;
y = x + 0.5 * n;
Results:
Observations: In this
question we observed the
effect of 20dB AWGN noise
on our previously generated
signal.
Conclusion: From this experiment I learnt about MATLAB like how to
write programs and run them, how to define matrices and arrays, how to
define unit step, unit ramp and unit impulse and plot their waveforms. I
learnt about three different types of plotting waveforms: plot, subplot and
stem. Then learnt about how to generate sine waves and sample them at
different frequencies. Also learnt about how to format your waveforms like
giving them title and naming x and y axis, increasing the width of line of
waves, hold on, hold off.