SlideShare uma empresa Scribd logo
1 de 12
MATLAB Sample
Scripts
With Electrical Engineering
Applications
Shameer A Koya
Introduction
 This lecture we will do some practice on Basic
MATLAB Scripts.
 We will start with simple scripts and will discuss
some electrical engineering applications.
 More scripts including conditional statements will
be discussed in the next lecture.
 Please review lectures on basic input and output
commands.
Script 1
% Program to calculate Height of a Building
from time a stone takes to reach the basement.
% Use g=9.81and k=0.05
g=9.81;
k=0.05;
time= input (‘Enter the time taken: ‘);
height=g*(time+(exp(-k*time)-1)/k)/k;
disp(’Depth of well is ’)
disp(depth)
disp(’metres’)
Script 2
% Program to calculate the BMI (body mass index)
% Input your Height and Weight
weight = input('Type your weight (kg): ');
height = input('Type your height (m): ');
bmi = weight / height^2;
% Display the BMI
fprintf('Your Body Mass Index is %fn", bmi);
Script 3
% Program to calculate Electricity bill.
w = input('Enter power of your device (in watts):
');
h = input('Enter time (in hours): ');
r = input('Enter electricity rate (in dollars per
KWH): ');
ec = w * h/1000 * r;
disp(’Your Electricity bill is’)
Disp(ec)
Power transfer vs Load resistance curve
RL = 1:0.01:10;
Vs = 12;
Rs = 2.5;
P = (Vs^2*RL)./(RL+Rs).^2;
plot(RL,P)
xlabel('Load resistance')
ylabel('Power dissipated')
1 2 3 4 5 6 7 8 9 10
9
10
11
12
13
14
15
Load resistance
Powerdissipated
Curve fitting
% Second order curve fitting
%enter the input x and y vectors
x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];
y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];
n = 2;
p = polyfit( x, y, n ) %Find the best quadratic fit to the
data
xi = linspace(0,1,100);
yi = polyval(p, xi); % evaluate the polynomial
plot(x,y,’-o’, xi, yi, ‘-’)
xlabel(‘x’), ylabel(‘y = f(x)’)
title(‘Second Order Curve Fitting Example’)
Series RLC circuit
 % Program to plot current vs frequency semilog plot of a
series RLC circuit
 R = input('Enter value of resistance in ohms:');
 L = input('Enter value of inductance in Henary:');
 C = input('Enter value of capacitance in Farads:');
 V = input('Supply voltage in volts:')
 f = 0 : 1: 1000000;
 XL = 2 * pi .* f * L;
 XC = 1./(2 * pi .* f * C);
 Z = (R^2-(XL-XC).^2).^0.5;
 I = V ./ Z;
 semilogx(f,real(I));
 title('Current Vs Log frequency plot' );
 xlabel('fLogf');
 ylabel('Current in A');
8
DC Machines Characteristics
MATLAB program to calculate the characteristics of separately excited DC motor.
%Required parameters are Ra, k, Rf, Vt, Ns, k, Vf
clc;
Ra=0.5 ;Rf=250;Vt=250;k=2;Vf=250;
T = 0:100; % vector of torque
If=Vf/Rf;
Ia=T/k;
Ea=Vt-Ia*Ra;
w=Ea/k/If;
N=w*60/2/pi;
plot(T,N)
xlabel('Torque')
ylabel('Speed in RPM')
title('Speed-Torque Curve')
plot(T,Ia)
xlabel('Torque')
ylabel('Armature Current')
study the characteristics of shunt and series DC motors
0 10 20 30 40 50 60 70 80 90 100
0
5
10
15
20
25
30
35
40
45
50
Torque
Armaturecurrent
Induction Machine
Torque-Speed Curve for a squirrel cage Induction Motor
 Ns=1500; % Synchronous speed;
 R1=15.6 ;R2=14;X1=18; X2=23;Xm=260;Vt=400/sqrt(3);
 s = 0.002:0.002:1; % vector of slip
 N = Ns.*(1-s); % Speed, in RPM
 Ws = 2*pi*Ns/60; % Synchronous speed in rad/sec
 Rr = R2./ s; % Rotor resistance
 Zr = j*X2 + Rr; % Total rotor impedance
 Za = j*Xm*Zr./(j*Xm+Zr); % Air-gap impedance
 Zt = R1 + j*X1 +Za; % Terminal impedance
 Ia = Vt ./ Zt; % Terminal Current
 I2 = j*Xm*Ia./(j*Xm+Zr); % Rotor Current
 Pag = 3* (abs(I2)).^2.*Rr; % Air-Gap Power
 Pm = Pag.* (1-s); % Converted Power
 Trq = Pag/ Ws; % Developed Torque
 subplot(2,1,1)
 plot(N, Trq)
 xlabel('Speed in RPM')
 ylabel('Torque (Nm)')
 subplot(2,1,2)
 plot(Ia, Trq)
 xlabel('Load Current')
 ylabel('Torque (Nm)')
