Free Essay

Matlab

In:

Submitted By liu33123
Words 1592
Pages 7
Lab 2: Linear Time-Invariant Systems

In this experiment, you will study the output response of linear time-invariant (LTI) systems using MATLAB, and learn how to use MATLAB to implement the convolution sum. You will also investigate the properties of LTI systems. The objective of this experiment is: (1) to study how to compute the output of LTI systems, and (2) to study the properties of discrete-time LTI systems.

1. Introduction to Linear Time-Invariant (LTI) Systems In discrete time, linearity provides the ability to completely characterize a system in terms of its response [pic] to a signal of the form [pic] for all [pic]. If a linear system is also time-invariant, then the responses [pic] will become [pic]. The combination of linearity and time-invariance therefore allows a system to be completely described by its impulse response [pic]. The output of the system [pic] is related to the input [pic] through the convolution sum as follows: [pic] Similarly, the output [pic] of a continuous-time LTI system is related to the input [pic] and the impulse response [pic] through the following convolution integral: [pic] The convolution of discrete-time sequences [pic] and [pic] represented mathematically by the expression given in [pic] can be viewed pictorially as the operation of flipping the time axis of the sequence [pic] and shifting it by [pic] samples, then multiplying [pic] by[pic] and summing the resulting product sequence over [pic]. This picture arises from the properties of linearity and time-invariance for discrete-time systems. The signal [pic] can be constructed from a linear superposition of delayed and scaled impulses, i.e. [pic] [pic] Since an LTI system can be represented by its response to a single impulse, the output of an LTI system corresponds to the superposition [pic]. Mathematically, this results in the convolution sum. It can also prove that (1) is equivalent to the following equation: [pic] [pic]

2. Computing the Output of an LTI System Using MATLAB In this section, you will learn how to use the MATLAB function conv to compute the output of LTI systems. The MATLAB function conv computes the convolution sum. Assuming that [pic] and [pic] are finite-length sequences. If [pic] is nonzero on the interval[pic]and [pic] is nonzero only on the interval [pic], then y[n] can be nonzero only on the interval [pic] [pic] This means that conv need only compute y[n] for the [pic] samples on this interval. If x is an [pic]-dimensional vector containing x[n] on the interval [pic] and h is an [pic]-dimensional vector containing h[n] on the interval [pic], then y = conv(h, x) returns in y the [pic] samples of y[n] on the interval in (5). However, conv does not return the indices of samples of y[n] stored in y, which makes sense because the intervals of x and h are not input to conv. a) Consider the finite-length signal, [pic] Analytically determine [pic], where [pic] denotes the convolution operation. b) Compute the nonzero samples of [pic] using conv. Plot your results using stem. The following code may help you: nx = 0:5; %interval of [pic] x = [1 1 1 1 1 1]; % [pic] figure, stem(nx, x) %plot [pic] y = conv(x, x); % [pic] ny = 0 : ? ; % interval of [pic], you should set a value for “?” figure, stem(ny, y) % plot [pic] What is the length of y[n]? Does the plot agree with the signal determined in (a)? c) Consider the finite-length signal, [pic] Analytically determine [pic]. Next, using conv to compute [pic]. Plot your results using stem. Is the system causal? d) Now consider the signal [pic], where[pic]. Compute [pic] using conv. Plot your result using stem. How does [pic] compare to the signal [pic] derived in (c)? Is this system causal? e) Since the MATLAB function conv does not keep track of the time indices of the sequences that are convolved, some extra book keeping is required to determine the proper indices for the result of the conv function. For the sequences:
[pic]
construct vectors h and x with proper indices. Define [pic] and compute y = conv(h,x). Determine the proper time indexing for y and plot the result. The following code may help you. x = [0, 1, 0, 1, 0]; % [pic] nx = –1 : 3; % interval of [pic] h = [2, 0, –2]; % [pic] nh = 0 : 2; -1:1 % interval of [pic] y = conv(x, h); % convolution ny = ?: ?; % interval of y, you must assign values to the “?”s figure, stem(ny, y) % plot [pic] f) Verify your result in (e) analytically. g) Consider the following signal and impulse response, [pic] If you wish to compute the convolved output using y = conv(h,x), you must deal appropriately with the infinite length of both h[n] and x[n]. Store in the vector x the value of x[n] for[pic]and store in the vector h the values of h[n] for [pic]. Now calculate y = conv(h,x) using MATLAB. Since you have truncated both [pic] and [pic], argue that only a portion of the output of y will be valid. Specify which values in the output are valid and which are not.

