Hexapod Simulation in MATLAB
Hello fiends, hope you all are fine and having fun with your lives. In today's tutorial, I am going to share a new project designed in MATLAB and named as Hexapod Simulation in MATLAB. We all know about the Hexapod, its a special kind of robot which has six legs. Hexa is used for six so its quite obvious that hexapod has six legs on it.
I have designed this project on a client's request and today I thought to share it with you guys. Because this Hexapod simulation in MATLAB is designed after a lot of efforts by our TEP team that's why this simulation is not free to download but we have placed a small price on it so that engineering students can buy it easily. So, let's get started with Hexapod Simulation in MATLAB.
Hexapod Simulation in MATLAB
- First of all, you need to buy this Hexapod Simulation in MATLAB by clicking the below button:
Buy This Simulation
- When you buy this project, you will get three files in it which are named as:
- Hexapod.m
- RobotMotion.m
- Robot Design.m
- You need to open the first one named as Hexapod.m, this is the Main file for this Hexapod Simulation in MATLAB.
- It has the below code in it:
clc;
clearvars;
close all;
imtool close all;
subplot(6,6,1:30)
xlabel('x'); ylabel('y'); zlabel('z');
axis([-150 200 -50 150 0 150])
grid on
hold on
Inc = 0;
firstLen = 50;
secondLen = 50;
stepSize = 20;
StepsTaken = 1;
y1 = 0;
y2 = 1;
RobotDesign(firstLen,secondLen)
subplot(6,6,31)
subplot(6,6,32)
subplot(6,6,33)
subplot(6,6,34)
subplot(6,6,35)
subplot(6,6,36)
OldInc = 0;
for b = 0:1:StepsTaken-1
subplot(6,6,1:30)
[Inc OldInc y1 y2]= RobotMotion(firstLen,secondLen,stepSize,Inc,OldInc, y1, y2);
end
- As you can see in the above code, we can set different parameters like lengths of legs and the steps it can take etc.
- Let me give a slight overview of Hexapod and how it works. So, have a look at below figure:
- I have designed a small hexapod and I have colored its legs.
- The red Color legs are called Gate 1 while the green color legs are called Gate 2.
- Now, when a Hexapod moves its first three legs (Gate 1) which I have designed in Red Color are first moved in upward motion and after that the Gate 1 moves in the Forward Direction and then finally Gate 1 moves in downward direction.
- After that the Gate 2 Legs are move in upward Direction and then Gate 2 Legs are moved in Forward Direction and finally Gate 2 moves in downward direction.
- Now when all legs are moved in Forward direction then finally the Robot Body is moved in Forward Direction.
- Let me summarize these steps:
- Gate 1 (Red Legs) moves in Upward Direction.
- Gate 1 (Red Legs) moves in Forward Direction.
- Gate 1 (Red Legs) moves in Downward Direction.
- Gate 2 (Green Legs) moves in Upward Direction.
- Gate 2 (Green Legs) moves in Forward Direction.
- Gate 2 (Green Legs) moves in Downward Direction.
- Robot Body moves in Forward Direction.
- These are the 7 steps a hexapod takes to move a single step Forward.
- Now in the above code, I have used some variables which are:
- firstLen = 50;
- secondLen = 50;
- stepSize = 20;
- StepsTaken = 1;
- firstLen is the length of Gate 1 legs which I have set 50 rite now.
- secondLen is the length of Gate 2 legs.
- stepSize is how big the step should be.
- StepsTaken is how much steps it should take.
- Now when you run the simulation then the first thing you will get is shown in below figure:
- AS I have given StepsTaken = 1 so it will just take one step, you can change it though and when it takes one step the final position of robot will be as shown in below figure:
- Now, if you compare the above two figures then you can see the starting position of Hexapod in x direction was 0 but when it took first step then now its position is 20.
- The below four graphs are showing the angles of your robot gates in radians.
- The below video will explain this project in detail:
That's all for today. I hope you have liked this Hexapod simulation in MATLAB. Before buying this project you must watch this video so that you have a clear overview of this Hexapod simulation in MATLAB.
DTMF Decoder using MATLAB
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a project named as DTMF Decoder using MATLAB. In this project, I have designed a keypad in MATLAB using the GUI functionality of MATLAB. After designing the keypad, I have assigned a tune to each of these buttons. Obviously the tune attached to each button is different and when we press any of these buttons, then the MATLAB recognizes the respective button.
This project is designed in MATLAB and I have tested it on MATLAB 2009 and MATLAB 2014 and it works fine on both of them. Code is given below in this tutorial for download. f you got problem in it then ask in comments and I will try to resolve them. So, let's get started with DTMF decoder in MATLAB.
DTMF Decoder using MATLAB
- You can download the complete code by clicking the below button:
Download Project Files
- In this download package, you will get three files and you need to run the file named as decoder.m.
- When you run the file named as decoder.m, it will start the GUI which will look something as shown in below figure:
- That's the GUI used for DTMF Decoder using MATLAB.
- You can see a keypad is shown in the above GUI, now I have assigned a specific tune to each of these buttons and the code for assigning this tune is as follows:
t=[0:0.000125:.05];
fs=8000;
f1=770;f2=1477;
y1=.25*sin(2*pi*f1*t);
y2=.25*sin(2*pi*f2*t);
y=y1+y2;sound(y,fs)
- So, you can see in the above code that I have generated a sine wave and then created a sound using that sine wave.
- So, we have such sounds assigned to each of these buttons.
- Now once button is pressed, the respective sound will be activated and rite after that sound, I have added a subroutine for decoding that sound.
- This subroutine is placed in a separate file named as subdecode.m.
- This subdecode.m is responsible for DTMF decoding and its code is as follows:
axes(handles.fig1);
plot(t,y);
set(handles.fig1,'XMinorTick','on');
title('DTMF Input');xlabel('Time');
ylabel('Amplitude');grid;
rmain=2048*2;rmag=1024*2;
cn=9;cr=0.5;
cl=.25;ch=.28;
[b,a]=cheby1(cn,cr,cl);
yfilt1=filter(b,a,y);
h2=fft(yfilt1,rmain);
hmag2=abs(h2(1:rmag));
[b1,a1]=cheby1(cn,cr,ch,'high');
yfilt2=filter(b1,a1,y);
h3=fft(yfilt2,rmain);
hmag3=abs(h3(1:rmag));
axes(handles.fig2);
plot(yfilt1);grid;
title('Filtered Low Freq. Signal');
xlabel('Time');ylabel('Amplitude');
axes(handles.fig3);
plot(yfilt2);grid;
title('Filtered High Freq. Signal');
xlabel('Time');ylabel('Amplitude');
hlow=fft(yfilt1,rmain);
hmaglow=abs(hlow);
axes(handles.fig4);
plot(hmaglow(1:rmag));
title('FFT Low Pass');grid;
xlabel('Time');ylabel('Amplitude');
hhigh=fft(yfilt2,rmain);
hmaghigh=abs(hhigh);
axes(handles.fig5);
plot(hmaghigh(1:rmag));
title('FFT High Pass');grid;
xlabel('Time');ylabel('Amplitude');
m=max(abs(hmag2));n=max(abs(hmag3));
o=find(m==hmag2);p=find(n==hmag3);
j=((o-1)*fs)/rmain;
k=((p-1)*fs)/rmain;
if j<=732.59 & k<=1270.91;
disp('---> Key Pressed is 1');
elseif j<=732.59 & k<=1404.73;
disp('---> Key Pressed is 2');
elseif j<=732.59 & k<=1553.04;
disp('---> Key Pressed is 3');
elseif j<=732.59 & k>1553.05;
disp('---> Key Pressed is A');
elseif j<=809.96 & k<=1270.91;
disp('---> Key Pressed is 4');
elseif j<=809.96 & k<=1404.73;
disp('---> Key Pressed is 5');
elseif j<=809.96 & k<=1553.04;
disp('---> Key Pressed is 6');
elseif j<=809.96 & k>1553.05;
disp('---> Key Pressed is B');
elseif j<=895.39 & k<=1270.91;
disp('---> Key Pressed is 7');
elseif j<=895.39 & k<=1404.73;
disp('---> Key Pressed is 8');
elseif j<=895.39 & k<=1553.04;
disp('---> Key Pressed is 9');
elseif j<=895.39 & k>1553.05;
disp('---> Key Pressed is C');
elseif j>895.40 & k<=1270.91;
disp('---> Key Pressed is *');
elseif j>895.40 & k<=1404.73;
disp('---> Key Pressed is 0');
elseif j>895.40 & k<=1553.04;
disp('---> Key Pressed is #');
elseif j>895.40 & k>1553.05;
disp('---> Key Pressed is D');
end
- Now you can see in this code we are applying FFT on each of these sound signals and then comparing them to get our required button press.
- Now, when I press any of these buttons then the GUI will look something as shown in below figure:
- You can see in the above figure that first graph is showing the DTMF input, which is actual signal which I have converted to sound on button press.
- The second graph is showing the Filtered Low Frequency Signal while the third one is showing the Filtered High Frequency Signal.
- The two graphs on the right side are showing the Amplitude of FFT Low Pass and FFT High Pass.
- Now if you have a look at the Command window of MATLAB then it will give you the button pressed as shown in below figure:
- These are the buttons which I have pressed while testing it and it has given me each time which button is pressed.
- Here's the video which will give you better idea of How this DTMF decoder using MATLAB is working.
That's all about
DTMF Decoder using MATLAB. If you have any questions, then ask in comments and I will try my best to resolve them. Till next tutorial take care and have fun !!! :)
Convolution Calculator in MATLAB
Hello friends, hope you all are fine and having fun with your lives. In today's post, I am gonna design a Convolution Calculator in MATLAB. We all know about convolution but if you don't know then here's the wiki page for convolution which has a detailed description of Convolution. In simple words, convolution is a mathematical operation, which applies on two values say f and g and gives a third value as an output say v. In convolution, we do point to point multiplication of input functions and gets our output function.
Convolution is an important technique and is used in many simulating projects. It has a vital importance in image processing. So, today we are gonna do convolution in MATLAB and will check the output. You should also check Image Zooming with Bilinear Interpolation in MATLAB in which we have used correlation technique which is quite similar to convolution. It will give you a better idea of convolution, I recommend you to read their difference. Anyways, coming back to our today's Convolution Calculator, let's start its designing:
Convolution Calculator in MATLAB
- MATLAB has a built in command for convolution using which we can easily find the convolution of two functions.
- Syntax of this builtin convolution command is v=conv(x,h) where x and h are the input functions while v is our output.
- In my code I have used this builtin function as well as I have also design a small algorithm for calculating the convolution using its formula.
- After finding both the convolutions, I have simply compared them by plotting them on graph so that we can also verify that our result is correct.
- You can use this convolution calculator to find convolution of any two functions.
- So, first of all, copy this code and paste it in your m file and run it in your MATLAB:
clc
close all
clear all
x=input('enter the sequence, x(n)=')
h=input('enter the sequence, h(n)=')
m=length(x);
n=length(h);
subplot(4,1,1)
stem(1:m,x,'fill','r')
grid on;
title('input sequence, x(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
subplot(4,1,2)
stem(1:n,h,'fill','r')
grid on;
title('impulse sequence, h(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
%------linear convolution using inbuilt command------------------------%
v=conv(x,h)
l=m+n-1;
subplot(4,1,3)
stem(1:l,v,'fill','r')
grid on;
title('output sequence using inbuilt command, v(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
%--------linear convolution using 'for' loop------------------------------%
X=zeros(1,l);
H=zeros(1,l);
X(1:m)=x;
H(1:n)=h;
for i=1:l
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
Y
subplot(4,1,4)
stem(1:l,Y,'fill','r')
grid on;
title('output sequence using loop, Y(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
- The above code for convolution calculator is quite self explanatory but let me explain it a little.
- First of all, I am asking for inputs from user and they are saved in variables named as x and h.
- After that I am plotting them using stem function.
- In the next section, I have used the default MATLAB command for Convolution and calculated the convolution of x and h and saved it in v.
- Next I applied my simple algorithm and calculated convolution of x and h and saved it in Y and also plotted it.
- Once you run the simulation and give your input functions, you will get the below results:
- You can see in the above figure that I have given two inputs x and h and MATLAB Convolution Calculator calculated the convolution and gave us v and Y.
- v is calculated by default MATLAB command while the Y is calculated by our small convolution algorithm.
- Their graph representation is shown in the below figure:
- You can see in the above figure that we have plotted all the four signals, two inputs and two outputs and you can see both the outputs are same.
- Here's the video for this convolution calculator in MATLAB:
That's how you can design a convolution calculator in MATLAB. Let me know about your experience with this convolution calculator. I am planning to design a GUI for this calculator and will add it in this post.
Speech Recognition in MATLAB using Correlation
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a tutorial on Speech Recognition in MATLAB using Correlation. Speech recognition is used in almost every security project where you need to speak and tell your password to a computer and is also used for automation. For example, I want to turn my AC on or off using voice commands then I have to use Speech Recognition. I have to make the system recognize that whether I am saying ON or OFF. In short, speech recognition plays a vital role in voice control projects. In today's post, I am gonna show you How to do Speech Recognition in Matlab and the technique I have used in this project is known as cross correlation. You should also have a look at Eye Ball Detection in MATLAB.
Correlation is normally used in signal processing, where you need to compare two signals and need to find the similarity between them. It is also known as the dot product of those two signals. Correlation has many uses and you can read more about it on its Wiki Page. Correlation is also used for pattern recognition like you want to find some pattern in the signal then you can use Correlation. Anyways, in our project, we are using correlation to find similarities between our stored signals and the testing signal. So, let's get started with Speech Recognition in MATLAB using Correlation.
Speech Recognition in MATLAB using Correlation
- First of all, download this complete project by clicking the below button:
- Now in this package, you will find nine audio wav files.
- Five of them are the recorded sounds that are already feed in MATLAB.
- Two are test files that will be recognized by the code.
- The remaining two are success and failure files which will run if you got the recognition or not.
- Let me explain the code a bit. First of all, what we need to do is to upload the first five training audio files in the software so and then we need to test these fives files with the test files and we need to check which one is a maximum match.
- Here's the complete code:
function speechrecognition(filename)
voice=wavread(filename);
x=voice;
x=x';
x=x(1,:);
x=x';
y1=wavread('one.wav');
y1=y1';
y1=y1(1,:);
y1=y1';
z1=xcorr(x,y1);
m1=max(z1);
l1=length(z1);
t1=-((l1-1)/2):1:((l1-1)/2);
t1=t1';
%subplot(3,2,1);
plot(t1,z1);
y2=wavread('two.wav');
y2=y2';
y2=y2(1,:);
y2=y2';
z2=xcorr(x,y2);
m2=max(z2);
l2=length(z2);
t2=-((l2-1)/2):1:((l2-1)/2);
t2=t2';
%subplot(3,2,2);
figure
plot(t2,z2);
y3=wavread('three.wav');
y3=y3';
y3=y3(1,:);
y3=y3';
z3=xcorr(x,y3);
m3=max(z3);
l3=length(z3);
t3=-((l3-1)/2):1:((l3-1)/2);
t3=t3';
%subplot(3,2,3);
figure
plot(t3,z3);
y4=wavread('four.wav');
y4=y4';
y4=y4(1,:);
y4=y4';
z4=xcorr(x,y4);
m4=max(z4);
l4=length(z4);
t4=-((l4-1)/2):1:((l4-1)/2);
t4=t4';
%subplot(3,2,4);
figure
plot(t4,z4);
y5=wavread('five.wav');
y5=y5';
y5=y5(1,:);
y5=y5';
z5=xcorr(x,y5);
m5=max(z5);
l5=length(z5);
t5=-((l5-1)/2):1:((l5-1)/2);
t5=t5';
%subplot(3,2,5);
figure
plot(t5,z5);
m6=300;
a=[m1 m2 m3 m4 m5 m6];
m=max(a);
h=wavread('allow.wav');
if m<=m1
soundsc(wavread('one.wav'),50000)
soundsc(h,50000)
elseif m<=m2
soundsc(wavread('two.wav'),50000)
soundsc(h,50000)
elseif m<=m3
soundsc(wavread('three.wav'),50000)
soundsc(h,50000)
elseif m<=m4
soundsc(wavread('four.wav'),50000)
soundsc(h,50000)
elseif m<m5
soundsc(wavread('five.wav'),50000)
soundsc(h,50000)
else
{soundsc(wavread('denied.wav'),50000)}
end
- Now if you read the code from start then you can see, first of all, I uploaded the test file which I want to compare with my samples.
- After that, I uploaded all 5 samples and also get their correlation with the test sample.
- Finally, in the end, I compared the results and on the basis of it I figured out which one is the correct speech file.
- You will also get spectrum graphs of your sound files as shown in the below figure:
- It was quite an easy project and I have done it within half an hour and I hope you guys will understand.
- If you got any problems then ask in the comments and I will resolve them.
- Here's the complete video demonstration for this project and I hope it's going to help you out in understanding it.
That's all for today, and I think you have understood How to do Speech Recognition in MATLAB using Correlation. Will meet you guys in the next tutorial soon. Till then take care !!! :)
Image Zooming with Bilinear Interpolation in MATLAB
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a simple tutorial on Image zooming with bilinear Interpolation in MATLAB. We have seen many software in which there's an option of zooming an image. For example, if you have used paint or photoshop then you have seen that you can zoom your image quite easily by clicking a button. Today's we are gonna do the same thing but in MATLAB and we will have a look at the code behind this feature.
Now, when we are zooming some image then in fact we are increasing the pixels of that image and in order to do that we have to fill those extra pixels with the color of their neighbor pixel. This thing is know as interpolation. There are many different techniques for interpolation and the one we are gonna use for this tutorial is known as Bilinear Interpolation. Bilinear interpolation is simple type of linear interpolation in which we simply apply interpolation formula on both the x and y axis. So, let's have a brief overview of Bilinear Interpolation first and then we will move on to MATLAB implementation.
What is Bilinear Interpolation ?
- As I explained earlier, Bilinear Interpolation is a simple interpolation technique in which we fill the gaps between pixels using the neighbor pixels.
- For example, we have an unknown pixel in between four pixels, and let's say the unknown pixel is f(x,y) and it is surrounded by four pixels which are:
- Q11 = (x1, y1).
- Q12 = (x1, y2).
- Q21 = (x2, y1).
- Q22 = (x2, y2).
- All these four neighbor pixels are known , now by using Bilinear Interpolation we can find the values of this unknown pixel.
- Now, first of all, we will move in the x direction only.
- The formula used for Bilinear Interpolation for x factor is:
- Now after calculating these x formulas, now we will move in y direction and the formulas are:
- Now using these formulas we can quite easily find our unknown pixel f(x,y) using Bilinear interpolation. These formulas are taken from Wiki Page of Bilinear Interpolation and you can read more details about it there.
- Now we have seen the Bilinear Interpolation so now let's move and see How to do Image Zooming using this Bilinear interpolation in MATLAB.
Image Zooming with Bilinear Interpolation in MATLAB
- You can download the complete code by clicking the below button but also read the post, as I have explained this code in this remaining post.
Download MATLAB Code for Image Zooming
- In order to do image zooming with Bilinear Interpolation in MATLAB, first of all, what you need to do is to read an image file, which I have done using this simple formula:
im0=imread('TEP.jpg');
im=cast(im0,'int16');
imshow(cast(im,'uint8'));
[h,v,d]=size(im);
- So, in this above code, what we did is , we simply read the image file which I have named as TEP.jpg
- After that I have converted this image file into int16 and then to uint8 and finally I get the size of this image file using size command.
- After that I have applied a simple algorithm and have zoomed my image using below code:
for i=1:h
for j=1:v
im1(1+(i-1)*fac,1+(j-1)*fac,:)=im(i,j,:);
end
imshow(cast(im1,'uint8'));
end
- Now in the above loop what we have done is we simply enhanced our image and named it as im1, I have used a variable fac, which is factor, its user defined like if you want to zoom image by 2 then factor will be 2.
- Now we have enhanced our image, next thing we need to do is to apply the bilinear Interpolation on this complete image and we will get the result.
- Here's the complete code for Image Zooming with Bilinear Interpolation in MATLAB.
function bilinear_zoom(fac)
im0=imread('TEP.jpg');
im=cast(im0,'int16');
imshow(cast(im,'uint8'));
[h,v,d]=size(im);
for i=1:h
for j=1:v
im1(1+(i-1)*fac,1+(j-1)*fac,:)=im(i,j,:);
end
imshow(cast(im1,'uint8'));
end
%bilinear interpolation
for i=1:1+(h-2)*fac %row number
for j=1:1+(v-2)*fac %column number
if ((rem(i-1,fac)==0) && (rem(j-1,fac)==0))
else
h00=im1( ceil(i/fac)*fac-fac+1,ceil(j/fac)*fac-fac+1,:);
h10=im1( ceil(i/fac)*fac-fac+1+fac,ceil(j/fac)*fac-fac+1,:);
h01=im1( ceil(i/fac)*fac-fac+1,ceil(j/fac)*fac-fac+1+fac,:);
h11=im1( ceil(i/fac)*fac-fac+1+fac,ceil(j/fac)*fac-fac+1+fac,:);
x=rem(i-1,fac); %coordinates of calculating pixel.
y=rem(j-1,fac);
dx=x/fac; %localizeing the pixel being calculated to the nearest four know pixels.
dy=y/fac;
b1=h00; %constants of bilinear interpolation.
b2=h10-h00;
b3=h01-h00;
b4=h00-h10-h01+h11;
im1(i,j,:)=b1+b2*dx+b3*dy+b4*dx*dy; %equation of bilinear interpolation.
end
end
imshow(cast(im1,'uint8'));
end
imshow(cast(im1,'uint8'));
imwrite(cast(im1,'uint8'),'zoomed_pic.jpg');
- Now if you check in the Bilinear Interpolation code, we have applied the same equations which we have discussed in the above section.
- The Image I have used for this code is as follows:
- Now in MATLAB window, I have given this command bilinear_zoom(2) , where fac = 2, so I am increasing my image by factor 2. So it will be zoomed by 2 times.
- Its the image from my 555 Timer post but as I have posted it recently so this image was on my desktop thats why I used it. :P
- The result obtained is as follows:
- Now you can see the image has been zoomed and is now looking big and because of Bilinear Interpolation in MATLAB we haven't lost the in between pixels.
- Here's a video for this tutorial, which will give you better idea of How to do Image Zooming with Bilinear Interpolation in MATLAB.
That's all for today, I hope you have enjoyed this post. Will meet you guys in the next tutorials soon. Till then take care. :)
Color Detection in Images using MATLAB
Hello friends, hope you all are fine and having fun with your lives. In today's tutorial, we are gonna see Color Detection in Images using MATLAB. In the previous tutorial, I have posted about How to Detect Circles in Images using MATLAB in which we have detected objects based on their geometrical figure means either they are circle or not but today we are gonna distinguish objects based on their color i.e. whether they are red colored or green colored etc. Its a quite simple tutorial and comes in the basic category. We will first detect the color and then will create a boundary around that object and will also show its XY coordinates as well.
Image processing is an important tool of MATLAB. We can quite easily do the image processing in it using Image Processing toolbox so you need to make sure that your MATLAB must have Image processing toolbox before running this code. You should also have a look at these MATLAB Image Processing Projects. So, let's start with the project.
Color Detection in Images using MATLAB
- In order to do the Color Detection in Images using MATLAB, first thing we are gonna need is the image itself. :P
- So, I designed an image in paint which has different shapes in different colors as shown in below figure:
- As you can see in the above figure, there are different shapes in different colors so now we are gonna detect these objects on the basis of their color.
- Now use the below code and add it in your MATLAB m file, if you are new to m File then have a look at How to Create m File in MATLAB.
- If you wanna protect your code in m File then you should read How to Protect code in m File.
data = imread('TEP.jpg');
diff_im = imsubtract(data(:,:,2), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'black');
end
hold of
- Now, run your m file and if everything goes fine then you will get an image as shown in below figure:
- You can see in the above figure, we have only detected the shapes with green color.
- The + sign indicates the center of each detected shape.
- X and Y are the x,y coordinates of the center point of each shape which are shown in black for each detected shape.
- Now, let's detect the red color in above figure, so in order to do so what I need to do is to simply change the third value in imsubtract function from 2 to 1.
- The complete code for red color detection in MATLAB is shown below:
data = imread('TEP.jpg');
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'black');
end
hold off
- Now, when you run this code in MATLAB, you will get the output as shown in below figure:
- Now instead of detecting the green shapes, it has now detected the red shapes in MATLAB.
- And have also shown their x,y coordinates in black color.
- Now, finally let's detect the blue color, in order to do, you now just need to change the third parameter to 3 and it will detect the blue color as shown in below figure:
- That's all for today, and I think its quite an easy one as I mentioned earlier this one is quite basic tutorials. Thanks for reading and I hope it will help you in some ways. :)
Detect Circles in Images Using MATLAB
Hello friends, hope you all are fine and having fun with your lives. In today's post we are gonna see How to detect Circles in Images using MATLAB. It's quite a simple and basic tutorial but quite helpful as today I was working on a project in which I need to do so but all the codes available online were for detection and tracking of circles in live images. So, I thought to share this one on our site. I have also posted another tutorial Color Detection in Images using MATLAB, so I think its better if you check that one as well.
We all know about MATLAB, which is a great tool for image processing and quite easy as it has a strong Help section. I haven't posted much tutorials on MATLAB in my blog so from now on I am gonna post tutorial on MATLAB as I get many requests about it. If you have any requests then use our Contact form and send them to us and I will try my best to postrelated tutorials. I personally prefer OpenCV over MATLAB, when it comes to image processing but in OpenCV there's not much flexibility as in MATLAB. Anyways, let's start our tutorial which is How to Detect Circles in Images using MATLAB.
Detect Circles in Images Using MATLAB
- First of all, you are gonna need an Image, in which you are gonna find circles so I used this image of a bike.
- As we can see there are two circles in the above image, which are two tyres, so we are gonna detect them now.
- So, copy the below code and paste it in your MATLAB m file.
ImagePath='TEP.jpg'; %Give Path of your file here
Img=imread(ImagePath);
Img=im2bw(Img(:,:,3));
Rmin=70;
Rmax=100;
[centersDark, radiiDark] = imfindcircles(Img, [Rmin Rmax], ...
'ObjectPolarity','bright','sensitivity',0.90)
imagesc(Img);
hold on
viscircles(centersDark, radiiDark,'LineStyle','--');
hold off
- Now, when you run this code you will get something as shown in below figure:
- As you can see in the above figure, both the circles are now detected and are marked with red and white line.
- The command, I have used for detecting these circles is imfindcircles , where Rmin and Rmax are the minimum and maximum radius of the circles.
- It will detect only those circles which will lie in this range and other circles will be ignored.
- Moreover, the last parameter is for setting the sensitivity of circle detection, which I have given is 0.90.
- It will also give the center of these circles along with their radii in the command window as shown in below figure:
- As, we have detected two circles so the command window is showing the X, Y coordinates of both these circles along with their radii.
- Now test it and also change the minimum and maximum ranges and you will see you are gonna detect more circles.
It was quite easy but if you have problem in it then ask in comments and I will try my best to solve them. That's all for today, will meet in next tutorial. Till then take care !!! :)
3 Level Cascaded H Bridge Inverter
Buy This Project
Hello Friends, i hope you all are fine and enjoying. Today i am going to share my new project tutorial which is 3 level cascaded H bridge Inverter. I also have explained inverters in detail in one of my previous tutorial which was Introduction to Multilevel Inverters. In this tutorial i am going t o explain a new application of cascaded H-bridge inverters and we will design a 3-level cascaded H bridge Inverter through it.
Before going to that, first of all lets recall some basics of Inverters from our previous posts. Inverters or commonly known as power inverters and A dc-to-ac converter whose output is of desired output voltage and frequency is called an inverter. Inverters are also called as counter devices of rectifiers. Rectifiers are those devices which are used to convert Alternating current (AC) into Direct Current (DC). Based on the type of operation, inverters can be divided into 2 major classes named as:
- Voltage Source Inverter (VSI)
- Current Source Inverter (CSI)
A voltage controlled inverter or VSI is one in which independent controlled ac output is a Voltage waveform. On the other hand, a current source inverter or CSI is one in which independent controlled ac output is Current waveform. Since my today's tutorial title is 3-level cascaded H-bridge inverter, A three level inverter is better than a two level inverter and the reason is that in 3 level inverter, we are dealing with three output voltage or current levels and the beauty of these type of inverters is that, they give better output and current sinusoidal waveforms and Threshold values are much better. Now i am done with the introduction and basics of inverters, now lets move towards the actual working of my project tutorial. You can also buy the complete simulation of this project and we have kept very small price for it which is only $10, only to meet our design costs.
3 level Cascaded H-Bridge Inverter
- We have designed the 3 level cascaded H-bridge inverter in MATLAB Simulink and the complete diagram of the circuit is shown in the image given below:
- The above figure seem like a complex one but it is very simple to understand and has a large no of applications. So lets explain each and every parameter one by one.
- In the first stage, signal comes to a common junction and in MATLAB it is known as 'Bus Selector'. It can accept no of inputs and outputs simultaneously. It has 1 input signal and 2 output signals.
- The output from this junction is going to 2 blocks named as 'A9' and 'A10'.
- In order to explore these blocks, you can simply double click on the and a new window will open. That window is shown in the image given below:
- Every block is infact a H-bridge( it contains 4 small blocks which are arranged in H form). It needs a DC supply to operate and at input and output we have apply scopes to monitor its input and output waveforms.
- Now if you want to explore it more then simply go to any small box, double click on it and a new window will open, which is shown in the image below:
- When you will double click on that small box then a new and very informative window will open which will represent, what is fabricated in that small box.
- If you carefully read the top lines then it reads that a gto transistor is fabricated in parallel with a series RC circuit. GTO means a Gate Turn Off transistor.
- GTO is a special type of transistor and a high power semi conductor device. The difference between a GTO and any other type of transistor is that the other transistors need a Gate pulse to turn ON and when you will remove the Gate pulse they will still remain in ON state.
- To turn it OFF you have to apply some alternate means like apply reverse voltage and when transistor tends to go into other direction we remove these reverse voltages.
- Unlike any other type of transistor, the beauty of GTO is that it can be turned ON & OFF only through gate control, which makes it a very important electrical component to implement.
- In ON state, GTO has some particular values of Resistance and Inductance.
- In OFF state, it has infinite internal impedance and no current passes through it in OFF state.
- Now in the circuit we have arranged 6 blocks. We have 3 sets of blocks and each set contains 2 thyristor blocks arranged in parallel with each other.
- In input supply from source is coming to every block in 3 sets. The output from each block goes to a ideal voltage measurement block representing as VC.
- When you will run the simulation, and to monitor the output voltage results, you will double click on this block and it will be giving complex values.
- After these voltage measurement blocks, we have Fourier analyzer block. This block Fourier analyzes the input signal over a running window of one cycle of fundamental frequency component.
- First and second output returns the Magnitude and Phase angle of the signals under consideration respectively. Here we are dealing with fundamental harmonic component so, i have kept its value 1.
- All this can be seen in the image shown below:
- If you have connected all the blocks in their exact positions and all the connections are OK then, when you will run the simulation and the waveforms on the scope will like:
OUTPUT WAVEFORMS
- The output results of scope#1 are shown in the image given below:
- You can see that in the above image, we have output square waves of three different colors which are green, yellow and pink.
- As i explained earlier that we are designing a 3 level inverter and we will be dealing with 3 output waveforms, which verifies our conclusion.
- The output graph of scope#3 is shown in the image given below:
- If you look closely then, the output graph of scope#1 is similar to that of scope#3 but the output curves of scope#3 are bit contracted.
- The output graph of the scope#2 is shown in the image given below:
- The output of scope#2 represents sinusoidal square waves and bu taking the mean of every part of square wave, we can generate a AC curve.
- The output of scope#5 is similar to that of scope#2 and it is also shown in the image given below:
- The output of scope#5 is s bit purified and much similar to sinusoidal AC signal.
Alright friends, that's all from my today's post. It was a bit lengthy but very technical and easy to understand. I hope you have learned something new today. If you have any questions regarding this, then don't feel shy to ask and i will try my best to make you understand the problem. Stay tuned for more project tutorials. Until next tutorial Take Care !! :)
11-Level 3-Phase Capacitor Clamped Inverter
Buy This Project
Hello friends, hope you all are fine and enjoying. Today i am going a new project tutorial which is 11-level 3-phase Capacitor Clamped Inverter. In my previous post 11 Level 3-phase Cascaded H-Bridge Inverter, we have designed the simulation of 3 phase 11 level inverter but the only difference was the method used in that project was cascaded H Bridge but today we are gonna see How to design an 11 level 3 phase inverter using clamped capacitors.
Now i am going to share a new and advanced bulk of knowledge about inverters with you people. Since we are going to design a 3-phase capacitor clamped inverter so, we need to design some algorithm which should be able to invert DC into AC at some High voltages and after inverting these DC voltages into AC, we will create a phase sequence and most importantly phase polarity between these three phases so they should be able to feed the load and must supply load current. It is a very interesting but a bit complicated project and now-a-days it has got a large no of industrial applications. The study about inverters and their implementation is the back bone of Modern Renewable Energy and it is the future of Power Generation. It is a MATLAB simulation based project so, any kind of hardware is not included in this tutorial. So what actually we are going to do is to design the complete simulation of the project and we will discuss every component and also each sub-component which will be used in Simulink MATLAB. So let's get started with 11 Level 3 Phase Capacitor Clamped Inverter:
11-level 3-Phase Capacitor Clamped Inverter
- Capacitor Clamped inverters are commonly known as Flying Capacitor Technology and they were first purposed by Meynard and Foch.
- Flying Capacitor includes no of series combination of Capacitor Clamped Inverter Switching Cells and these capacitors are used to get high voltages.
- The general concept related to flying capacitor is that it can charge up to one-half of the DC voltages and then within the circuit they can automatically increase or decrease the voltages, according to our requirement.
- The block diagram of the complete simulation of capacitor clamped inverter in MATLAB is given in the image below:
- The complete block diagram of the Capacitor 3-phase clamped inverter is shown above. In this image, you can notice that we have 30 input pulses numbered as no.1 to no.30 .
- So we can say that we have 30 DC input pins and these DC voltages will be inverted to get High Voltage AC.
- If you double click on any input pulse then, a new window will open and it will be showing that source from which we are gaining input DC voltages.
- We are gaining DC voltages from DC generators and a no of generators are connected in parallel to get HIGH voltage DC.
- The block to which all the inputs are connected is in fact a Capacitor Clamped Bank.
- In this bank, no. of capacitors are connected in series. Since a charged capacitor behaves as a voltage source and these capacitors are connected in series and their voltages adds up and in this way we get, HIGH voltages.
- To look inside the block then double click on the block and a new window will open and it will be showing all the components which are fabricated in that block.
- The internal structure of the block for capacitor clamped inverter is shown below in image:
- In the above shown image, you can see that within the block, we have a no. of sub-blocks which are connected with each other.
- To see what is in that small box, double click on that and a new window will open, which will be showing the internal structure of the each small box.
- The internal structure of sub-block is shown in the image given below:
- In the above given figure you can see that, in every block we have a MOSFETS which are connected with antiparallel diodes for capacitor clamped inverter.
- Ideal IGBT or GTO transistors can also be used but as I explained the properties of MOSFET in the beginning, that we give pulse to its base and it becomes operational.
- Once MOSFET has been triggered it keep conducting and in order to stop it, we will have to provide reverse voltage on its base to bring it to rest state.
- Since we are going to generate High Voltages 3-phase AC, so we have applied 3 big blocks and from each block, only one phase will be generated.
- After each big block, we have a summing junction on which voltages arrives and then we have applied two different types of voltage measuring devices.
- One device measures the phase voltages of inverted AC voltages. It can also be seen from the above given block diagram that the meter on the above side, measures phase voltages of all the three phases appearing on the summing junction.
- Now if you look closely then, you will observe that only one wire from each summing junction is coming to the meter and we also know that in order to measure phase voltages, we also need a neutral wire.
- We can get neutral wire from common ground of the system and the voltage difference between a phase and a neutral wire will give us Phase voltages.
- The below meter measures line voltages. Line voltages means the voltage difference between 2 phases. In our system we have three phases which are A, B and C respectively.
- To measure line voltages, this meter measures potential difference between phases and NO neutral wire is included in it.
- The line voltages will be AB, BC and CA.
- The Phase voltages and Line voltages have much difference between them and each have their own applications.
- For example to run the single phase House-Hold load we need phase voltages (voltage difference between a phase and a neutral wire).
- Whereas in industries, we need Line voltages to run the 3-phase load.
- Now run the simulation of this capacitor clamped inverter, and after completion now click on the scope for Line Voltages and you will get the below results:
- Now for Phase voltages of capacitor clamped inverter, click on the scope for phase voltages and you will get the below results:
APPLICATIONS
All type of Inverters have a large no of applications and now a days they are focus of Research and modern studies. Inverters have also made us able to get power from Renewable energy sources like solar panels, wind mills etc. Some industrial based applications of inverters are given below:
- The biggest advantage of inverters are that they give good power quality.
- Due to good power quality motors can reach at High speed at High voltages without producing any harmonics.
- They are used in power supply circuits.
- Now-a-days inverter Air Conditioners are also available in market and due to their High Efficiency and low power rating their demand is much High.
- ECU( electrical control unit) which carries out in-vehicle control also carries inverted circuits and it's demand is also accelerating these days.
Alright friends, that was all from today post. I hope you have learned something new today. If you have any question then don't hesitate to ask in comments. Stay tuned for more beneficial project tutorials. Until next tutorial Take Care !!! :)
11 Level 3-phase Cascaded H Bridge Inverter
Buy This Project
Hello friends, i hope you all are fine and enjoying. In this post i am going to share a new project tutorial, in which we will see how to design an 11 Level Cascaded H Bridge Inverter. If you recall my previous tutorial, in which we saw the design and working applications of 11 Level 3-phase Capacitor Clamped Inverter, then you can see its exactly the same project but only we are having a different approch in it, instead of using Capacitor clamped we are using cascaded H bridge Inverter in this project.
In this project we again are going to design an inverter but the only difference is The Implementation Technique. In that project we used Capacitor Clamped technique to get High Voltages inverted AC and now in this project, we will use Cascaded H-Bridge technique to design an Inverter. We have designed this Cascaded H bridge Inverter project in Simulink MATLAB. So i will explain this project tutorial in steps. First of all we will discuss the block diagram of the project, which we have made in Simulink. Then we will discuss the internal structure and the components which are implemented in the block diagram. And in the end we will see the applications of the cascaded H-Bridge inverters. I think this was enough for introduction and Now let's get practical and without wasting any time i think we should move towards the designing of the cascaded H Bridge 3-phase inverter.
11 Level 3-Phase Cascaded H Bridge Inverter
- A cascade H Bridge Inverter is a power electronic device, built to synthesize a desired AC voltage from several level of DC voltages.
- Cascaded H Bridge inverter can be implemented by using only a single DC source or capacitors or multiple DC sources.
- A standard cascade multilevel inverter requires 'n' DC sources to produce '2n+1' levels.
- The beauty of this system is that it can allow us to gain the desired levels of AC without using any type of Transformer.
- It allows us to simultaneously maintain the DC voltage level of the DC source and choose a fundamental frequency switching pattern to produce a nearly sinusoidal AC output.
- The block diagram of the Cascaded H Bridge Inverter designed in Simulink MATLAB is shown in the image given below:
- From above figure, you can see that we have on the extreme left side we have inputs of the systems and they are numbered as 'pulse'.
- Since we are going to design a multilevel inverter, which is a 11 Level inverter and to get that much levels, we also need multiple DC inputs.
- In this system, we have 30 DC inputs and they are numbered as 'pulse1-pulse30'.
- From the title of the project, you can understand that we are going to design a 3-phase inverter and for that we must have 3 control units to get three phase voltages.
- All the inputs are going to three big blocks which are named as ' Cascaded H-Bridge Inverter'. If you double click on that block then, a new window will open which will show the internal mechanism of this big block.
- This window is shown in the image given below:
- The above figure is very important and it is showing what actually is happening in that block. Since the components encrypted in each block are large so the above figure is showing half of the components.
- 10 inputs are connected to each block and in the above shown block we have 5 inputs.
- Every input is connected to a H shape bridge. In every H-shaped bridge, we have 4 sub-blocks. In order to under the mask of the sub-blocks, Double click on them and a new window will open, which will be representing the internal structure of sub-block.
- That small window is shown in the image given below:
- Now from the above figure, you can see that every sub-block contains an ideal IGBT, Gto or MOSFET and antiparallel diodes.
- In these H-bridges we have implemented MOSFET transistor for switching. Reason is that they have mush fast response and are capable to perform switching at high speed.
- Below are some parameters of transistors, which are fabricated in sub-blocks.
- An important thing to note here is that for MOSFET 'Snubber Resistance (Cs)' is infinite in OFF state. This is because in OFF state it doesn't allow the current to pass through it.
- Once MOSFET is triggered then it will keep on conducting and after that we will have to stop it manually.
- Now if you again focus the first block diagram then, you will observe that each block is giving only value of phase voltages at its output.
- From three blocks, we get three phase voltages and then to measure these voltages, we have 2 types of measuring devices.
- First type of voltmeter will measure the phase voltages and you can see that all the three phases are connected to that instrument.
- Phase voltage is the potential difference between a single phase and neutral wire. Since no neutral wire is connected to this instrument and the meter will take the system's neutral wire to measure the voltages.
- The other meter measures the Line voltages. Line voltages are the potential difference between any two phases. At our meters input we have Line Voltages like AB, BC and CA.
RESULTS
- We have connected two different types of voltmeters in our system. One will give the graphical representation of phase voltages and the other will give the graph of Line voltages.
- The graph of phase voltages is given below in the image:
- The above graph is representing the phase voltages of all the three phases, which we have generated in our system.
- You can see that all the three phases are at an angle of 120 degrees to each other.
- The graph of line voltages is shown in the image given below:
- The above graph is showing the 3-phase line AC voltages.
- You can see that some cornered square wave is obtained at output. Corners are appearing in output wave due to switching of MOSFET transister, we have used in our project.
- A proper filter circuit can eliminate this flaw and a fine AC can been obtained at output.
Alright friends, that was all from today's post. I hope you guys have enjoyed this H Bridge Inverter. If you have any question then ask in comments and i will try my best to resolve the issue. For more tutorials stay tuned. Till next tutorial Take Care !!! :)