Synchronous Motor
%M-file to calculate and plot the terminal voltage % of a synchronous generator as a function of load
% for power factors of 0.8 lagging, 1.0, and 0.8 leading.
% Define values for this generator
EA = 277; % Internal gen voltage
I = 0:2:240; % Current values (A)
R = 0.03; % R (ohms)
X = 0.25; % XS (ohms)
% Calculate the voltage for the lagging PF case
VP_lag = sqrt( EA^2 - (X.*I.*0.8 - R.*I.*0.6).^2 )- R.*I.*0.8 - X.*I.*0.6;
VT_lag = VP_lag .* sqrt(3);
% Calculate the voltage for the leading PF case
VP_lead = sqrt( EA^2 - (X.*I.*0.8 + R.*I.*0.6).^2 )- R.*I.*0.8 + X.*I.*0.6;
VT_lead = VP_lead .* sqrt(3);
% Calculate the voltage for the unity PF case
VP_unity = sqrt( EA^2 - (X.*I).^2 );
VT_unity = VP_unity .* sqrt(3);
% Plot the terminal voltage versus load
plot(I,abs(VT_lag),'b');
hold on;
plot(I,abs(VT_unity),'k--');
plot(I,abs(VT_lead),'r:');
legend('0.8 PF lagging','1.0 PF','0.8 PF leading');
grid on;
hold off;
TransmissionLineVoltageRegulation
12
% INPUT THE LINE PARAMETERS
Z = input ('Enter Line Impedence, Z line: ');
Y = input ('Enter Line Admittance, Y line: ');
P = input ('Enter Recieving end Power, Pr: ');
VL = input ('Enter Recieving end Voltage, Vr: ');
PF = input ('Enter Recieving end Power factor, pfr: ');
% CALCULATION OF ABCD CONSTANTS
A=(1+Z*Y/2);
D=A;
B=Z;
C=Y*(1+Z*Y/4);
A1=acos(PF);
VR=VL/sqrt(3);
% CALCULATION OF RECEIVING END CURRENT
IR= P/(sqrt(3)*VL*PF);
IR=IR*(cos(A1)-j*sin(A1));
% CALCULATION OF SENDING END VOLTAGE
VS=A*VR+ B*IR;
VSA=abs(VS);
VSL=sqrt(3)*VSA;
% CALCULATION OF VOLTAGE REGULATION
VVRR=(VSA/abs(A)-VR)/VR;
VREGULATION = VVRR*100;
% CALCULATION OF SENDING END CURRENT
IS=C*VR+D*IR;
ISA=abs(IS);
% CALCULATION OF PHASE ANGLE
PA=angle(VS)*180/pi;
PB = angle (IS) *180/pi;
PS=(PA-PB)*pi/180;
PFS=cos(PS);
PS=sqrt(3)*ISA*VSL*PFS; % CALCULATION OF SENDING END POWER
EFFICIENCY=(P/PS)* 100; % CALCULATION OF EFFICIENCY
fprintf ('Efficiency is %dn', EFFICIENCY);
fprintf ('Voltage Regulation is %d n', VREGULATION);

Mais conteúdo relacionado

Mais procurados

The 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systemsThe 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systemsmanishpatel_79
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABMartin Wachiye Wafula
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Introduction to simulink (1)
Introduction to simulink (1)Introduction to simulink (1)
Introduction to simulink (1)Memo Love
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processingLiving Online
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gatesRakesh kumar jha
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabMohan Raj
 