3. Properties of Discrete-Time LTI Systems In this section, you will verify the commutative, associative and distributive properties of convolution for a specific set of signals. In addition, you will examine the implications of these properties for series and parallel connections of LTI systems. a) Consider the following three signals: [pic] [pic] [pic] Define the MATLAB vector x to represent [pic] on the interval [pic], and the vectors h1 and h2 to represent [pic] and [pic] for [pic]. Also define nx to be an appropriate index vector for x[n] and nh for h1[n] and [pic]. Make appropriately labeled plots of all the signals using stem. b) The commutative property states that the result of a convolution is the same regardless of the order of the operands, i.e. [pic] . (6) This implies that, if [pic]is the input and [pic] is the impulse response, the output is equivalent to that of an LTI system with impulse response [pic] and input [pic]. Use conv with h1 and x to verify this property. Is the output of conv the same regardless of the order of the input arguments? c) Convolution is also distributive. This means that [pic]. (7) This implies that the output of two LTI systems connected in parallel is the same as one system whose impulse response is the sum of the impulse responses of the parallel systems. Figure 1 illustrates this property.

[pic] Figure 1 Distributive property of convolution Verify the distributive property using x, h1 and h2. Compute the sum of the outputs of the two LTI systems with impulse responses [pic] and [pic] when [pic] is the input. Compare this with the output of the LTI system whose impulse response is [pic] when the input is [pic]. Do these two methods of computing the output give the same results? d) Convolution also possesses the associative property, i.e., [pic] (8) This property implies that the result of processing a signal with a series of LTI systems is equivalent to processing the signal with a single LTI system whose impulse response is the convolution of all the individual impulse responses of the connected systems. Figure 2 illustrates this property for the case of two LTI systems connected in series.

[pic]

Figure 2 Associative property of convolution

Use the following steps to verify the associative property using x, h1 and h2: • Let w[n] be the output of the LTI system with impulse response [pic], as shown in Fig. 2. Compute w[n] by convolving [pic] and [pic]. • Compute the output [pic] of the whole system by convolving [pic] with [pic]. • Find the impulse response [pic]. • Convolve [pic] with[pic]to get the output [pic]. Compare [pic] and [pic]. Are they the same?

4. Linearity and Time-Invariance In this section, you will become more familiar with the system properties of linearity and time-invariance. An important property of discrete-time LTI systems is that if [pic] is the response to the unit impulse [pic], then the response of the system [pic] to any [pic] is determined by the convolution sum. An analogous property holds for continuous-time LTI systems. Consider the systems System 1: [pic] System 2: [pic] a) Consider these three input signals: [pic] [pic] [pic] For System 1, store in w1, w2, and w3 the responses to these three inputs. Use stem to plot the four functions represented by w1, w2, w3 and w1+2*w2. The following code may help you. x1 = [1 0 0 0 0 0]; % define [pic] x2 = [0 1 0 0 0 0]; % define [pic] x3 = [1 2 0 0 0 0]; % define [pic] h = ?; % impulse response of [pic] w1 = conv(h, x1); % response of [pic] w2 = conv(h, x2); % response of [pic] w3 = conv(h, x3); % response of [pic] nw = 0 : ?; % interval of [pic] figure, stem(nw, w1) % plot [pic] figure, stem(nw, w2) % plot[pic] figure, stem(nw, w3) % plot [pic] figure, stem(nw, w1+2*w2) % plot [pic] b) Is System 1 linear? Is the system time-invariant? c) Repeat (a) for System 2. Is System 2 linear? Is it time-invariant? The following code may help you. ny = 0 : 5; % interval of [pic] y1 = cos(x1); % response of [pic] y2 = cos(x2); % response of [pic] y3 = cos(x3); % response of [pic]

Similar Documents

Free Essay

Forecasting Models

