Digital Signal Processing: Using Matlab Lab Tasks

You might also like

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

Digital Signal Processing

Using Matlab

Lab Tasks

1. 2d Convolution
2. 2d Image Blurring
3. Properties of Fourier Transform






2D CONVOLUTION
Code:








Output:

Figure 1 Showing Convolution of 2 Matrices


function out=conv2d(x,h)
[rx cx]=size(x);
[rh ch]=size(h);
h=fliplr(h);
h=flipud(h);
xp=zeros(2*rh+rx-2,2*ch+cx-2);
xp(rh:rh+rx-1,ch:ch+cx-1)=x;

for i=1:rx+rh-1
for j=1:cx+ch-1
w=xp(i:rh+i-1,j:ch+j-1);
y(i,j)=sum(sum(w.*h));
end
end
out=y;
end

IMAGE FILTERING USING 2D MOVING AVERAGE
FILTER























function imblr2d(x1,M1,M2) %%M1=row
wise<> and M2=column wise<>

if nargin==1
M1=20;
M2=20;
end
if nargin==2
M2=M1;
end

x=imread(x1);
[r c clr]=size(x);
xp=zeros(r+2*M1,c+2*M2,clr);
xp(M1+1:M1+r,M2+1:M2+c,:)=x;

for i=1:clr
for j=1:r
for k=1:c

a=xp(j:2*M1+j,k:2*M2+k,i);
y(j,k,i)=sum(sum(a));
end
end
end
y=y/((2*M1+1)*(2*M2+1));
y=uint8(y);
figure('Name',x1,'NumberTitle','off')
subplot(1,2,1)
imshow(x)
title('Original Image')
subplot(1,2,2)
imshow(y);
title('Blurred Image')
end

Output:

Figure 2 Blurring for M1=M2=10

Figure 3 Blurring for M1=M2=50

Figure 4 Blurring for M1=M2=100





PROPERTIES OF DTFT
1. When x[n] is real and even, X(e
jw
) is real and symmetric.




2. When x[n] is real and odd, X(e
jw
) is imaginary and symmetric.



3. If x[n] Is any real function, |X(e
jw
)|=even and < X(e
jw
)=odd




CODE:

function out=mydft(xn)
out=fourier(xn);
w=-4:0.0001:4;
f=subs(out);
subplot(2,1,1);
stem(w,abs(f));
xlabel('w----->');
ylabel('|X(e^j^w)|----->')
subplot(2,1,2);
stem(w,angle(f));
xlabel('w----->');
ylabel('<X(e^j^w)----->')
end

You might also like