Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Digital Signal Processing

Assignment # 1

Q. Load your voice in the computer for 1 sec.


A.

Code:
[y,fs]= audioread('Rec.wav');
a. Find out the sampling frequency and the length of the signal.
Code:
>> fs
fs = 44100
>> length(y)
ans = 302080
b. Down sample by the factor of 2 and 5.
Code:
x=downsample(y,2);
z=downsample(x,5);
c. Find out the length of the new signal.
Code:
>> length(z)
ans = 30208
d. Compute 1, 2 and infinite norms.
Code:
>> a=norm(z,1)
a = 1.7733e+03
>> b=norm(z)
b = 17.9174
>> norinf=norm(z,inf)
norinf = 0.6447

e. Plot original sampled signal and draw a line on the graph representing sampling
frequency.
Code:
n=[0:length(z)-1];
df=fs/length(y);
f=df*n;
plot(f,z)
grid on

Q. Load your voice:


Code:
[y,fs]= audioread('Rec.wav');

a. Add Gaussian White Noise with mean 0 and variance 6.


Code:
a=imnoise(y,'gaussian',0,6);

b. Plot signal with and without noise in one graph.


Code:
n=[0:length(y)-1];
plot(n,a)
hold on
plot(n,y)

c. Remove noise and plot clean signal and noise signal.


Code:
k=wiener2(a,[15 15]);
plot(n,a)
hold on
plot(n,k)

Q. Plot the following signal up to two complete cycles.


a. A = 2 sin 314t + 4 sin 471.75t
Code:
t=0:0.1:100;
a=2*sin(314*t)+4*sin(471.75*t)
plot(t,a)

b. What is the suitable sampling frequency of the above signal?


Code:
fs=2*(471.75/(2*pi))
Result:
fs = 150.1627 (Sampling Frequency ~ 150 Hz)

Q. Plot the following sequence:


(i). x[n] = {-4, 5, 1, -3, -2, 0, 2}
Code:
x=[-4 5 1 -3 -2 0 2]
n=-3:1:3;
stem(n,x)

-3 n 3

(ii). y[n] = {6, -3, -1, 0, 8, 7, 2}

-1 n 5

Code:
y=[6, -3, -1, 0, 8, 7, 2]
n=-1:1:5;
stem(n,x)

(iii). w[n] = {3, 2, 2, -1, 0, -2, 5}


Code:
w=[3 2 2 -1 0 -2 5]
n=2:1:8;
stem(n,x)

Plot using MATLAB code for each.


a. c[n] = x[-n+2]
Code:
x=[-4 5 1 -3 -2 0 2]
n=-3:1:3;
c=-n+2;

2n8

stem(c,x)

b. d[n] = y[-n-3]
Code:
y=[6, -3, -1, 0, 8, 7, 2]
n=-1:1:5;
c=-n-3;
stem(c,x)

c. e[n] = w[-n]
Code:
w=[3 2 2 -1 0 -2 5]
n=2:1:8;
c = -n;
stem(c,x)

d. u[n] = x[n].w[n+4]
Code:

e. Energy of each signal.


Code:
x= [-4 5 1 -3 -2 0 2]
energy = (norm(x)^2)
Result:
energy = 59.0000
Code:
y=[6, -3, -1, 0, 8, 7, 2]
energy = (norm(y)^2)
Result:
energy = 163.0000
Code:
w=[3 2 2 -1 0 -2 5]
energy = (norm(w)^2)
Result:
energy = 47.0000

f. Compute 1,2 and infinity norms


Code:
x=[-4,5,1,-3,-2,0,2];
normx1=norm(x,1)
normx2=norm(x)
normxinf=norm(x,inf)
Result:
normx1 = 17
normx2 = 7.6811
normxinf = 5
Code:
y=[6,-3,-1,0,8,7,-2];
normy1=norm(y,1)
normy2=norm(y)
normyinf=norm(y,inf)
Result:
normy1 = 27
normy2 = 12.7671
normyinf = 8
Code:
w=[3,2,2,-1,0,-2,5];
normz1=norm(z,1)
normz2=norm(z)
normzinf=norm(z,inf)
Result:
normz1 = 1.7733e+03
normz2 = 17.9174

normzinf = 0.6447

You might also like