...MATLAB® Getting Started Guide R2011b How to Contact MathWorks Web Newsgroup www.mathworks.com/contact_TS.html Technical Support www.mathworks.com comp.soft-sys.matlab suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. MATLAB® Getting Started Guide © COPYRIGHT 1984–2011 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights...

Words: 36443 - Pages: 146

Free Essay

Human Step Detection and Counting with a Microphone (June 2015)

...alternative use of sensors for detecting human movements such as footsteps and that is done for various reasons such as security or just for lightning a lamp automatically. We developed a Simulink model in Matlab to simulate a system that analyses the footsteps of three 25 years old men. Those men had different heights and weights. The data were recorded and analyzed using filtering and conditioning blocks of Matlab. The System collected 3 sets of steps. The first set had 5 steps with 5 detections. The second set had 8 steps with 3 detection and the third set had 4 steps with 1 detections. In total, there were 17 steps where 9 steps were detected. I. C. Procedure During the first part of the experiment, the footsteps were recorded on the main corridor of the first floor of the house 21, located in the University of Kristianstad. We also recorded the steps at our respective houses. The experiment was carried on a floor without carpet to allow a better collection of the data. This procedure was repeated several times, until satisfactory data without much noisy could be acquired. INTRODUCTION T HE objective of this work was to detect the steps of a person using a microphone array embedded in our computer together with the Simulink library of Matlab. We have some background of the idea after reading a few articles regarding this type of experiments. Fig. 1. Simulink models used to record the steps In the articles we read, the experiment...

Words: 1833 - Pages: 8

Free Essay

Matlab

...matlab Probleme teoretice ale programării în MATLAB 1. Tipul de dată numeric. 2. Tipul de dată logic. 3. Tipul de dată caracter, şir de caractere. 4. Tipul de dată data şi ora. 5. Tipul de dată structură. 6. Tipul de dată celulă. 7. Expresii numerice şi logice în MATLAB. 8. Variabile în MATLAB. Definiţie şi tipuri de variabile. 9. Crearea variabilelor şi reguli de declarare a lor. 10. Cuvinte cheie. 11. operatori şi reguli de precedenţă. 12. Constante speciale în MATLAB. 13. Matrici, vectori, scalari. Funcţia size. Crearea cu operatorul []. 14. Crearea matricelor cu funcţii speciale. 15. Concatenarea matricelor. 16. Crearea matricelor cu blocuri pe diagonală 17. Accesarea directă şi liniară a matricelor. 18. Accesarea multiplă (cu operatorul :). 19. Accesarea logic indexată. 20. Funcţii de matrici şi funcţii de manipulare a matricelor. 21. Comanda de atribuire. Comenzi de întrerupere a execuţiei buclelor. 22. Comenzi de execuţie condiţionată. 23. Comenzi de execuţie a ciclurilor. 24. M-programe (M-scripturi şi M-funcţii) 25. Erori. Exportul şi importul datelor. Listarea pe ecran. 26. Depanarea M-programelor. 27. Utilizarea eficientă a memoriei. 28. Analiza timpului de execuţie şi principalele tehnici de reducere a timpului de execuţie. 29. Modelarea cu blocuri şi conexiuni în Simulink 30. Cele mai utilizate blocuri din biblioteca de blocuri Simulink. 1. Să se scrie...

Words: 1953 - Pages: 8

Premium Essay

Matlab

