【課堂筆記】C++程序設計- 第一章-緒論
1379
2025-04-02
【 MATLAB 】filter 函數介紹(一維數字濾波器)
在上篇博文中,里面有一個例子,就是過濾部分中的數據,這個部分中的數據的意思是如果有一個向量需要過濾,我們可以把它分為幾段,然后分段過濾。
關于這個問題,使用語法:
[y,zf] = filter(___)
賦值符號左邊的部分有一個y是過濾后的數據,那至于zf到底是個什么玩意,當時沒有弄清楚,所以這里來專門討論一番,參考MATLAB的參考文檔的例子。
賦值符號右邊的部分,可以是函數filter的語法中任何一種,即:
filter(b,a,x):對x進行濾波;
filter(b,a,x,zi):關于zi的解釋,我們看下面這一段:
zi?—?Initial conditions for filter delays
[]?(default) |?vector?|?matrix?|?multidimensional array
Initial conditions for filter delays, specified as a vector, matrix, or multidimensional array.
濾波器延遲的初始條件,指定為矢量,矩陣或多維數組。
If?zi?is a vector, then its length must be?max(length(a),length(b))-1.
If?zi?is a matrix or multidimensional array, then the size of the leading dimension must be?max(length(a),length(b))-1. The size of each remaining dimension must match the size of the corresponding dimension of?x. For example, consider using?filter?along the second dimension (dim = 2) of a 3-by-4-by-5 array?x. The array?zi?must have size [max(length(a),length(b))-1]-by-3-by-5.
The default value, specified by?[], initializes all filter delays to zero.
Data Types:?double?|?single?|?int8?|?int16?|?int32?|?int64?|?uint8?|?uint16?|?uint32?|?uint64?|?logical
Complex Number Support:?Yes
對比zf,看看zf的解釋:
zf?— Final conditions for filter delays
vector | matrix | multidimensional array
Final conditions for filter delays, returned as a vector, matrix, or multidimensional array.
濾波器延遲的最終條件,作為矢量,矩陣或多維數組返回。
If?x?is a vector, then?zf?is a column vector of length?max(length(a),length(b))-1.
If?x?is a matrix or multidimensional array, then?zf?is an array of column vectors of length?max(length(a),length(b))-1, such that the number of columns in?zf?is equivalent to the number of columns in?x. For example, consider using?filter?along the second dimension (dim = 2) of a 3-by-4-by-5 array?x. The array?zf?has size [max(length(a),length(b))-1]-by-3-by-5.
Data Types:?double?|?single
filter(b,a,x,zi,dim):dim是指定維度,如果x是一個矩陣,那么如果dim為1(默認值),那么就把對矩陣的每個列進行濾波,如果dim為2,則對矩陣的行進行濾波。
Filter Data in Sections
Use initial and final conditions for filter delays to filter data in sections, especially if memory limitations are a consideration.
Generate a large random data sequence and split it into two segments, x1 and x2.
x = randn(10000,1);
x1 = x(1:5000);
x2 = x(5001:end);
The whole sequence, x, is the vertical concatenation of x1 and x2.
Define the numerator and denominator coefficients for the rational transfer function,
b = [2,3];
a = [1,0.2];
Filter the subsequences x1 and x2 one at a time. Output the final conditions from filtering x1 to store the internal status of the filter at the end of the first segment.
[y1,zf] = filter(b,a,x1);
Use the final conditions from filtering x1 as initial conditions to filter the second segment, x2.
y2 = filter(b,a,x2,zf);
y1 is the filtered data from x1, and y2 is the filtered data from x2. The entire filtered sequence is the vertical concatenation of y1 and y2.
Filter the entire sequence simultaneously for comparison.
y = filter(b,a,x);
isequal(y,[y1;y2])
上面這個例子,驗證了一種情況,就是如果對一個序列進行濾波,可以得到一個結果。
也可以通過另一種方式,就是把該序列分成兩段,分段濾波,最后將濾波數據拼接起來,對比兩種方式的最終結果,發現是一致的。
對第一段數據進行濾波時候會得到一個zf,這個zf作為第二段數據濾波時候的zi。
MATLAB
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。