0% found this document useful (0 votes)
11 views

MATLAB Programming Lecture 6

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

MATLAB Programming Lecture 6

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

for internal use only Automation

Dr./ Essam and


Nabil
Drives

Lecture No.“6”
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction

MATLAB
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis
The Language of
Curve fitting Technical Computing
Symbolic math.

Signal processing
Prepared by:
Function m-file
Dr./ Essam Nabil
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human
Waveform Generation:
Programming
Machine Interface Consider generating data with a 1000 Hz
Introduction
sample frequency, for example. An appropriate
MATLAB Basics
time vector is:
Vectors & Arrays

Math. Functions

Polynomials t = 0 : 0.001 :1 ;
that represents time running from 0 to 1 s in
Common sequences waveforms:
MATLAB plotting

2-D & 3-D Graphics


steps of 1 ms.
Flow Control
1. Impulse function:
System analysis

Curve fitting
Delta=[1 zeros(1,99)];
Symbolic math.
plot(Delta)
Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human
Programming
2. Step function:
Machine Interface
Introduction
%Unit step generation u(t)
MATLAB Basics

Vectors & Arrays


y=ones(1,100);
Math. Functions plot(y)
Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis
%Step generation R=5u(t)
Curve fitting
y=5*ones(1,100);
Symbolic math.
plot(y)
Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface 2. Saw tooth wave signal:
Introduction
MATLAB Basics
%Generate saw tooth with 50Hz and sample
Vectors & Arrays
rate of 10kHz
Math. Functions
clear all, close all, clc
Polynomials

MATLAB plotting
fs=10000; %sample rate
2-D & 3-D Graphics
t=0:1/fs:1;
Flow Control
y=sawtooth(2*pi*50*t);
System analysis
plot(t,y)
Curve fitting
axis([ 0 0.2 -1 1])
Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface 3. Square wave signal:
Introduction
MATLAB Basics clear all, close all, clc
Vectors & Arrays t=0:0.1:100;
Math. Functions
y=square(t);
Polynomials
plot(t,y)
MATLAB plotting
axis([ 0 50 -2 2])
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB Example 1:
The Human
Programming
Machine Interface This example generates sawtooth waveform
Introduction with a repetition frequency of 3 Hz and a
MATLAB Basics sawtooth width of 0.1s. It has a signal
Vectors & Arrays
length of 2s and a 1 kHz sample rate:
Math. Functions

Polynomials
clear all, close all, clc
MATLAB plotting
fs=1000;
2-D & 3-D Graphics t = 0 : 1/fs : 2; % 1 kHz sample freq for
Flow Control
1 sec
System analysis
d = 0 : 1/3 : 2; % 3 Hz repetition freq
Curve fitting
y = pulstran(t,d,'tripuls',0.1,-1);
Symbolic math. plot(t,y)
Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB Example 2:
The Human
Programming
Machine Interface This example generates a periodic Gaussian
Introduction pulse signal at 10 kHz, with 50%
MATLAB Basics bandwidth. The pulse repetition frequency
Vectors & Arrays
is 1 kHz, sample rate is 50 kHz, and pulse
Math. Functions
train length is 10 msec.
Polynomials

MATLAB plotting
clear all, close all, clc
2-D & 3-D Graphics
t = 0 : 1/50000 : 0.01;
Flow Control
d =0 : 1/1000 : 0.01;
System analysis y = pulstran(t,d,'gauspuls',10000,0.5);
Curve fitting plot(t,y)
Symbolic math. axis([0 0.01 -2 2])
Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human 5. Sinc function:
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions
clear all, close all, clc
Polynomials
t=linspace(-5,5);
MATLAB plotting
y=sinc(t);
2-D & 3-D Graphics plot(t,y)
Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB
The Human
Programming
Generating test input signals for Lsim:
Machine Interface
Introduction gensig :returns a vector t of time
MATLAB Basics samples and the vector
Vectors & Arrays
u of signal values at these
Math. Functions
samples.
Polynomials

MATLAB plotting Syntax:


2-D & 3-D Graphics

Flow Control
>> [u,t] = gensig( type, periode)
System analysis
>> [u,t] = gensig(type, periode,Tf,Ts)
%generates test signal specified by its
Curve fitting