Z trasnform & Inverse Z-transform in matlab
Z trasnform & Inverse Z-transform in matlabZ trasnform & Inverse Z-transform in matlab
Z trasnform & Inverse Z-transform in matlabHasnain Yaseen
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabVidhyaSenthil
 
Embedded Programming for Quadcopters
Embedded Programming for QuadcoptersEmbedded Programming for Quadcopters
Embedded Programming for QuadcoptersRyan Boland
 
Comparative Study and Performance Analysis of different Modulation Techniques...
Comparative Study and Performance Analysis of different Modulation Techniques...Comparative Study and Performance Analysis of different Modulation Techniques...
Comparative Study and Performance Analysis of different Modulation Techniques...Souvik Das
 
1.Basics of Signals
1.Basics of Signals1.Basics of Signals
1.Basics of SignalsINDIAN NAVY
 

Mais procurados (20)

The 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systemsThe 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systems
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Matlab
MatlabMatlab
Matlab
 
Introduction to simulink (1)
Introduction to simulink (1)Introduction to simulink (1)
Introduction to simulink (1)
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processing
 
Convolution
ConvolutionConvolution
Convolution
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
 
Bit Error rate of QAM
Bit Error rate of QAMBit Error rate of QAM
Bit Error rate of QAM
 
Actel fpga
Actel fpgaActel fpga
Actel fpga
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Z trasnform & Inverse Z-transform in matlab
Z trasnform & Inverse Z-transform in matlabZ trasnform & Inverse Z-transform in matlab
Z trasnform & Inverse Z-transform in matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Embedded Programming for Quadcopters
Embedded Programming for QuadcoptersEmbedded Programming for Quadcopters
Embedded Programming for Quadcopters
 
Embedded System-design technology
Embedded System-design technologyEmbedded System-design technology
Embedded System-design technology
 
Comparative Study and Performance Analysis of different Modulation Techniques...
Comparative Study and Performance Analysis of different Modulation Techniques...Comparative Study and Performance Analysis of different Modulation Techniques...
Comparative Study and Performance Analysis of different Modulation Techniques...
 
1.Basics of Signals
1.Basics of Signals1.Basics of Signals
1.Basics of Signals
 

Destaque

Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab ScriptsShameer Ahmed Koya
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABShameer Ahmed Koya
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1Shameer Ahmed Koya
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2Shameer Ahmed Koya
 
Matlab solving rlc circuit
Matlab solving rlc circuitMatlab solving rlc circuit
Matlab solving rlc circuitAmeen San
 
Matlab assignment help
Matlab assignment helpMatlab assignment help
Matlab assignment helpAnderson Silva
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functionsmatlab Content
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsShameer Ahmed Koya
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshopVinay Kumar
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2Shameer Ahmed Koya
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlabTUOS-Sam
 
Journal Club - Best Practices for Scientific Computing
Journal Club - Best Practices for Scientific ComputingJournal Club - Best Practices for Scientific Computing
Journal Club - Best Practices for Scientific ComputingBram Zandbelt
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4Shameer Ahmed Koya
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While LoopHock Leng PUAH
 
Circuit analysis i with matlab computing and simulink sim powersystems modeling
Circuit analysis i with matlab computing and simulink sim powersystems modelingCircuit analysis i with matlab computing and simulink sim powersystems modeling
Circuit analysis i with matlab computing and simulink sim powersystems modelingIndra S Wahyudi
 
Cruise control simulation using matlab
Cruise control simulation using matlabCruise control simulation using matlab
Cruise control simulation using matlabHira Shaukat
 

Destaque (20)

Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab Scripts
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2
 
Matlab solving rlc circuit
Matlab solving rlc circuitMatlab solving rlc circuit
Matlab solving rlc circuit
 
Dsp file
Dsp fileDsp file
Dsp file
 
Matlab assignment help
Matlab assignment helpMatlab assignment help
Matlab assignment help
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functions
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Matlab time series example
Matlab time series exampleMatlab time series example
Matlab time series example
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
Journal Club - Best Practices for Scientific Computing
Journal Club - Best Practices for Scientific ComputingJournal Club - Best Practices for Scientific Computing
Journal Club - Best Practices for Scientific Computing
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 
Circuit analysis i with matlab computing and simulink sim powersystems modeling
Circuit analysis i with matlab computing and simulink sim powersystems modelingCircuit analysis i with matlab computing and simulink sim powersystems modeling
Circuit analysis i with matlab computing and simulink sim powersystems modeling
 
