2009年9月19日 星期六

Kalman Filter 簡介

Kalman 濾波器的部份,我發現網路上有一些不錯的介紹 (無法找到原作者 ),應用一引用其一。

在學習 Kalman 濾波器之前,首先看看為什麼叫「Kalman」。跟其他著名的理論(例如傅立葉變換,泰勒級數等等)一樣,Kalman也是一個人的名字,不同的是,他是個二十世紀的人。

Kalman 全名 Rudolf Emil Kalman,匈牙利數學家,1930年出生於匈牙利首都布達佩斯。1953,1954年於麻省理工學院分別獲得電機工程學士及碩士學位。1957年於哥倫比亞大學獲得博士學位。我們現在要學習的Kalman濾波器,正是源於他的博士論文和1960年發表的論文《A New Approach to Linear Filtering and Prediction Problems》(線性濾波與預測問題的新方法)。如果對這編論文有興趣,可以到這裡的地址下載: http://www.cs.unc.edu/~welch/kalman/media/pdf/Kalman1960.pdf

故名思義,Kalman 濾波器有兩類應用:一類是濾波 (filtering, 或稱為 smoothing),另一類是預測 (prediction)。特別後者被廣泛用在需要預測+修正 (prediction + correction) 的場合。簡單來說,Kalman濾波器是一個「optimal recursive data processing algorithm(最佳化自回歸數據處理演算法)」。對於解決很大部分的問題,他是最優,效率最高甚至是最有用的。他的廣泛應用已經超過30年,包括機器人導航,控制,傳感器數據融合甚至在軍事方面的雷達系統以及導彈追蹤等等。近年來更被應用於計算機圖像處理,例如頭臉識別,圖像分割,圖像邊緣檢測等等。

Kalman濾波器的介紹

為了可以更加容易的理解Kalman濾波器,這裡會用定性的描述方法來解釋,而不是像大多數參考書那樣羅列一大堆的數學公式和數學符號。雖然 Kalman filter 的5條公式是其核心內容,非常適合電腦執行。其實 Kalman 的程序相當的簡單,只要你理解了他的那5條公式。 在介紹他的5條公式之前,先讓我們來根據下面的例子一步一步的探索。

假設我們要研究的對象是一個房間的溫度。根據你的經驗判斷,這個房間的溫度是恆定的,也就是下一分鐘的溫度等於現在這一分鐘的溫度(假設我們用一分鐘來做時間單位)。假設你對你的經驗不是100%的相信,可能會有上下偏差幾度。我們把這些偏差看成是高斯白噪聲(White Gaussian Noise),也就是這些偏差跟前後時間是沒有關係的而且符合高斯分配(Gaussian Distribution)。另外,我們在房間裡放一個溫度計,但是這個溫度計也不準確的,測量值會比實際值偏差。我們也把這些偏差看成是高斯白噪聲。

好了,現在對於某一分鐘我們有兩個有關於該房間的溫度值:你根據經驗的預測值(系統的預測值)和溫度計的值(測量值)。下面我們要用這兩個值結合他們各自的噪聲來估算出房間的實際溫度值。

假如我們要估算k時刻的是實際溫度值。首先你要根據k-1時刻的溫度值,來預測k時刻的溫度。因為你相信溫度是恆定的,所以你會得到k時刻的溫度預測值是跟 k-1時刻一樣的,假設是23度,同時該值的高斯噪聲的偏差是5度(5是這樣得到的:如果k-1時刻估算出的最優溫度值的偏差是3,你對自己預測的不確定度是4度,他們平方相加再開方,就是5)(Step 1 and 2, state and covariance prediction)。然後,你從溫度計那裡得到了k時刻的溫度值,假設是25度,同時該值的偏差是4度。

由於我們用於估算k時刻的實際溫度有兩個溫度值,分別是23度和25度。究竟實際溫度是多少呢?相信自己還是相信溫度計呢?究竟相信誰多一點,我們可以用他們的 covariance來判斷。因為Kg^2=5^2/(5^2+4^2),所以Kg=0.78 (Step 4, Kalman gain correction),我們可以估算出k時刻的實際溫度值是:23+0.78* (25-23)=24.56度 (Step 3, state correction)。可以看出,因為溫度計的covariance比較小(比較相信溫度計),所以估算出的最優溫度值偏向溫度計的值。

