Você está na página 1de 12

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI

Hyderabad Campus
Digital Signal Processing

Lab 2
(You are instructed to write solutions, plots, observations and explorations in your
observation record and get it signed before leaving the lab)
[A] A sinusoidal signal s(t) is of frequency 1 Hz and peak amplitude of 1.
1. (i) Assume s(t) is sampled with sampling frequency of 10 Hz. Sub plot the
samples of sinusoid for 4 sec .
f=1;
fs=10;
T=4;
dt=1/fs;
x=sin(2*pi*[0:dt:T])
subplot(1,2,1)
stem([0:dt:T],x)

(ii) Now plot the continuous signals connecting these samples as the second sub
plot.
f=1;
fs=10;
T=4;
dt=1/fs;
x=sin(2*pi*[0:dt:T])
subplot(1,2,1)
stem([0:dt:T],x)
subplot(1,2,2)
plot([0:dt:T],x)

2. (i) Assume s(t) is sampled with sampling frequency of 2 Hz. Plot the samples of
sinusoid for 4 sec.
f=1;
fs=2;
T=4;
dt=1/fs;
x=sin(2*pi*[0:dt:T])
subplot(1,2,1)
stem([0:dt:T],x)

(ii) Now plot the continuous signals connecting these samples as the second sub
plot.
f=1;
fs=2;
T=4;
dt=1/fs;
x=sin(2*pi*[0:dt:T])
subplot(1,2,1)
stem([0:dt:T],x)
subplot(1,2,2)
plot([0:dt:T],x)

3. Note down your observations and explorations


[B] Plot a sound file, amplified and attenuated sound file in one plot using sub plot. Use
the available audio file from the folder.
1. Use the auread command to load the file speech.au into Matlab.
2. Plot the signal on the screen as if it is a continuous-time signal (in top plot using
sub plot).
3. Amplify the sound wave by a factor of 5 and plot below the first plot.
4. Attenuate the original sound wave by a factor of 5 and plot below the second plot.
5. Play the three signals via the digital-to-analog converter in your workstation with
the Matlab sound function.
6. Note down your observations and explorations
x=auread('speech.au');
sound(x)

subplot(2,1,1)
y=5*x;
plot(y)
sound(y)
subplot(2,1,2)
z=x/5;
plot(z)
sound(z)

[C] Follow the instructions given below:


1. Read the lena image in Tiff format from the folder given.
2. Display this image in gray scale as top plot in subplot of three.
t = Tiff('lena.tiff');
a = read(t);
imshow(a+-100);

3. Add some DC value of 100 and then display the image in gray scale as second
plot in subplot of three.

4. Subtract some DC value of 100 from original image and then display the image in
gray scale as third plot in subplot of three.

5. Note down your observations and explorations.


[D] The following matlab program is given. Find the mathematical expression for y in
terms of x.
n = 0:100;
s1 = cos(2*pi*0.05*n); % A low frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 1');

subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 2');
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal');
axis;

b =
0.2000

0.2000

0.2000

0.2000

0.2000

Define the denominator coefficients of the rational transfer function.

a = 1;
Find the moving-average of the data with a window size of 5.

y = filter(b,a,x);
y(1) is equivalent to 0.2*x(1).
y(2) is equivalent to 0.2*(x(1)+x(2)).
...
y(5) is equivalent to 0.2*(sum(x(1:5)) = mean(x(1:5)).
y(6) is equivalent to mean(x(2:6)).
...
y(100) is equivalent to mean(x(96:100)).

1. Now change the program so that it will find y3, y10, y50 and y100 corresponding
to M = 3, 10, 50 and 100. Plot the inputs s1, x and four outputs corresponding to
different values of M.

M=3

M=10

M=50

M=100
2. Explain the function of the above program and comments/remarks based on
different outputs obtained for M = 3, 10, 50 and 100.

Você também pode gostar