Symbolic math.
type, periode , time duration Tf and the
Signal processing
spacing Ts between the time samples t
of the signal .
Function m-file
The following types of signals are
MATLAB Simulink
available.
Final Test Industrial Electronics and Automatic Control Engineering
'sin'-------->Sine wave.
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB Example 1:
The Human
Programming
Machine Interface Generate a square wave with period 5
Introduction seconds, duration 30 seconds, and
MATLAB Basics sampling every 0.1 second.
Vectors & Arrays

Math. Functions [u,t] = gensig('square',5,30,0.1);


Polynomials plot(t,u)
MATLAB plotting axis([0 30 -1 2])
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB Example 2:
The Human
Programming
Machine Interface Generate a sine wave with period 5
Introduction seconds, duration 30 sec, and sampling
MATLAB Basics every 0.1 sec.
Vectors & Arrays

Math. Functions [u,t] = gensig('sin',5,30,0.1);


Polynomials plot(t,u)
MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Signal generation and processing


SIMATIC HMI
MATLAB Example 3:
The Human
Programming
Machine Interface Generate a periodic pulse wave with period
Introduction 5 seconds, duration 30 seconds, and
MATLAB Basics sampling every 0.1 second.
Vectors & Arrays

Math. Functions
[u,t] = gensig('pulse',5,30,0.1);
Polynomials
plot(t,u)
MATLAB plotting
axis([0 30 -1 1.5])
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB
The Human
Programming
1. Fourier analysis is useful for data
Machine Interface
Introduction
and signal analysis.
MATLAB Basics
2. It breaks down a signal into
Vectors & Arrays fundamental sinusoids of different
Math. Functions frequencies.
Polynomials 3. For periodic signals or vector data,
MATLAB plotting Fourier analysis is performed using
2-D & 3-D Graphics Fourier series.
Flow Control 4. For non-periodic signals or vector
System analysis data, Fourier analysis is performed
Curve fitting using Fourier transform.
Symbolic math.
5. For sampled vector data, Fourier
Signal processing
analysis is performed using the
Function m-file
discrete Fourier transform (DFT).
MATLAB Simulink
6. The fast Fourier transform (FFT) is an
Final Test
efficient algorithm for computing the
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB
The Human
Programming
Syntax:
Machine Interface
Introduction >> Y = fft(X) %returns the
MATLAB Basics

Vectors & Arrays


discrete Fourier transform
Math. Functions
(DFT) of vector X.
Polynomials

MATLAB plotting
>> Y = fft(X,n) %returns the n-point
2-D & 3-D Graphics
DFT of vector X. .
Flow Control

System analysis
Note:
Curve fitting
If the length of X is less than n, X is added
Symbolic math.
with zeros to length n.
Signal processing
If the length of X is greater than n, the
Function m-file
increase of X is truncated or
MATLAB Simulink
neglected.
Final Test  If X is a matrix, fft returns
Faculty of Electronic Engineering
the Fourier
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB Example :
The Human
Programming
Machine Interface Use of Fourier analysis to find the
Introduction frequency components of a noisy time
MATLAB Basics domain signal containing 50 Hz and 120 Hz
Vectors & Arrays
and corrupt it with some zero-mean random
Math. Functions
noise. Consider data sampled at 1000 Hz:
Polynomials
fs=1000;
MATLAB plotting
t = 0:1/fs:1;
2-D & 3-D Graphics
y = sin(2*pi*50*t)+sin(2*pi*120*t)+
Flow Control
2*randn(size(t));
System analysis
plot(y(1:100))
Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB
The Human
Programming
Y = fft(y,512); % Taking the
Machine Interface
512-point (FFT).
Introduction
MATLAB Basics
Pyy = Y.* conj(Y) / 512; %power
Vectors & Arrays
spectrum, a measurement
Math. Functions f = fs*(0:256)/512;
Polynomials plot(f,Pyy(1:257))
fundamental
MATLAB plotting components
2-D & 3-D Graphics have higher
Flow Control
power
spectrum
System analysis
magnitudes.
Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB
The Human
Programming
Magnitude and Phase of Transformed Data :
Machine Interface
Introduction MATLAB functions abs and angle are
MATLAB Basics used to calculate magnitude and phase.
Vectors & Arrays

Math. Functions Example :


Polynomials

MATLAB plotting
fs=100;
2-D & 3-D Graphics
t = 0:1/fs:9.99;
Flow Control
x = sin(2*pi*15*t) + sin(2*pi*40*t);
System analysis
y = fft(x); %computes DFT of the
data sequence.
Curve fitting