現在我們已經得到k時刻的最優溫度值了,下一步就是要進入k+1時刻,進行新的最優估算。到現在為止,好像還沒看到什麼自回歸的東西出現。對了,在進入 k+1時刻之前,我們還要算出k時刻那個最優值(24.56度)的偏差。算法如下:((1-Kg)*5^2)^0.5=2.35 (Step 5, covariance correction)。這裡的5就是上面的k時刻你預測的那個23度溫度值的偏差,得出的2.35就是進入k+1時刻以後k時刻估算出的最優溫度值的偏差(對應於上面的3)。

就是這樣,Kalman濾波器就不斷的把covariance遞歸,從而估算出最優的溫度值。他運行的很快,而且它只保留了上一時刻的covariance。上面的Kg,就是Kalman增益(Kalman Gain)。他可以隨不同的時刻而改變他自己的值,是不是很神奇!

下面就要言歸正傳,討論真正工程系統上的Kalman。

Kalman濾波器演算法

在這一部分,我們就來描述源於 Dr Kalman 的Kalman濾波器。下面的描述,會涉及一些基本的概念知識,包括機率(Probability),隨機變量(Random Variable),高斯或常態分配(Gaussian Distribution)還有State-space Model等等。但對於Kalman濾波器的詳細證明,這裡不能一一描述。

首先,我們先要引入一個離散控制過程的系統。該系統可用一個線性隨機微分方程(Linear Stochastic Difference equation)來描述:
X(k)=A X(k-1)+B U(k)+W(k)

再加上系統的測量值:
Z(k)=H X(k)+V(k)

上兩式子中,X(k)是k時刻的系統狀態,U(k)是k時刻對系統的控制量。A和B是系統參數,對於多模型系統,他們為矩陣。Z(k)是k時刻的測量值,H 是測量系統的參數,對於多測量系統,H為矩陣。W(k)和V(k)分別表示過程和測量的噪聲。他們被假設成高斯白噪聲(White Gaussian Noise),他們的covariance 分別是Q,R(這裡我們假設他們不隨系統狀態變化而變化)。

對於滿足上面的條件(線性隨機微分系統,過程和測量都是高斯白噪聲),Kalman濾波器是最佳的信息處理器。下面我們來用他們結合他們的covariances 來估算系統的最佳化輸出(類似上一節那個溫度的例子)。

首先我們要利用系統的過程模型,來預測下一狀態的系統。假設現在的系統狀態是k,根據系統的模型,可以基於系統的上一狀態而預測出現在狀態:
X(k|k-1)=A X(k-1|k-1)+B U(k) ……….. (1)
式(1)中,X(k|k-1)是利用上一狀態預測的結果,X(k-1|k-1)是上一狀態最佳的結果,U(k)為現在狀態的控制量,如果沒有控制量,它可以為0。
到現在為止,我們的系統結果已經更新了,可是,對應於X(k|k-1)的covariance還沒更新。我們用P表示covariance:
P(k|k-1)=A P(k-1|k-1) A'+Q ……… (2)
式 (2)中,P(k|k-1)是X(k|k-1)對應的covariance,P(k-1|k-1)是X(k-1|k-1)對應的 covariance,A'表示A的轉置矩陣,Q是系統過程的covariance。式子1,2就是Kalman濾波器5個公式當中的前兩個,也就是對系統的預測。
現在我們有了現在狀態的預測結果,然後我們再收集現在狀態的測量值。結合預測值和測量值,我們可以得到現在狀態(k)的最優化估算值X(k|k):
X(k|k)= X(k|k-1)+Kg(k) (Z(k)-H X(k|k-1)) ……… (3)
其中Kg為Kalman增益(Kalman Gain):
Kg(k)= P(k|k-1) H' / (H P(k|k-1) H' + R) ……… (4)
到現在為止,我們已經得到了k狀態下最優的估算值X(k|k)。但是為了要另Kalman濾波器不斷的運行下去直到系統過程結束,我們還要更新k狀態下X(k|k)的covariance:
P(k|k)=(I-Kg(k) H)P(k|k-1) ……… (5)
其中I 為1的矩陣,對於單模型單測量,I=1。當系統進入k+1狀態時,P(k|k)就是式子(2)的P(k-1|k-1)。這樣,算法就可以自回歸的運算下去。
Kalman濾波器的原理基本描述了,式子1,2,3,4和5就是他的5 個基本公式。根據這5個公式,可以很容易的實現計算機的程序。
下面,我會用程序舉一個實際運行的例子。。。 
 

應用一: 找出 (estimate) 室溫

這裡我們舉一個非常簡單的例子來說明 Kalman 濾波器的工作過程。所舉的例子是進一步描述上一節的例子,而且還會配以 matlab 模擬結果。

根據第二節的描述,把房間看成一個系統,然後對這個系統建模。當然,我們見的模型不需要非常地精確。我們所知道的這個房間的溫度是跟前一時刻的溫度相同的,所以A=1。沒有控制量,所以U(k)=0。因此得出:

