You are on page 1of 6

clc;

close all;
clear all;
a=imread("D:\lena_gray.bmp" );
figure(1)
imshow(a);
a=im2double(a);
title('original input image');
w1=[1 2 1;0 0 0;-1 -2 -1]; w2=[-1 0 1;-2 0 2;-1 0 1];
[row,col]=size(a);
for x=2:1:row-1
for y=2:1:col-1
a1(x,y)=w1(1)*a(x-1,y-1)+w1(2)*a(x-1,y)+w1(3)*...
a(x-1,y+1)+w1(4)*a(x,y-1)+w1(5)*a(x,y)+w1(6)*...
a(x,y+1)+w1(7)*a(x+1,y-1)+w1(8)*a(x+1,y)+w1(9)*...
a(x+1,y+1);
a3(x,y)=a1(x,y)*a1(x,y);
a2(x,y)=w2(1)*a(x-1,y-1)+w2(2)*a(x-1,y)+w2(3)*...
a(x-1,y+1)+w2(4)*a(x,y-1)+w2(5)*a(x,y)+w2(6)*...
a(x,y+1)+w2(7)*a(x+1,y-1)+w2(8)*a(x+1,y)+w2(9)*...
a(x+1,y+1);
a4(x,y)=a2(x,y)*a2(x,y);
end
end
figure(2);imshow(sqrt(a3));
title('Edge Detection in y direction');figure(3);
imshow(sqrt(a4));title('Edge Detection in x direction');
output(sqrt(a3+a4))
figure(4)
imshow(output);title('Edge Detection');
Edge Detection in x direction

Edge Detection in y direction


clc;
clear all;
close all;
fs=1000;
fp=200;
fs1=250;
rp=1;
rs=60;

%Normalized frequency
wp=2*fp/fs;
ws=2*fs1/fs;

%Chebyshev filter design


[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wn);

[h,w]=freqz(b,a,1024,fs);
f=w/(2*pi)*fs;
mag=20*log10(abs(h));
phase=unwrap(angle(h))*180/pi;

figure
subplot(2,1,1);
plot(f,mag);
grid on;
title('Magnitude Response');
xlabel('Frequency(Hz)');
ylabel('Magnitude(dB)');

subplot(2,1,2)
plot(f,phase);
grid on;
title('Phase Response');
xlabel('Frequency(Hz)');
ylabel('Phase (degrees)');
Magnitude Response
0
Magnitude(dB)

-100

-200

-300

-400
0 1 2 3 4 5 6 7 8
Frequency(Hz) 4
10
Phase Response
0
Phase (degrees)

-500

-1000

0 1 2 3 4 5 6 7 8
Frequency(Hz) 104
clc;
clear all;
close all;
fs=1000;
wp=100;
ws=200;
rp=1;
rs=30;

wpn=wp/(fs/2);
wsn=ws/(fs/2);
[N,Wn]=buttord(wpn,wsn,rp,rs);

[b,a]=butter(N,Wn);

[h,w]=freqz(b,a,1024,fs);
f=w/(2*pi)*fs;
mag=20*log10(abs(h));
phase=unwrap(angle(h))*180/pi;

figure
subplot(2,1,1);
plot(f,mag);
grid on;
title('Magnitude Response');
xlabel('Frequency(Hz)');
ylabel('Magnitude(dB)');

subplot(2,1,2)
plot(f,phase);
grid on;
title('Phase Response');
xlabel('Frequency(Hz)');
ylabel('Phase (degrees)');
Magnitude Response
0
Magnitude(dB)

-100

-200

-300

-400
0 1 2 3 4 5 6 7 8
Frequency(Hz) 10 4

Phase Response
0
Phase (degrees)

-200

-400

-600
0 1 2 3 4 5 6 7 8
Frequency(Hz) 104

You might also like