Symbolic math.
n=length(y);
Signal processing m = abs(y);
Function m-file p = unwrap(angle(y)); % unwrap to
MATLAB Simulink
remove phase jumps
Final Test Faculty of Electronic Engineering
greater than pi to
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Fourier Analysis
SIMATIC HMI
MATLAB
The Human subplot(2,1,1),
Programming
Machine Interface
plot(f,m)
Introduction
grid on
MATLAB Basics

Vectors & Arrays


xlabel('Frequency [Hz]')
Math. Functions ylabel('Magnitude')
Polynomials subplot(2,1,2)
MATLAB plotting plot(f,p*180/pi)
2-D & 3-D Graphics grid on
Flow Control xlabel('Frequency [Hz]')
System analysis ylabel('Phase [Degrees]')
Curve fitting

Symbolic math. Note:


Signal processing
The magnitude plot is perfectly
Function m-file
symmetrical about the Nyquist
frequency of 50 hertz.
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
 The digital filter design issue is influenced by such
Programming
Machine Interface factors as:
Introduction
MATLAB Basics
1.Filter Impulse Response Types.
Vectors & Arrays
 Finite Impulse Response (FIR) Filter, is
Math. Functions characterized by finite-duration impulse response.
Polynomials  Infinite Impulse Response (IIR) Filter, is
MATLAB plotting characterized by infinite-duration impulse response.
2-D & 3-D Graphics
2.Filter Type of Implementation and
Flow Control
Structure.
System analysis
Low Pass Filter. Band Pass
Curve fitting
Filter.
Symbolic math.

Signal processing
High Pass Filter. Band Stop
Filter.
Function m-file

MATLAB Simulink
3.Filter Design Strategies.
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
Elliptic (ellip) Chebyshev
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Filter Types and Structures:
Programming
Machine Interface
Introduction
Low Pass Filter:

Magnitude
MATLAB Basics

Vectors & Arrays Pass Stop


Math. Functions Band Band
Polynomials

MATLAB plotting
Fc Frequency
2-D & 3-D Graphics

Flow Control High Pass Filter:


System analysis

Curve fitting Magnitude


Symbolic math.
Stop Pass
Signal processing
Band Band
Function m-file

MATLAB Simulink Fc Frequency


Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Programming
Band Pass Filter:
Machine Interface

Magnitude
Introduction
MATLAB Basics
Stop Pass Stop
Vectors & Arrays
Band Band Band
Math. Functions

Polynomials
Fc1 Fc2
MATLAB plotting
Frequency
2-D & 3-D Graphics Band Stop Filter:
Flow Control

System analysis

Curve fitting Magnitude Pass Stop Pass


Symbolic math.
Band Band Band
Signal processing

Function m-file
Fc1 Fc2
MATLAB Simulink
Frequency
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Filter Design Specifications:
Programming
Machine Interface
Introduction
Band
MATLAB Basics Width
Vectors & Arrays

Math. Functions
Magnitude

Polynomials Stop Pass Stop


MATLAB plotting
Band Band Band

2-D & 3-D Graphics

Flow Control
Fc1 Fc2
System analysis
Frequency
Curve fitting
Ideal Filter Response Practical Filter Response
Symbolic math.

Signal processing Note:


Function m-file The band width cut-off frequencies are given in normalized form
MATLAB Simulink (Wp is a number between 0 and 1) as: [Fc1 Fc2]/Fmax
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Filter Design Steps:
Programming
Machine Interface
Introduction 1. Obtain the original or noisy signal to be filtered i.e. S
MATLAB Basics e.g. S= sin(2*pi*50*t)+ sin(2*pi*120*t)+ randn(size(t));
Vectors & Arrays

Math. Functions
2. Design the specified filter i.e. obtain a, b parameters.
n
Polynomials

MATLAB plotting B ( z ) k 0  n
b z n
b0  b1 z  1    bn z  n
H ( z)   n  1 n
; a0 1
A( z ) 1  a1 z    an z
 n
2-D & 3-D Graphics n
a z
Flow Control
k 0
System analysis

Curve fitting
3. Analyze the designed filter responses.
Symbolic math.
e.g. [H,W] = freqz(b,a,N); %frequency response analysis
The number of points N by default 512 if it isn’t written
Signal processing