X(k|k-1)=X(k-1|k-1) ……….. (6)

式子(2)可以改成:

P(k|k-1)=P(k-1|k-1) +Q ……… (7)

因為測量的值是溫度計的,跟溫度直接對應,所以H=1。式子3,4,5可以改成以下:

X(k|k)= X(k|k-1)+Kg(k) (Z(k)-X(k|k-1)) ……… (8)

Kg(k)= P(k|k-1) / (P(k|k-1) + R) ……… (9)

P(k|k)=(1-Kg(k))P(k|k-1) ……… (10)

現在我們模擬一組測量值作為輸入。假設房間的真實溫度為25度,我模擬了200個測量值,這些測量值的平均值為25度,但是加入了標準偏差為幾度的高斯白噪聲(在圖中為藍線)。

為了令Kalman濾波器開始工作,我們需要告訴Kalman兩個零時刻的初始值,是X(0|0)和P(0|0)。他們的值不用太在意,隨便給一個就可以了,因為隨著Kalman的工作,X會逐漸的收斂。但是對於P,一般不要取0,因為這樣可能會令Kalman完全相信你給定的X(0|0)是系統最優的,從而使算法不能收斂。我選了 X(0|0)=1度,P(0|0)=10。

該系統的真實溫度為25度,圖中用黑線表示。圖中紅線是Kalman濾波器輸出的最優化結果(該結果在算法中設置了Q=1e-6,R=1e-1)。



附matlab下面的kalman濾波程序:

clear

N=200;

w(1)=0;

w=randn(1,N)

x(1)=0;

a=1;

for k=2:N;

x(k)=a*x(k-1)+w(k-1);

end

V=randn(1,N);

q1=std(V);

Rvv=q1.^2;

q2=std(x);

Rxx=q2.^2;

q3=std(w);

Rww=q3.^2;

c=0.2;

Y=c*x+V;

p(1)=0;

s(1)=0;

for t=2:N;

p1(t)=a.^2*p(t-1)+Rww;

b(t)=c*p1(t)/(c.^2*p1(t)+Rvv);

s(t)=a*s(t-1)+b(t)*(Y(t)-a*c*s(t-1));

p(t)=p1(t)-c*b(t)*p1(t);

end

t=1:N;

plot(t,s,'r',t,Y,'g',t,x,'b');

 

 應用二:Symbol(Bit) Synchronization with Unknown Phase/Frequency

考慮如下一個 burst mode 的 packet (任何 shared media 的傳送方式)。在 packet 最前頭都會有 1010.. 的 preamble 做為 bit/symbol synchronization。緊接在後的是事先定義好的 frame sync word 用來做為確認 lock 到對的 packet 以及 word boundary。最後才是實際的 data。這個應用 focus 在 preamble 部份 (1010..) synchronization,也就是找出 (estimate) preamble 的相位和頻率,同步之後的 data。

image 

我們可以把問題重新定義如下:A [2pft + q]  如何找出 f (or b = 1/(2pf) or T=1/f) and q ?

這個問題同樣可以用 state-space model 來模擬,而得到最佳的 Kalman filter 解。有趣的是,Kalman filter 等價於一個 2nd order time variant PLL 架構。這和一般所用 2nd order time invariant PLL 非常近似。可參見另文 Kalman Filter and PLL。

應用三:TCP/IP 演算法和 Kalman Filter

2009年7月25日 星期六

作虛功?

多數人都不喜歡作虛功。但在古典力學中,虛功原理 (virtual work) 漂亮的洐生出 D'Alembert 原理,以及等價的最小作用原理。後者成為 Lagrangian mechanics 和 Hamiltonian mechanics 的基礎。可以說虛功原理簡單且容易了解,並不是真的作虛功。

什麼是虛功

Wiki 的定義如下。基本上是從牛頓力學第一定律出發導出虛功原理:

Consider a system of particles, i, in static equilibrium.  Based on Newton's first law, the total force on each particle is

\mathbf {F}_{i}^{(T)} = 0.

Summing the work exerted by the force on each particle that acts through an arbitrary virtual displacement, \delta \mathbf r_i, of the system leads to an expression for the virtual work that must be zero since the forces are zero.

\delta W = \sum_{i} \mathbf {F}_{i}^{(T)} \cdot \delta \mathbf r_i = 0.

At this point it should be noted that the original vector equation could be recovered by recognizing that the work expression must hold for arbitrary displacements. Separating the forces into applied forces, \mathbf F_i, and constraint forces, \mathbf C_i, yields