...C1: MATLAB Codes t1=[37.79 39.51 38.54 39.14 39.02 39.4 39.01 37.18] t2=[22.4 22.07 22.15 21.72 21.75 22.55 22.18 21.92] T1=mean(t1) T2=mean(t2) V1=var(t1) V2=var(t2) S1=sqrt(V1) S2=sqrt(V2) MATLAB Answers T1=38.6988 T2=22.0925 V1=0.6718 V2=0.0859 S1=0.8196 S2=0.2931 C2: MATLAB Codes beta=0.98 alpha=1-0.98 z=icdf ('norm', alpha/2, 0, 1) hatmu=mean(t1); hatmu=mean(t2) s=std(t1); s=std(t2) n=length (t1); n=length (t2) margin=z*s/sqrt(8) MATLAB Answers alpha=0.02 z=2.3263 margin(t1)=0.6741; margin(t2)=0.2931 C3: MATLAB Codes syms l s b T1 T2 l=0.0496; s=1.00; b=10; T1=0.0386988; T2=0.0220925; g=((l^2)/(2*s*sind(b)))*((1/T2^2)-(1/T1^2)) MATLAB Answers g=9.7835 C4: MATLAB Codes for Partial Derivatives g=((l^2)/(2*s*sin(b)))*((1/T2^2)-(1/T1^2)) gl=diff(g,l) gs=diff(g,s) gb=diff(g,b) gT1=diff(g,T1) gT2=diff(g,T2) MATLAB Answers for Partial Derivatives gl=-(l*(1/T1^2 - 1/T2^2))/(s*sin(b)) gs=(l^2*(1/T1^2 - 1/T2^2))/(2*s^2*sin(b)) gb=(l^2*cos(b)*(1/T1^2 - 1/T2^2))/(2*s*sin(b)^2) gT1=l^2/(T1^3*s*sin(b)) gT2=-l^2/(T2^3*s*sin(b)) MATLAB Codes for Partial Derivative Values gl0=subs(gl,[l s b T1 T2],[l0 s0 b0 T10 T20]) gs0=subs(gs,[l s b T1 T2],[l0 s0 b0 T10 T20]) gb0=subs(gb,[l s b T1 T2],[l0 s0 b0 T10 T20]) gT10=subs(gT1,[l s b T1 T2],[l0 s0 b0 T10 T20]) gT20=subs(gT2,[l s b T1 T2],[l0 s0 b0 T10 T20]) MATLAB Answers for Partial Derivative Values gl0= -125.9202 gs0=...

Words: 455 - Pages: 2

Free Essay

Matlab

...An Introduction to Matlab for Econometrics John C. Frain TEP Working Paper No. 0110 February 2010 Trinity Economics Papers Department of Economics Trinity College Dublin An Introduction to MATLAB for Econometrics John C. Frain. February 2010 ∗ Abstract This paper is an introduction to MATLAB for econometrics. It describes the MATLAB Desktop, contains a sample MATLAB session showing elementary MATLAB operations, gives details of data input/output, decision and loop structures, elementary plots, describes the LeSage econometrics toolbox and maximum likelihood using the LeSage toolbox. Various worked examples of the use of MATLAB in econometrics are also given. After reading this document the reader should be able to make better use of the MATLAB on-line help and manuals. Contents 1 Introduction 1.1 1.2 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The MATLAB Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 ∗ Comments 4 4 6 6 7 8 8 9 9 9 The Command Window . . . . . . . . . . . . . . . . . . . . . . . . The Command History Window . . . . . . . . . . . . . . . . . . . The Start Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Edit Debug window . . . . . . . . . . . . . . . . . . . . . . . . The Figure Windows . . . . . . . . . . . . . . . . . . . . . . . . . . The Workspace Browser . . . . . . . . . . . . . . . . . . . . . . . . The...

Words: 15376 - Pages: 62

Free Essay

Matlab

...Memulai Menggunakan Matlab Matlab merupakan bahasa canggih untuk komputansi teknik. Matlab merupakan integrasi dari komputansi, visualisasi dan pemograman dalam suatu lingkungan yang mudah digunakan, karena permasalahan dan pemecahannya dinyatakan dalam notasi matematika biasa. Kegunaan Matlab secara umum adalah untuk : • • • • • Matematika dan Komputansi Pengembangan dan Algoritma Pemodelan,simulasi dan pembuatan prototype Analisa Data,eksplorasi dan visualisasi Pembuatan apilikasi termasuk pembuatan graphical user interface Matlab adalah sistem interaktif dengan elemen dasar array yang merupakan basis datanya. Array tersebut tidak perlu dinyatakan khusus seperti di bahasa pemograman yang ada sekarang. Hal ini memungkinkan anda untuk memecahkan banyak masalah perhitungan teknik, khususnya yang melibatkan matriks dan vektor dengan waktu yang lebih singkat dari waktu yang dibutuhkan untuk menulis program dalam bahasa C atau Fortran. Untuk memahami matlab, terlebih dahulu anda harus sudah paham mengenai matematika terutama operasi vektor dan matriks, karena operasi matriks merupakan inti utama dari matlab. Pada intinya matlab merupakan sekumpulan fungsi-fungsi yang dapat dipanggil dan dieksekusi. Fungsi-fungsi tersebut dibagi-bagi berdasarkan kegunaannya Kuliah Berseri IlmuKomputer.Com Copyright © 2004 IlmuKomputer.Com yang dikelompokan didalam toolbox yang ada pada matlab. Untuk mengetahui lebih jauh mengenai toolbox yang ada di matlab dan fungsinya...