Cruise control simulation using matlab
Cruise control simulation using matlabCruise control simulation using matlab
Cruise control simulation using matlab
 

Semelhante a MATLAB Scripts - Examples

90981041 control-system-lab-manual
90981041 control-system-lab-manual90981041 control-system-lab-manual
90981041 control-system-lab-manualGopinath.B.L Naidu
 
Ece 415 control systems, fall 2021 computer project 1
Ece 415 control systems, fall 2021 computer project  1 Ece 415 control systems, fall 2021 computer project  1
Ece 415 control systems, fall 2021 computer project 1 ronak56
 
PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)Tsuyoshi Horigome
 
PWM Buck Converter using Average Model
PWM Buck Converter using Average ModelPWM Buck Converter using Average Model
PWM Buck Converter using Average ModelTsuyoshi Horigome
 
Electrical Engineering Assignment Help
Electrical Engineering Assignment HelpElectrical Engineering Assignment Help
Electrical Engineering Assignment HelpEdu Assignment Help
 
「SPICEの活用方法」セミナー資料(28JAN2011) PPT
「SPICEの活用方法」セミナー資料(28JAN2011) PPT「SPICEの活用方法」セミナー資料(28JAN2011) PPT
「SPICEの活用方法」セミナー資料(28JAN2011) PPTTsuyoshi Horigome
 
Chapter two Part two.pptx
Chapter two Part two.pptxChapter two Part two.pptx
Chapter two Part two.pptxAbdalleAidrous
 
PSpiceで位相余裕度シミュレーション
PSpiceで位相余裕度シミュレーション PSpiceで位相余裕度シミュレーション
PSpiceで位相余裕度シミュレーション Tsuyoshi Horigome
 
Matlab fair-record-model
Matlab fair-record-modelMatlab fair-record-model
Matlab fair-record-modelajaydev1111
 
PID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachPID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachWaleed El-Badry
 
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf Loren Schwappach
 
Design of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceDesign of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceIAEME Publication
 
Modeling of Self Excited Induction Generator
Modeling of Self Excited Induction GeneratorModeling of Self Excited Induction Generator
Modeling of Self Excited Induction GeneratorANURAG YADAV
 
Chapter 08
Chapter 08Chapter 08
Chapter 08Tha Mike
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Alamgir Hossain
 

Semelhante a MATLAB Scripts - Examples (20)

90981041 control-system-lab-manual
90981041 control-system-lab-manual90981041 control-system-lab-manual
90981041 control-system-lab-manual
 
Ece 415 control systems, fall 2021 computer project 1
Ece 415 control systems, fall 2021 computer project  1 Ece 415 control systems, fall 2021 computer project  1
Ece 415 control systems, fall 2021 computer project 1
 
PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)
 
PWM Buck Converter using Average Model
PWM Buck Converter using Average ModelPWM Buck Converter using Average Model
PWM Buck Converter using Average Model
 
ACS 22LIE12 lab Manul.docx
ACS 22LIE12 lab Manul.docxACS 22LIE12 lab Manul.docx
ACS 22LIE12 lab Manul.docx
 
Electrical Engineering Assignment Help
Electrical Engineering Assignment HelpElectrical Engineering Assignment Help
Electrical Engineering Assignment Help
 
「SPICEの活用方法」セミナー資料(28JAN2011) PPT
「SPICEの活用方法」セミナー資料(28JAN2011) PPT「SPICEの活用方法」セミナー資料(28JAN2011) PPT
「SPICEの活用方法」セミナー資料(28JAN2011) PPT
 
Psms lab manual
Psms lab manualPsms lab manual
Psms lab manual
 
Chapter two Part two.pptx
Chapter two Part two.pptxChapter two Part two.pptx
Chapter two Part two.pptx
 
PSpiceで位相余裕度シミュレーション
PSpiceで位相余裕度シミュレーション PSpiceで位相余裕度シミュレーション
PSpiceで位相余裕度シミュレーション
 