Function m-file 4. Apply the given signal to the designed filter by:
MATLAB Simulink sf = filter(b, a, S); %SF is the filtered signal
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Filter Design Strategies:
Programming
Machine Interface
1. Elliptic (ellip):
Introduction
MATLAB Basics [b,a] = ellip(n,Rp,Rs,Wp) %designs an n-order low pass or band
Vectors & Arrays pass filter with normalized pass band edge frequency Wp, Rp dB of
Math. Functions
ripple in the pass band, and a stop band Rs dB down from the peak
value in the pass band.
Polynomials

MATLAB plotting [b,a] = ellip(n,Rp,Rs,Wp,'ftype') %designs a high pass or band


2-D & 3-D Graphics
stop filter, where the string 'ftype' is either:
'high' :for a high pass filter with normalized cut-off frequency Wp
Flow Control
'stop' :for a band stop filter with normalized stop band Wp = [w1 w2].
System analysis
 Zero-Pole-Gain form:
Curve fitting
[z,p,k] = ellip(n,Rp,Rs,Wp)
Symbolic math.
[z,p,k] = ellip(n,Rp,Rs,Wp,'ftype')
Signal processing
 Analog domain form:
Function m-file
[b,a] = ellip(n,Rp,Rs,Wp , ‘s’)
MATLAB Simulink
[b,a] = ellip(n,Rp,Rs,Wp,'ftype', ‘s’)
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Example :
Programming
Machine Interface clear all,close all,clc
Introduction
%Original Signal
MATLAB Basics
fs=100
Vectors & Arrays
t=(0:100)/fs;
Math. Functions
s=sin(2*pi*5*t)+sin(2*pi*15*t)+sin(2*pi*30*t);
Polynomials
plot(t,s),grid on
MATLAB plotting
title('Original signal')
2-D & 3-D Graphics
%Filter Design
Flow Control
n=4, Rp=0.1, Rs=40;
System analysis
[b,a] = ellip(n,Rp,Rs,[10 20]*2/fs);
Curve fitting
%Obtain Filtered signal
Symbolic math.
sf = filter(b,a,s);
Signal processing
figure
Function m-file
plot(t,sf),grid on
MATLAB Simulink
title('Filtered signal')
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
%Filter Response
Programming
Machine Interface [H,W]=freqz(b,a,512);
Introduction
mag=abs(H);
MATLAB Basics
freq=W*fs/(2*pi);
Vectors & Arrays
figure
Math. Functions

Polynomials
plot(freq,mag),grid on
xlabel('Freq (Hz)')
MATLAB plotting
ylabel('Magnitude')
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human 2. Chebyshev (cheby1, cheby2):
Programming
Machine Interface
Introduction
[b,a] = cheby1(n,Rp,Wp) %designs an n-order low pass or band
MATLAB Basics
pass filter with normalized pass band edge frequency Wp, Rp dB of
ripple in the pass band.
Vectors & Arrays

Math. Functions [b,a] = cheby1(n,Rp,Wp,'ftype') %designs a high pass or band


Polynomials
stop filter, where the string 'ftype' is either:
'high' :for a high pass filter with normalized cut-off frequency Wp
MATLAB plotting
'stop' :for a band stop filter with normalized stop band Wp = [w1 w2].
2-D & 3-D Graphics
 Zero-Pole-Gain form:
Flow Control
[z,p,k] = cheby1(n,Rp,Wp)
System analysis [z,p,k] = cheby1(n,Rp, Wp,'ftype')
Curve fitting
 Analog domain form:
Symbolic math.
[b,a] = cheby1(n,Rp, Wp, ‘s’)
Signal processing [b,a] = cheby1(n,Rp, Wp,'ftype', ‘s’)
Function m-file
Note: cheby2 has the same syntax above but uses Rs dB down from the
MATLAB Simulink
peak pass band value in stead of Rp.
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Programming
3. Butterworth (butter):
Machine Interface
Introduction [b,a] = butter(n, Wp) %designs an n-order low pass or band pass
MATLAB Basics filter with normalized pass band edge frequency Wp.
Vectors & Arrays
[b,a] = butter (n, Wp, 'ftype') %designs a high pass or band stop
Math. Functions filter, where the string 'ftype' is either:
Polynomials 'high' :for a high pass filter with normalized cut-off frequency Wp
MATLAB plotting 'stop' :for a band stop filter with normalized stop band Wp = [w1 w2].
2-D & 3-D Graphics  Zero-Pole-Gain form:
Flow Control [z,p,k] = butter (n, Wp)
System analysis [z,p,k] = butter (n, Wp,'ftype')
Curve fitting  Analog domain form:
Symbolic math. [b,a] =butter (n, Wp , ‘s’)
Signal processing [b,a] = butter (n, Wp ,'ftype', ‘s’)
Function m-file
Note: Butterworth filters are characterized by a magnitude response
MATLAB Simulink that is maximally flat in the pass band.
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Programming
4. Recursive digital filter (yulewalk):
Machine Interface
Introduction [b,a] = yulewalk(n,f,m)
MATLAB Basics