\delta W = \sum_{i} \mathbf {F}_{i} \cdot \delta \mathbf r_i + \sum_{i} \mathbf {C}_{i} \cdot \delta \mathbf r_i = 0.

If arbitrary virtual displacements are assumed to be in directions that are orthogonal to the constraint forces, the constraint forces do no work. Such displacements are said to be consistent with the constraints.  This leads to the formulation of the principle of virtual work for applied forces, which states that forces applied to a static system do no virtual work

\delta W = \sum_{i} \mathbf {F}_{i} \cdot \delta \mathbf r_i = 0.

虛功原理源起於靜力學。它的白話文:對於一個處於平衡 (equilibrium, 一般為靜止)的系統,其外力乘上虛位移 (virtual displacement)為零。虛位移並不是任意的方向,而必須根據 constraint 的限制。

 

 

 

 

Lancos 則有不同的看法,他把虛功原理視為一個假設。配合牛頓第二定律可以推廣至動力學的 D'Alembert 原理。而與最小作用原理是等價。

  

虛功原理的應用

第一個重要的應用就是最低勢能原理。如果所有的外力都是勢能 (potential or work function) 的 derivative  dV = -dU = F. dr = 0 , 虛功原理就變為靜力學的最低勢能原理 (minimal potential)。請參閱另一文章。

應用在 rigid body

 

應用在 rigid body

應用在 deformable body

應用在 incomperssible fluid

 

Pascal principle

differnce between Newtonian

minimal potential principle

difference between least action and virtue work

 

Virtual work does not depend on time (t), only a spacial function

Q: When virtue work equals to Newtonian law?

Q:

2009年7月19日 星期日

RF CMOS Tuner

superheterodyne receiver

一個 generic RF superheterodyne receiver可以分為 RF stage, IF stages (上圖有兩個 IF, 第二個 IF 是 baseband), 和 clocking subsystem。

RF receiver 要達成兩個目的: (I) 將天線接收微弱的RF信號 (例如 -100 dBm, 2.2uV, or 7dBuV) 放大;(II) 把不要的干擾信號濾掉。

(I) 主要是 focus on LNA 的設計,如何提供需要的 RF gain 和夠好的 Noise Figure, 讓 receiver total noise figure 控制的夠小。此外還必須有足夠的 dynamic range 來應付不同強弱的 receiver RF signal.

(II) 主要透過一連串的 filter 設計,濾掉不同頻帶的干擾信號。如下:

  Frequency Interference type Suppresion
Tracking Filter RF far (different band) < 10dB
Image Rejection Filter RF near (+/- N channel)* 30-50dB
IF Filter IF adjacent (+/-1) High Q, 40-50dB
Baseband channel selection filter BB adjacent (+/-1) 30-50dB*
Anti-alias Filter BB near (+/-K)* < 10dB

1: depending on IF frequency; 2: for ZIF or LIF; K depends on ADC oversampling frequency

 

Receiver Filtering

Superheterodyn receiver 有下面三種最常見的變形:(a) HIF (high IF); (b) LIF (low IF); and (c) ZIF (zero IF).  各自對 filter 有不同的要求。

ZIF: 上圖中省略 IF stage,RF 訊號直接 down convert 到 baseband。這是目前最普遍的 RF CMOS tuner。

優點是 RF 架構簡單,低功秏,並且不需要外接 SAW filter,可以達到很高的整合度。

缺點是需要許多的 calibration 來彌補 ZIF 架構上的問題;例如 DC offset calibration, IQ mismatch calibration, baseband filter bandwidth calibration。

receiver filter

第一級的 Band Select Filter 大略上 suppress out of band interference,避免。因為是 wideband filter,通常 suppression 效果有限,一般是在 10dB 以內。

LIF Frequency Interference type Suppresion
Tracking Filter RF far (different band) < 10dB
Image Rejection Filter RF near (+/- N channel)* 30-50dB
IF Filter IF adjacent (+/-1) High Q, 40-50dB
Baseband channel selection filter BB adjacent (+/-1) 30-50dB*
Anti-alias Filter BB near (+/-K)* < 10dB

LIF: 類似 LIF 架構。

例如

2009年7月5日 星期日

力耶?勢耶?孰優孰劣

孫子兵法:故善戰者,求之於勢。善戰人之勢,如轉圓石於千仞之山者,勢也。故上兵伐謀,其次伐交,其次伐兵,其下攻城。伐謀、伐交就是造勢、借勢。伐兵、攻城就是以力取勝。孫子兵法明顯認為 "勢" 優 "力" 劣。