Words: 2781 - Pages: 12

Free Essay

Matlab

...PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   a) figure subplot(2,1,1) plot(ecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') axis([0 3000 -1 2]) subplot(2,1,2) plot(ecg50hz) xlabel('Time,t/ms') ylabel('Voltage,V/mV') title('ECG containing mains contamination') axis([0 3000 -1 2]) PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   b & c) figure subplot(2,1,1) length=5; for x=1:3000-length+1; zecg_emg(x)=(ecg_emg(x)+ecg_emg(x+1)+ecg_emg(x+2)+ecg_emg(x+3)+ ecg_emg(x+4))/5; end plot(ecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') axis([0 3000 -1 2]) subplot(2,1,2) length=5; for x=1:3000-length+1; zecg50hz(x)=(ecg50hz(x)+ecg50hz(x+1)+ecg50hz(x+2)+ecg50hz(x+3)+ecg 50hz(x+4))/5; end plot(ecg50hz) xlabel('Time,t/ms') ylabel('Voltage,V/mV') title('ECG containing mains contamination') PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   axis([0 3000 -1 2]) d) figure subplot(2,1,1) length=3; for x=1:3000-length+1; zecg_emg(x)=(ecg_emg(x)+ecg_emg(x+1)+ecg_emg(x+2))/3; end plot(zecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   axis([0 3000 -1 2]) subplot(2...

Words: 645 - Pages: 3

Free Essay

Matlab

...A、B 机器加工,加工时间分别为每台 2 小时和 1 小时;生产乙机床 需用 A、B、C 三种机器加工, 加工时间为每台各一小时。 若每天可用于加工的机器时 数分别为 A 机器 10 小时、 B 机器 8 小时和 C 机器 7 小时,问该厂应生产甲、乙机床各 几台,才能使总利润最大? 上述问题的数学模型: 设该厂生产 x1 台甲机床和 x 2 乙机床时总利润最大, x1 , x2 则 应满足 (目标函数) max z = 4 x1 + 3 x2 (1) ⎧2 x1 + x2 ≤ 10 ⎪x + x ≤ 8 ⎪ 1 2 s.t.(约束条件) ⎨ ⎪ x2 ≤ 7 ⎪ x1 , x2 ≥ 0 ⎩ (2) (1)式被称为问题的目标函数, (2)中的几个不等式 这里变量 x1 , x 2 称之为决策变量, 是问题的约束条件,记为 s.t.(即 subject to)。由于上面的目标函数及约束条件均为线性 函数,故被称为线性规划问题。 总之, 线性规划问题是在一组线性约束条件的限制下, 求一线性目标函数最大或最 小的问题。 在解决实际问题时, 把问题归结成一个线性规划数学模型是很重要的一步, 但往往 也是困难的一步,模型建立得是否恰当,直接影响到求解。而选适当的决策变量,是我 们建立有效模型的关键之一。 1.2 线性规划的 Matlab 标准形式 线性规划的目标函数可以是求最大值, 也可以是求最小值, 约束条件的不等号可以 是小于号也可以是大于号。为了避免这种形式多样性带来的不便,Matlab 中规定线性 规划的标准形式为 min cT x x ⎧ Ax ≤ b ⎪ s.t. ⎨ Aeq ⋅ x = beq ⎪lb ≤ x ≤ ub ⎩ 其中 c 和 x 为 n 维列向量, A 、 Aeq 为适当维数的矩阵, b 、 beq 为适当维数的列向 量。 -1- 例如线性规划 Ax ≥ b max cT x s.t. x 的 Matlab 标准型为 min − cT x s.t. x − Ax ≤ −b 1.3 线性规划问题的解的概念 一般线性规划问题的(数学)标准型为 n z = ∑cj xj max (3) j =1 s.t. 可行解 ⎧n ⎪∑ aij x j = bi i = 1,2, L, m ⎨ j =1 ⎪ x ≥ 0 j = 1,2,L, n ⎩ j (4) 满足约束条件 (4) 的解 x = ( x1 , x2 , L , xn ) , 称为线性规划问题的可行解, 而使目标函数(3)达到最大值的可行解叫最优解。 可行域 所有可行解构成的集合称为问题的可行域,记为 R 。 1.4 线性规划的图解法 10 2 x1 + x2 = 1 0 9 8 7 x2 = 7 (2 ,6 ) 6 5 4 3 2 x1 + x2 = 8 1 z= 1 2 0 0 2 4 6 8 10 图 1 线性规划的图解示意图 图解法简单直观, 有助于了解线性规划问题求解的基本原理。 我们先应用图解法来 求解例 1。对于每一固定的值 z ,使目标函数值等于 z 的点构成的直线称为目标函数等 位线,当 z 变动时,我们得到一族平行直线。对于例...

Words: 57838 - Pages: 232

Free Essay

Matlab

...Matlab Assignment 7 Make the Matalb assignment discussed in the last class (least square regression estimates). Make sure that you program a function with proper comments and at least one test for sound input. Test your function with some input vectors, for example: y=[1,2,4,23,4,6,3,2] and x=[5,4,3,2,6,5,4,3] You can take any other input vectors. m.file command: function [alpha_estimate, beta_estimate] = my_regression(y,x) n = length(x) a = sum(x); b = sum(y); c = sum(x)/n; d = sum(y)/n; e = sum(x.*y); f = sum(x.*x); alpha_estimate = d-(e-n*c*d)/(f-n*c^2)*c; beta_estimate = (e-n*c*d)/(f-n*c^2); disp('alpha =') disp(alpha_estimate) disp('beta =') disp(beta_estimate) % Purpose of the function: This function is used to calculate the % coefficients of the regression formula. % Input: value of y and x % Output: alpha_estimate and beta_estimate % How to run the function: % I use n to represent the length of vector x and y % a to represent the sum of vector x % b to represent the sum of vector y % c to represent the avergae of vector x % d to represent the average of vector y % e to represent the sum of vector x and y % f to represent the sum of square of vector x %then calculating: alpha_estimate = d-(e-n*c*d)/(f-n*c^2)*c; % beta_estimate = (e-n*c*d)/(f-n*c^2); % Author: Hengya Jin % Date of last change: 11/27/2013 end Check: >> y=[1,2,4,23,4...

Words: 298 - Pages: 2

Premium Essay

Matlab Ode

...MATLAB 數值微積分與微分方程式求解 數值積分 ∫ b a f ( x) dx 等於由界限範圍 x = a 到 x = b 之間 曲線 f(x) 底下的面積 (a) 矩形以及 (b) 梯形 數值積分的圖解說明 數值積分 已知數據點的積分, 已知數據點的積分,不知函數 f(x):trapz : I = trapz(x, y) (梯形積分法 梯形積分法) 梯形積分法 x : 數據點之 x 值所構成的向量 y : 數據點之 f(x) 值所構成的向量 Ex: >>x=[0 10 20 30 40]; >>y=[0.5 0.7 0.9 0.6 0.4]; >>area=trapz(x,y) %梯形法 梯形法 area = 26.5000 數值積分 之形式: 已知函數 f(x) 之形式:quad , quadl I = quad(@fun, a, b) I = quadl(@fun, a, b) (適應性辛普森法) (羅伯特二次式) fun:定義函數的 function m-file 檔名 a :積分下限 b :積分上限 數值積分 Ex: ∫ 1 0 e − x cos( x) dx 1. edit fun.m function y=fun(x) y=exp(-x).*cos(x); 2. 求積分 回到Matlab Command Window) 求積分(回到 area=quadl(@fun,0,1) 亦可使用 area=quadl(‘exp(-x).*cos(x)’,0,1) NOTE: 函數內之數學運算必須使用向量個別元素之運算 (.* ./ .^) (註:比較此結果與利用trapz指令計算之結果) 數值微分 已知數據點的微分 在 x2 之微分 數值微分 可利用 diff 函數 Ex: >>x=0:0.1:1; >>y=[0.5 0.6 0.7 0.9 1.2 1.4 1.7 2.0 2.4 2.9 3.5]; >>dx=diff(x); >>dy=diff(y); >>dydx=diff(y)./diff(x) 數值微分 Ex: f ( x) = sin( x), f ′( x) = ? x ∈ [ 0, π ] >> >> >> >> >> >> >> x = linspace(0,pi,20); y = sin(x); d = diff(y)./diff(x); % backward or forward difference dc = (y(3:end)-y(1:end-2))./(x(3:end)-x(1:end-2)); % central difference dy = cos(x); % 實際微分值 plot(x, dy, x(2:end), d,'o', x(1:end-1), d,'x', x(2:end-1), dc,'^') xlabel('x'); ylabel('Derivative') 1 0.8 0.6 0.4 Derivative 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 0.5 1 1.5 x 2 2.5 3 3.5 工程問題中常微分方程式的解 常微分方程式 常微分方程式之形式: dy = f (t, y) dt 一般解之形式: yi +1 = yi + φ h ...

Words: 983 - Pages: 4

Free Essay

Matlab

...Signals and Systems Midterm 10:20a.m. ~ 12:20p.m., May 1, Fri., 2009 Closed book, but open 1 sheet (both sides, 2 pages) of personal notes of A4 size Total score: 120 Total 4 pages in one B4 sheet 1. [12] Suppose x and y denote input and output, respectively, of each of the three systems: System A: y (t ) = x(t + 2) sin(ω t + 2), ω ≠ 0 System B: y[n] = ( − 1 ) ( x[n] + 1) 2 System C: y[n] = ∑ x 2 [k + 1] − x[k ] k =1 n n Answer the following questions for each system and justify your answer. (a) Is the system linear? (b) Is the system time invariant? (c) Is the system causal? (d) Is the system stable? 2. We want to develop an edge detector that is robust against additive noise. Consider a discrete-time (DT) linear time-invariant (LTI) system H 2 with h2 [ n] = h[ n] ∗ h[ n + 1] as its impulse response shown below, where h[ n] = δ [ n] − δ [ n − 1] . (a) [4] Assume there is no noise, i.e., d [n] = 0 and x[n] = p[n] . Sketch the output y[n] of the system assuming the input p[n] to the system is the following signal: (b) [4] Assume the noise is d [ n] = −δ [ n + 1] and the input p[n] remains the same. Sketch the output y[n] of the system. (c) [4] In order to use system H 2 as a part of an edge detector, we would like to add an LTI system H s whose unit impulse response hs [n] is shown below. System H s smoothes out effect of noise on x[n] . The overall system can be represented as below: Sketch the output ys [n] of the system with d [n] and p[n] specified...

Words: 1025 - Pages: 5

Free Essay

Matlab & Ss

...Lab 1: Introduction to MATLAB Warm-up MATLAB is a high-level programming language that has been used extensively to solve complex engineering problems. The language itself bears some similarities with ANSI C and FORTRAN. MATLAB works with three types of windows on your computer screen. These are the Command window, the Figure window and the Editor window. The Figure window only pops up whenever you plot something. The Editor window is used for writing and editing MATLAB programs (called M-files) and can be invoked in Windows from the pull-down menu after selecting File | New | M-file. In UNIX, the Editor window pops up when you type in the command window: edit filename (‘filename’ is the name of the file you want to create). The command window is the main window in which you communicate with the MATLAB interpreter. The MATLAB interpreter displays a command >> indicating that it is ready to accept commands from you. • View the MATLAB introduction by typing >> intro at the MATLAB prompt. This short introduction will demonstrate some basic MATLAB commands. • Explore MATLAB’s help capability by trying the following: >> help >> help plot >> help ops >> help arith • Type demo and explore some of the demos of MATLAB commands. • You can use the command window as a calculator, or you can use it to call other MATLAB programs (M-files). Say you want to evaluate the expression [pic], where a=1.2, b=2.3, c=4.5 and d=4....

Words: 2151 - Pages: 9

Free Essay

Pelajaran Matlab

...SUPLEMEN Pemodelan Sistem / Pengolahan Sinyal / Metode Kuantitatif TUTORIAL SINGKAT MATLAB oleh: Judi Prajetno Sugiono Sekolah Tinggi Teknik Surabaya (2005, 2008, 2011) judi@stts.edu ©2005 p. 1 of 40 MATLAB Short Tutorial Reserve word (don’t used it as variable's name) · · · · · ans pi nan inf eps Special sign · · · · · % [] ; ' : line comment begin - end of matrix row separation, or not echoed command if place in the end of a statement begin - end of string indexing sign Variable is assume as matrix % empty matrix A=[] A = [] % matrix 1x1 or a constant A=[0] A = 0 % same with A=0 A = 0 % complex number: use i or j to express imaginary part z=3+4j z = 3.0000 + 4.0000i Entry a matrix % use as column separation and or as row separation A=[1 2 3; 4 5 6; 7 8 9] A = 1 4 7 2 5 8 3 6 9 Last saved by jpsugiono 9/23/2011 judi@stts.edu ©2005 p. 2 of 40 How to point element of matrix % A(row,column) A(1,3) ans = 3 % sign use as get all row or column A(2,:) ans = 4 5 6 % sign use as get from m to n cell in row or colomn A(1:2, 2:3) ans = 2 5 3 6 row and column vector % row vector a=[0 1 2 3 4 5] a = 0 1 2 3 4 5 % column vector b=[0; 1; 3; 4; 5] b = 0 1 3 4 5 % Shortcut to build a vector % init:step:final a=0:0.2:1 a = 0 0.2000 0.4000 0.6000 String % begin and end with < ' >, and act like a matrix of character ...

Words: 819 - Pages: 4

Free Essay

Ocr Matlab

...EEN 538: DIGITAL IMAGE PROCESSING Optical Character Recognition (OCR) using binary image processing with MATLAB Abstract- Nowadays, Optical Recognition is becoming a very important tool in several fields: medicine, physics, cosmology, traffic (plate numbers), etc. We can also use this to recognize character for example to digitalize a book. We will talk about this last topic in this report: Optical Character Recognition (OCR). I. INTRODUCTION Once we have the b&w image we can start the segmentation process. To do that we can use the function “bwconncomp”. This function returns us a struct from where we can obtain the characters because it gives us all the connected components. Thus, we can use it to get all the character even if they have 2 or 3 objects. This function returns us the pixels of the connected components (characters) but we have to figure out from those, the coordinates of the character in the original matrix (row and columns). To do this, we will obtain the centroid of every connected component and from it and using the first and last pixel detected of the connect component, we can figure out the exact coordinates of the image. The idea is as follows: Firstly, we can to convert the number that the function returns us to a column and a row. We can do this using the total rows of the original image. Once we have the first and last pixel detected of the connect component in (row, column) we can figure out directly the x-coordinates of the character in the image...

Words: 1132 - Pages: 5

Premium Essay

Matlab Sol

...mClassics Company paid $275,000 on May 1 to purchase $300,000, 6%, bonds that will mature in 5 years from the date of purchase. Interest on the bonds is paid May 1 and November 1 of each year. Classics Company plans to hold the bonds until maturity and amortizes the premium or discount on each interest payment date using the straight-line method. At year end, the bonds had a market value of $285,000. Prepare all necessary journal entries related to the investment in bonds. Answer: May 1 Long-Term Investment in Bonds 275,000 Cash 275,000 Nov. 1 Cash 9,000 Interest Revenue ($300,000 × 6% × 6/12) 9,000 Nov. 1 Long-Term Investment in Bonds 2,500 Interest Revenue ($300,000 - $275,000) × (6/60) 2,500 Dec 31 Interest Receivable 3,000 Interest Revenue ($300,000 × 6% × 2/12) 3,000 Dec. 31 Long-Term Investment in Bonds 833 Interest Revenue ($300,000 - $275,000) × (2/60) 833 On April 2, Smith Co. purchased 25% of Wesson Inc.’s stock for $600,000. On August 1, Wesson paid a cash dividend of $340,000 and on August 31 reported net income for the year of $2,000,000. On October 1, Smith sold all the stock in Wesson Inc. for $1,200,000. Record the Wesson-related transactions in the journal of Smith Co. Answer: April 2 Long-Term Investment in Wesson $600,000 Cash $600,000 August 1 Cash ($340,000 X .25) $85,000 Long-Term Investment in Wesson...

Words: 534 - Pages: 3