Vectors & Arrays

Math. Functions
f :is a vector of frequency points, specified in the range between 0
Polynomials
and 1. The first point of f must be 0 and the last point 1, with all
MATLAB plotting
intermediate points in increasing order. Duplicate frequency
2-D & 3-D Graphics points are allowed.
Flow Control m :is a vector containing the desired magnitude response at the
System analysis points specified in f.
Curve fitting

Symbolic math.
f and m must be the same length.
Signal processing
plot(f,m) displays the filter shape.
Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Digital Filter Design


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Example :
Introduction
MATLAB Basics clear all,close all,clc
Vectors & Arrays %Filter Design
Math. Functions f=[0 0.2 0.2 0.4 0.4 1];
Polynomials m=[0 0 1 1 0 0];
MATLAB plotting [b,a] = yulewalk(8,f,m);
2-D & 3-D Graphics %Filter Response
Flow Control [h,w] = freqz(b,a,128);
System analysis mag=abs(h);
Curve fitting freq=w/pi;
Symbolic math. plot(f,m,freq,mag,'k--','linewidth',2),grid on
Signal processing legend('Ideal' , 'yulewalk Designed')
Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

M-File Scripts and Functions


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction M-file programming
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials
Provides
MATLAB plotting The simplest kind of M-
2-D & 3-D Graphics Scripts
file. m-file Function m-file
extensibility to
They contain series of MATLAB
Flow Control
functions by
MATLAB commands,
System analysis
creating new
such as computations
Curve fitting functions
that you have to
Symbolic math. (program
perform repeatedly
Signal processing routines), that
from the command
accept input and
Function m-file
line.
MATLAB Simulink
return output
arguments.
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

User-defined Functions
SIMATIC HMI
MATLAB Functions look exactly like scripts, but
The Human
Programming
Machine Interface Functions must have a function
Introduction
declaration
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials Function declaration

MATLAB plotting Outputs Inputs Help file


2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

User-defined Functions
SIMATIC HMI
MATLAB
The Human
User-defined functions design
Programming
Machine Interface
Introduction
steps:
MATLAB Basics 1. From Menu bar select File-->New-->Function
Vectors & Arrays or open a new m-file editor.
Math. Functions 2. Define Function m-file declaration line as:
Inputs must be
Polynomials
specified
MATLAB plotting

2-D & 3-D Graphics function [x, y, z] = funName(in1, in2)


Flow Control

System analysis Must have the Function name should


Curve fitting reserved word: match m-file name
function
Symbolic math.
If more than one
Signal processing output, must be in
Function m-file brackets
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

User-defined Functions
SIMATIC HMI
MATLAB 3. Write Comment lines that describe detailed
The Human
Programming
Machine Interface help information a bout your function.
Introduction 4. Write all equations that required in your
MATLAB Basics function.
Vectors & Arrays 5. Save the Functions m-file with the same
Math. Functions name of the function. (Don’t change default
Polynomials
name)
Exampl
6. Now, your function is ready for using.
MATLAB plotting
e:
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

User-defined Functions
SIMATIC HMI
MATLAB
The Human
Programming Exampl
Machine Interface
Introduction function
e: Z=impedance(R,L,C,f)
MATLAB Basics

Vectors & Arrays


% Z=impedance(R,L,C,f) calculates impedance Z of the RLC
Math. Functions
%connected in series where R is the resistance in Ohms, L
Polynomials
% is the inductance in Henry, C is the capacitance in Farads
MATLAB plotting
% and F is the frequency in Hertz
2-D & 3-D Graphics
if (nargin <4)
Flow Control
error(‘Not enough input arguments')
System analysis
end;
Curve fitting
XC= 1/(2*pi*f*C);
Symbolic math.
XL = 2*pi*f*L;
Signal processing
Z = R + (XL-XC)*i;
Function m-file
end
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

End of Lecture No. “6”


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering

You might also like