古典力學的兩種 approach

一是大家都熟悉的牛頓力學 (Newtonian mechanics) 和三大定律 (實際上是假設):即 (i) F=0 的慣性定律, (ii) F=mA 運動定律,  和 (iii) 作用力和反作用力定律。其中最重要最關鍵的物理量就是力。這也是為什麼 mechanics 中文翻譯為 "力" 學。

另一類 approach 是基於最小作用原理 (least action principle),通常稱為 Lagrangian mechanics 或是 Hamiltonian mechanics。這裹只有一個假設,就是運動的物體會遵循最小的 action。什麼是 action(S),可以用下面公式定義:

\mathcal{S} = \int_{t_1}^{t_2}\; L(x,\dot{x})\,\mathrm{d}t 

其中 L = T - V。T (kinetic energy) 是動能。V (potential) 通常稱為位能,或是勢(能)。雖然 V 大多是位置的函數,但也可能是速度或是時間的函數,所以位能不是妥當的翻譯。

只要能找出 L (i.e. T-V),其它只是計算。T=1/2mv2 是 well-known.  主要的工作就是找出 V (勢)。

簡言之:牛頓力學 (Newtonian mechanics) 主要的工作就是找到所有的力。Largrangian or Hamiltonian mechanics 主要的工作就是找到勢。在多數的情況,找勢比找力簡單容易。意即"勢" 優 "力" 劣。

靜力學的例子

考慮一條均勻繩子或鏈子兩端固立,在重力場中自然垂下如下。

img025

從牛頓力學的靜力學觀點而言,每一小段鏈子的重力和上下兩端的張力的合力為零。雖然不難,但須費一番功夫。

在靜力場中,動能 T=0, S = (t2-t1) V.   因此在靜力學中,最小作用力原理簡化為最低勢能原理。解法如下:

img026

因為重力場函數是 -gy, 所以只要將每一小段鏈子質量乘上重力場即是每一小段的勢。最後再把所有小段的勢積分就得到全部的勢。

最小作用力原理的優點

(A) 不用找力,不論是明顯的外力 (重力),或是不明顯的內力 (張力);只需要找勢。勢通常只由外力造成,內力可以被忽略(除非有彈力位能)。這讓思考簡化很多,也容易讓電腦自動計算。

(B) 同時勢能是一純量,而力是一向量。這也讓計算簡化許多。

(C) 除此之外,最小作用原理是一普遍的原理。可以同樣適用在相對論力學,量子力學上。這是比牛頓的力學三定律更基本的原理。此外,結合廣義座標和微分幾何,可以得到更深的物理意義。請參閱參考資料。

參考資料: "The Variational Principles of Mechanics" by Lanczos

2009年5月28日 星期四

LDO Regulator 設計要點

Screenshot - 20090516 - 084339

LDO 設計最主要的工作是設計 PMOS, error amplifer, 和適當的 frequency compenstation 電路,步驟如下:

Step 1: 由 steady state 決定 PMOS 的大小。主要是由 Iload 和 PMOS 的 Vdrop (droupout voltage) 決定,條件是讓 PMOS 維持在 saturation.

img017

以 Iload = 50mA and Vdrop = 200mV 為例, 假設為 0.35um 3.3V 製程 uCox = 65uA/V^2.    W/L ~> 40,000. 

For L = 0.4um (3.3V device), W > 16mm,

WL = 6400 um^2  or 80 um x 80 um area.   The gate capacitance is around 80 um x 80 um x 6 fF = 38.4 pF.

 

Step 2: 由 transient condition 決定 close loop (包含 error amplifier and output PMOS) 的頻寬 BW 和 Cload 的大小。

img018

DVdrop(X) 是指在 x 點 (output point) 當 Iload 由0 跳升為 Iload 時的 voltage drop。這是由三部份所組成,ESR, ESL, and C1 的壓降。如果 ESL 很小且 Iload 不大,可忽略 ESL 的壓降。一般我們希望 DVdrop 控制在 Vout 的+/-10% 之內。因此,BW* Cload 必須大於一個常數。

 

 

 

( Cload * BW > constant )

 

先選 output cap 的大小。

Q = CV   i = C dv/dt

dv  = i * ESR +  i / C * dt

i –>  current;  C –> output cap

dt –> close loop bandwidth dt * BW = 0.35  -> dt = 0.35 / BW

dv = i * ESR + 0.35 * i /  (C * BW)

example:  這是由 time domain 決定。 for example, 1.2V 10% is  120mV.   output current is 60mA. ESR = 0.5Ohm, vdrop = 30mV.  dv = 90mv = 0.35*i / (c * BW)   (c*BW) > 0.23