Matlab fair-record-model
Matlab fair-record-modelMatlab fair-record-model
Matlab fair-record-model
 
PID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachPID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB Approach
 
Abdul Haseeb
Abdul HaseebAbdul Haseeb
Abdul Haseeb
 
Quiz
QuizQuiz
Quiz
 
Final Project
Final ProjectFinal Project
Final Project
 
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
 
Design of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceDesign of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospace
 
Modeling of Self Excited Induction Generator
Modeling of Self Excited Induction GeneratorModeling of Self Excited Induction Generator
Modeling of Self Excited Induction Generator
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report
 

Último

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 

Último (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

MATLAB Scripts - Examples

  • 1. MATLAB Sample Scripts With Electrical Engineering Applications Shameer A Koya
  • 2. Introduction  This lecture we will do some practice on Basic MATLAB Scripts.  We will start with simple scripts and will discuss some electrical engineering applications.  More scripts including conditional statements will be discussed in the next lecture.  Please review lectures on basic input and output commands.
  • 3. Script 1 % Program to calculate Height of a Building from time a stone takes to reach the basement. % Use g=9.81and k=0.05 g=9.81; k=0.05; time= input (‘Enter the time taken: ‘); height=g*(time+(exp(-k*time)-1)/k)/k; disp(’Depth of well is ’) disp(depth) disp(’metres’)
  • 4. Script 2 % Program to calculate the BMI (body mass index) % Input your Height and Weight weight = input('Type your weight (kg): '); height = input('Type your height (m): '); bmi = weight / height^2; % Display the BMI fprintf('Your Body Mass Index is %fn", bmi);
  • 5. Script 3 % Program to calculate Electricity bill. w = input('Enter power of your device (in watts): '); h = input('Enter time (in hours): '); r = input('Enter electricity rate (in dollars per KWH): '); ec = w * h/1000 * r; disp(’Your Electricity bill is’) Disp(ec)
  • 6. Power transfer vs Load resistance curve RL = 1:0.01:10; Vs = 12; Rs = 2.5; P = (Vs^2*RL)./(RL+Rs).^2; plot(RL,P) xlabel('Load resistance') ylabel('Power dissipated') 1 2 3 4 5 6 7 8 9 10 9 10 11 12 13 14 15 Load resistance Powerdissipated
  • 7. Curve fitting % Second order curve fitting %enter the input x and y vectors x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1]; y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2]; n = 2; p = polyfit( x, y, n ) %Find the best quadratic fit to the data xi = linspace(0,1,100); yi = polyval(p, xi); % evaluate the polynomial plot(x,y,’-o’, xi, yi, ‘-’) xlabel(‘x’), ylabel(‘y = f(x)’) title(‘Second Order Curve Fitting Example’)
  • 8. Series RLC circuit  % Program to plot current vs frequency semilog plot of a series RLC circuit  R = input('Enter value of resistance in ohms:');  L = input('Enter value of inductance in Henary:');  C = input('Enter value of capacitance in Farads:');  V = input('Supply voltage in volts:')  f = 0 : 1: 1000000;  XL = 2 * pi .* f * L;  XC = 1./(2 * pi .* f * C);  Z = (R^2-(XL-XC).^2).^0.5;  I = V ./ Z;  semilogx(f,real(I));  title('Current Vs Log frequency plot' );  xlabel('fLogf');  ylabel('Current in A'); 8
  • 9. DC Machines Characteristics MATLAB program to calculate the characteristics of separately excited DC motor. %Required parameters are Ra, k, Rf, Vt, Ns, k, Vf clc; Ra=0.5 ;Rf=250;Vt=250;k=2;Vf=250; T = 0:100; % vector of torque If=Vf/Rf; Ia=T/k; Ea=Vt-Ia*Ra; w=Ea/k/If; N=w*60/2/pi; plot(T,N) xlabel('Torque') ylabel('Speed in RPM') title('Speed-Torque Curve') plot(T,Ia) xlabel('Torque') ylabel('Armature Current') study the characteristics of shunt and series DC motors 0 10 20 30 40 50 60 70 80 90 100 0 5 10 15 20 25 30 35 40 45 50 Torque Armaturecurrent
  • 10. Induction Machine Torque-Speed Curve for a squirrel cage Induction Motor  Ns=1500; % Synchronous speed;  R1=15.6 ;R2=14;X1=18; X2=23;Xm=260;Vt=400/sqrt(3);  s = 0.002:0.002:1; % vector of slip  N = Ns.*(1-s); % Speed, in RPM  Ws = 2*pi*Ns/60; % Synchronous speed in rad/sec  Rr = R2./ s; % Rotor resistance  Zr = j*X2 + Rr; % Total rotor impedance  Za = j*Xm*Zr./(j*Xm+Zr); % Air-gap impedance  Zt = R1 + j*X1 +Za; % Terminal impedance  Ia = Vt ./ Zt; % Terminal Current  I2 = j*Xm*Ia./(j*Xm+Zr); % Rotor Current  Pag = 3* (abs(I2)).^2.*Rr; % Air-Gap Power  Pm = Pag.* (1-s); % Converted Power  Trq = Pag/ Ws; % Developed Torque  subplot(2,1,1)  plot(N, Trq)  xlabel('Speed in RPM')  ylabel('Torque (Nm)')  subplot(2,1,2)  plot(Ia, Trq)  xlabel('Load Current')  ylabel('Torque (Nm)')
  • 11. Synchronous Motor %M-file to calculate and plot the terminal voltage % of a synchronous generator as a function of load % for power factors of 0.8 lagging, 1.0, and 0.8 leading. % Define values for this generator EA = 277; % Internal gen voltage I = 0:2:240; % Current values (A) R = 0.03; % R (ohms) X = 0.25; % XS (ohms) % Calculate the voltage for the lagging PF case VP_lag = sqrt( EA^2 - (X.*I.*0.8 - R.*I.*0.6).^2 )- R.*I.*0.8 - X.*I.*0.6; VT_lag = VP_lag .* sqrt(3); % Calculate the voltage for the leading PF case VP_lead = sqrt( EA^2 - (X.*I.*0.8 + R.*I.*0.6).^2 )- R.*I.*0.8 + X.*I.*0.6; VT_lead = VP_lead .* sqrt(3); % Calculate the voltage for the unity PF case VP_unity = sqrt( EA^2 - (X.*I).^2 ); VT_unity = VP_unity .* sqrt(3); % Plot the terminal voltage versus load plot(I,abs(VT_lag),'b'); hold on; plot(I,abs(VT_unity),'k--'); plot(I,abs(VT_lead),'r:'); legend('0.8 PF lagging','1.0 PF','0.8 PF leading'); grid on; hold off;
  • 12. TransmissionLineVoltageRegulation 12 % INPUT THE LINE PARAMETERS Z = input ('Enter Line Impedence, Z line: '); Y = input ('Enter Line Admittance, Y line: '); P = input ('Enter Recieving end Power, Pr: '); VL = input ('Enter Recieving end Voltage, Vr: '); PF = input ('Enter Recieving end Power factor, pfr: '); % CALCULATION OF ABCD CONSTANTS A=(1+Z*Y/2); D=A; B=Z; C=Y*(1+Z*Y/4); A1=acos(PF); VR=VL/sqrt(3); % CALCULATION OF RECEIVING END CURRENT IR= P/(sqrt(3)*VL*PF); IR=IR*(cos(A1)-j*sin(A1)); % CALCULATION OF SENDING END VOLTAGE VS=A*VR+ B*IR; VSA=abs(VS); VSL=sqrt(3)*VSA; % CALCULATION OF VOLTAGE REGULATION VVRR=(VSA/abs(A)-VR)/VR; VREGULATION = VVRR*100; % CALCULATION OF SENDING END CURRENT IS=C*VR+D*IR; ISA=abs(IS); % CALCULATION OF PHASE ANGLE PA=angle(VS)*180/pi; PB = angle (IS) *180/pi; PS=(PA-PB)*pi/180; PFS=cos(PS); PS=sqrt(3)*ISA*VSL*PFS; % CALCULATION OF SENDING END POWER EFFICIENCY=(P/PS)* 100; % CALCULATION OF EFFICIENCY fprintf ('Efficiency is %dn', EFFICIENCY); fprintf ('Voltage Regulation is %d n', VREGULATION);