# Kategori arşivi: Maltab

## Edge Detection on Matlab

Hi everyone,

At my this project i am going to make edge detection. I will use matlab’s built in functions.

This is my original photo. I will read it, convert to the gray, finally from the gray photo i will detect the edges. As you can see from the code below, i used sobel edge detection.

lena=imread('lena.jpg'); lena_gray=rgb2gray(lena); lena_gray_double=double(lena_gray); lena_gray_double=lena_gray_double/max(max(lena_gray_double)); figure; edge(lena_gray_double,'sobel') title('Built-in Edge Detected Image With Sobel'); %https://ozturkgokhan.com/

Best wishes;

Gökhan ÖZTÜRK

## Plotting Equation at Z-Plane

Hi, today i will try to plot poles and zeros of an parametric equation. A parametric equation type is given below b(n) and a(n) are the coefficients of the equation Assume we know the coefficients. Let's try to plot at z- plane.

b1=[1 -0.4944 0.64]; b2=[1 0.4944 0.64]; root_a1=roots(a1); root_b1=roots(b1); figure;zplane(root_b1,root_a1); title('Pole-Zero Diagram of a1-b1 System'); %http://ozturkgokhan.com

As u see we managed the process.

Best wishes;

Gökhan ÖZTÜRK

## Creating Butterworth and Chebyshev filters with by Using Sptool

Hi, at my previous post i talked about the filters and input-output relationship.

As you remember i mentioned that i will design the discrete-time

filters with Butterworth and Chebyshev approximations.

Let’s see the properties of the filter again.

0.8 < |H(exp(jw))| < 1 for 0 < w < 0.22*pi

|H(exp(jw))| < 0.26 for 0.32*pi < w < pi

For able to desing filter we will use “sptool” command. When we write ‘sptool’ to command window, we get SPTOOL:startup.spt window.

Then click ‘FIRbp[design]’ and ‘New’.

So we have a new window like ‘Filter Design & Analysis Tool-(FIRbp)’, change the values of filter at the blue arrows and right click to ‘Magnitude (DB)’ at the red arrow and hange as given. Finally, click ‘Design Filter’. After that click to ‘Edit’ and use ‘convert to single section’.

Now we will get our numerator and denominator coefficients of filter. Use this way; ‘File -> export (change name of coefficients) -> export’.

Name numerator coefficients b1,denominator coefficients a1 for Butterworth filter and b2,a2 for

Chebyshev filter.

f=linspace(-1,1,length(data)) BW = filter(b1,a1,data) CS1 = filter(b2,a2,data) figure; subplot(3,1,1) stem(f,fftshift(abs(fft(data)))); title('Magnitude response of my input signal'); grid on; subplot(3,1,2) stem(f,fftshift(abs(fft(BW)))); title('Magnitude response of my output,filtered by Butterworth '); grid on; subplot(3,1,3) stem(f,fftshift(abs(fft(CS1)))); title('Magnitude response of my output,filtered by Chebyshev'); grid on;

Let’s examine the differences Butterworth and Chebyshev approximations.

As you see transition region at Chebyshev approximation is smaller than Butterworth approximation.

But at the passband region of Chebyshev approximation has ripples and filters the signal around zero.

I hope it would be helpful to you.

Thanks.

gökhan öztürk

## Differences Between Butterworth and Chebyshev approximations.

Hi, at my this post i will share my experiment that i learned at my digital

signal processing lessons and laboratory.

It is about filters and i am going to show you that is how to desing discrete-time filters with Butterworth and Chebyshev approximations. Then we will use and see the differences.

First step; we are investigating the input-output relations a filter and taking Fast Fourier Transform (FFT) of a signal.

We have the properties of a low-pass filter like following.

(Later on i will show how we did this )

0.8 < |H(exp(jw))| < 1 for 0 < w < 0.22*pi

|H(exp(jw))| < 0.26 for 0.32*pi < w < pi

This means our filter has bandpass region between 0-0.22*pi and tolereable

magnitude values 0.8 and 1 (at ideal low-pass filters our magnitude was 1)

,transition region 0.22 to 0.32 and at the end it has stopband region

0.32*pi to pi and magtinude is smaller than 0.26 (at ideal low-pass filters

our magnitude was 1). Also we will normalize this values.

%x is the input signal %y is the filtered output signal f=linspace(-1,1,length(x));figure; subplot(4,1,1);plot(x); title('My input signal'); subplot(4,1,2);plot(y); title('My output signal'); subplot(4,1,3);stem(f,fftshift(abs(fft(x)))); title('Magnitude response of my input signal'); subplot(4,1,4);stem(f,fftshift(abs(fft(y)))); title('Magnitude response of my output signal');); stem(X,Y) fuction plots a signal X versus Y linspace(a,b,n) funtion creates a row vector between a and b, divides linearly with n.ta stem(f,fftshift(abs(fft(x)))); takes the FFT of x and

As you see just symetric peaks. Three of them are at right side at another side. Filter’s cutoff frequency was 0.32 and just outside of 0.4 (and -0.4) is supressed so the signal at 0.6 ( and -0.6 ).

Additionally; if you want to use matlab’s help file, just type help and subject to the command window and press enter.

Like help stem. It suggests you the titles or you may know the fuction but wanna see the details ; use doc coomad like,

doc. stem .

Good Luck,

Gökhan Öztürk