opamp 的 BW = 100KHz  c > 3uF.  

 

Step 3: 決定 frequency compensation 的方式

一般使用 single stage opamp 以簡化 frequency compensation 方式。因此 output pole can be obtain by  Rpar * C par.  Gain can be obtain gm * Rpar.  Therefore, the transfer function is gm * Rpar / (1 + Rpar * Cpar * s).    At high frequency, the UGF = gm / Cpar.  (gm usually around 400uA/V, therefore 10M rad or 1.5MHz. 

On the other hand, the output has another dominant pole, usually Gp = gmp * Rout;  Cout * Rout, therefore, the UGF of output pole is gmp / Cout.  assume gmp = 100mA/V, Cout = 10uF, UGF = 10K rad or 1.5kHz, far smaller compared with originally ucf. 

Screenshot - 20090517 - 195420

如上所述,若沒有 compensation, 兩個 low frequency poles 會造成 no phase margin.  常見解決方法是在 output cap 上加一個 ESR zero,  但仍有其他的 output pole (usually needs to be less than 10% of output cap, Pb), 如下圖所示 。

 

 

Screenshot - 20090517 - 195403

然而 ESR 所造成的 zero, 必須小心控制,太小或太大都不合適。太大乍看之下很好,甚至可以讓 zero 和 Pa 互消,但間題是 ucf 太高, 會被下一個 pole 造成 low phase margin.  相反的,如果 ESR 太小,對 phase margin 沒有什麼貢獻。

Screenshot - 20090517 - 195449

Screenshot - 20090517 - 211947

2009年4月25日 星期六

LDO Regulator 簡介

img003

LDO (Low Dropout Regulator) 的主要功能就是在輸入電壓 (Vin) 或是輸出電流 (Iout) 變動的情形下,仍然維持穩定的輸出電壓 (Vout)。如上圖所示,如果 Vin (就是 line) 有一個電壓的突升, 輸出電壓 Vout 也會隨之改變,但經由 LDO 的回授電路會把 Vout 穩定在原來的電壓,因此 Vout 有一些電壓漣波,同時最終穩定的電壓也有些許的變化。Vout 對 Vin 的變化稱之為 line regulation,後面有更詳細的說明。同樣的如果輸出電流突升,輸出電壓 Vout 也會改變, Vout 對 Iout 的變化則稱為 load regulation。

 img007

上圖是一個 LDO 的原理圖,主要有四個部份。簡單卻包含了類比電路的feedback 控制、和補償的原理。

Reference 和 RC filter: 通常為 bandgap 電路加上 RC 濾波電路提供穩定的參考電壓。

Error Amplifier 及 R1/R2 分壓: 通常為一簡單的 opamp 放大輸出電壓(經R1/R2 比例)和參考電壓的誤差。注意此處參考電壓接正極。實務上 Pass FET 多為 PMOS 提供多一次反向。因此參考電壓會接負極而非正極。

Pass FET: 一般為一個巨大的 PMOS。PMOS 的大小由提供的電流和 dropout voltage 決定。

Cout 及 Rload: Cout 為輸出濾波及提供快速電流給 output load。可以用 Rload 模擬 LDO 提供的電流。 Cout 通常會有寄生電感和電阻,稱之為 ESL 和 ESR (equivlaent serial resistance)。其中 ESR 對於 LDO 的穩定(或振盪)相當重要。

 

LDO performance: AC and Step Response

LDO 常見的特性包含 frequency domain PSRR 和 time domain step response。以 Vin 的 PSRR 為例:

 image

上圖為 Vout 對 Vin 在不同頻率正弦波的 rejection ratio 。一般可分為三區:

  • Region 1 是由 reference 和 RC filter 決定。由於 RC 面積的限制,一般 RC filter 的頻率很難低於100 Hz。
  • Region 2 是由全部的 feedback loop 的 gain 和 frequency response 決定,包含 error amp, pass FET, output load 和 R1/R2。一般 dominant pole 是由 Cout Rload 決定 (10uF, 10 Ohm ~  1.5kHz)。
  • Region 3 是由 output 電容分壓決定。Cout 愈大,PSRR 在 region 3 愈高。

 

再以 load current 的 500mA step response 為例:

 Screenshot - 20090511 - 002144

可分為二區

第一區為高頻區 (以 close loop 的 loop bandwidth 為準)。因為 error amplifier 和 PMOS 來不及反應,電流由外接電容供應,因此 Vout 往下降。可以根據 output cap 以及寄生的電阻電感、再細分為三個部份壓降,分別為 ESR, 其次為 ESL, 然後是 cap 造成。ESL 壓降最快,反應電流的變率(微分);ESR 壓降其次,直接反應電流; cap 壓降最慢,反應電流的積分 (droop)。

一旦進入了 loop bandwidth 的反應時間,error amplifier 和 PMOS 開始動作,加大的電流同時供應 output load 以及對電容充電。電壓上升,這時對應的是 PSRR 的 region II 。

理論上可以同樣得出 Vin  的 step response 和 load current 的 ac response。可由 fourier transform 得到。不過一般 LDO 較少用到。

  AC response Step response
Input Voltage PSRR, 週期性 noise step noise
Load current 很少用到 常見且重要

 

LDO Frequency Compensation

Screenshot - 20090516 - 012513

上述的 LDO 很明顯有 stability 的問題,因為有兩個低頻的 poles:一個位於 output 的 dominant pole,由 Cload (~10uF) 所造成;另一個位於 PMOS  gate 的 non-dominant pole,由 PMOS 的 gate capacitance (Cgate ~ 幾十 pF) 所造成。另外加上一些高頻的 poles, 會讓 phase margin 小於10度而引起 stability 的問題。

更麻煩的是 Cload 所看到的等效電阻會隨著 Iload 有很大的改變。大電流時 (50-100mA) 等效電阻小 (Rload 和Rpar, 幾十歐姆),小電流時 (<1mA) 時等效電阻大 (> kOhm)。會造成 dominant pole 頻率可能相差百倍。

相反的,Cgate 所看到的等效電阻 (error amplifier output impedance) 卻是與 Iload 無關,non-dominant pole 的頻率基本上不會隨著 Iload 改變 (但仍與 PVT 有關)。因些有可能藉著增加 zero 來補償 (或者可想成 cancel) non-dominant pole 而增加 phase margin。

 

Screenshot - 20090516 - 084339

最容易加上 zero 的方法就是直接利用 output cap 上的 ESR,自動創造出一個位於 Cload* ESR 的 zero。這個增加 zero 的方法簡單有效,廣為 LDO 所用,但是有一些限制。

  1. 為了能適當的補償或 cancel non-dominant pole,ESR 值有一定的範圍,太大或太小都會造成問題。
  2. 必須選擇 tantalum (鉭質)電容,因為 ESR 值適中 (~100 mOhm) 且不隨著溫度變化太大。ceramic 電容雖然體積小且低價,但 ESR 過小 (<10 mOhm) 不適合。一般電解電容的 ESR 隨溫度變化太大也不適合。
  3. 另外 ESR 在 Iload 變化時,會有額外的壓降而造成 Vout 上的 noise。

對於 LDO 更詳細的介紹請參考 LDO 設計重點一文。

2009年2月22日 星期日

藍牙簡介

如前文所述,bluetooth 己成為 mobile computing 的 de facto 外接的標準。本文主要討論 bluetooth 的規格及應用。

Bluetooth 有內定的 profile 決定有關的應用,可參考 wiki。以下舉出手機中常見的 profile:

  • Hands Free and Headset profile: HFP / HSP
  • Advanced Audio Distribution (Stereo) profile: A2DP
  • Audio/Video Remote control profile: AVRCP

不同的 profile 並不完全是獨立的,常常是互相關連,如下圖所示。GAP 是最基本的 profile;GAVDP 是架構在GAP之上; A2DP 又是架構在 GAVDP之上。

image

以下說明各種 os/device 對 profile 的支援程度。以 embedded OS 而言,symbian 目前有最完整的 bluetooth profile 支援。

 

General OS

Windows XP SP2/Vista/7

The Microsoft Windows Bluetooth stack only supports external or integrated Bluetooth dongles attached through USB. It does not support Bluetooth radio connections over PCI, I²C, serial, PC Card or other interfaces.

Windows XP includes a built-in Bluetooth stack starting with the Service Pack 2 update, released on 2004-08-06.

The Windows XP and Windows Vista Bluetooth stack supports the following Bluetooth profiles natively: SPP, DUN, HID, HCRP.  Windows 7 also supports audio related profiles-HFP, HSP, A2DP and AVRCP natively.

 

Linux

The Linux operating system currently has two widespread Bluetooth stack implementations:

BlueZ is the official Bluetooth stack for Linux and is used in Google's Android OS. Its goal is to make an implementation of the Bluetooth wireless standards specifications for Linux. As of 2006, the BlueZ stack supports all core Bluetooth protocols and layers.  It was initially developed by Qualcomm, and is available for Linux kernel versions 2.4.6 and up.

 

MAC OS

Mac OS X: As of version 10.5, Mac OS X includes native support for A2DP on Bluetooth equipped Macs.  Version 10.4 does not support A2DP, but can be hacked to enable limited functionality.  Softick Audio Gateway for Mac OS X also supports A2DP. Despite being capable of A2DP, the iPhone variant of OS X provides no A2DP support as of October 2008. (But will be supported in future versions of the iPhone OS.)

 

Embedded OS

BlueMagic

BlueMagic 3.0 is Open Interface's (now Qualcomm) highly portable embedded Bluetooth protocol stack which power's Apple's iPhone and Qualcomm-powered devices such as the Motorola RAZR. BlueMagic also ships in products by Logitech, Samsung, LG, Sharp, Sagem, and more. BlueMagic 3.0 was the first fully certified (all protocols and profiles) Bluetooth protocol stack at the 1.1 level.

 

BlueCore Host Software (BCHS)

CSR's BCHS or BlueCore™ Host Software provides the upper layers of the Bluetooth® protocol stack (above HCI, or optionally RFCOMM) - plus a large library of Profiles - providing a complete system software solution for embedded BlueCore applications. BCHS supports 1.2, 2.0+EDR and 2.1+EDR. Current qualified Profiles available with BCHS: A2DP,AVRCP,PBAP,BIP,BPP,CTP,DUN,FAX,FM API,FTP GAP,GAVDP,GOEP,HCRP,Headset,HF1.5,HID,ICP,JSR82,LAP Message Access Profile,OPP,PAN,SAP,SDAP,SPP,SYNC,SYNC ML.

 

Windows CE/Mobile

Windows CE is Microsoft's embedded operating system, which also supports Bluetooth. However, different stacks can be installed on windows CE devices, including Microsoft, Widcomm, and Toshiba, depending on the embedded device on which the OS is installed.

Windows Mobile (previously Pocket PC, PPC): Version 5.0 and newer (with AKU 2.0), thus far based on the Windows CE 5.0 kernel, fully support A2DP if an appropriate device is present.

There is a huge amount of debate on the forums as to what Bluetooth profiles Windows Mobile devices support.  Below is the list that we support natively in the Microsoft Stack in AKU 2.0 of Windows Mobile 5.0 and beyond:

Generic Access Profile (GAP)
Generic Object Exchange Profile (GEOP)
Serial Port Profile (SPP)
Dial-up Networking (DUN) Profile
Hands-Free Profile (HFP)
Headset Profile (HSP)
Human Interface Device (HID) Profile
Object Push Profile (OPP)
ActiveSync-Over-Bluetooth
Advanced Audio Distribution Profile (A2DP)
Audio/Video Remote Control Profile (AVRCP)

The confusion typically starts because it is up to to the OEM to choose which ones they implement or to add additional support for other profiles.

 

Symbian OS bluetooth profile (v9.2)

Symbian OS is an operating system for mobile phones, which includes a bluetooth stack. All phones based on Nokia's S60 platform and Sony Ericsson/Motorola's UIQ platform use this stack. The Symbian bluetooth stack runs in user mode rather than kernel mode, and has public APIs for L2CAP, RFCOMM, SDP, AVRCP, etc. Profiles supported in the OS include GAP, OBEX, SPP, AVRCP, GAVDP, PAN, PBAP.  Additional profiles supported in the OS + S60 platform combination include A2DP, HSP, HFP1.5, FTP, OPP, BIP, DUN, SIM access, device ID.

There are two kinds of profiles provided for by Symbian OS: implemented and supported. Implemented profiles can be used directly from the existing components. When a profile is supported the licensee will need to provide its own APIs to make the functionality of that profile available to application developers.

image

The above figure shows the dependencies of profiles. The shaded profiles are implemented by the Symbian OS Bluetooth subsystem.

Implemented Bluetooth profiles

The following profiles are implemented by Symbian OS Bluetooth:

  • Generic Access Profile (GAP)

  • Serial Port Profile (SPP)

  • Generic Object Exchange Profile (GOEP)

  • Personal Area Networking (PAN) Profile

  • Audio Video Remote Control Profile (AVRCP)

  • Generic Audio Video Distribution Profile (GAVDP)

 

Android (Cupcake)

Android bluetooth is based on BlueZ on Linux.  New kernel based on Linux 2.6.27.  However, the bluetooth API is not supported till v1.0 release.  Google promised it will support A2DP profile.  The tentative release cupcake supports A2DP and AVRCP profiles.

iphone OS

iphone OS is based on MAC OS X.  The only bluetooth device opens now is the bluetooth headset.  It is annoying!

追蹤者