# 创建复合的 System object

### 作为私有属性的 System object

```properties (Access=private) % This example class contains two moving average filters (more can be added % in the same way) MovingAverageFilter1 MovingAverageFilter2 end ```

### 设置移动平均滤波器

`setupImpl` 方法中，创建两个移动平均值 System object 并初始化其公共属性。

```function setupImpl(obj,~) % Set up moving average objects with default values obj.MovingAverageFilter1 = movingAverageFilter('WindowLength',obj.WindowLength1); obj.MovingAverageFilter2 = movingAverageFilter('WindowLength',obj.WindowLength2); end ```

### 使用从属属性

```properties(Nontunable,Dependent) % WindowLength Moving window length WindowLength1; WindowLength2; end ```

```function set.WindowLength1(obj,WindowLength1) % Set the window length of one moving average filter obj.MovingAverageFilter1.WindowLength = WindowLength1; end function WindowLength = get.WindowLength1(obj) % Read window length from one of the moving average filters WindowLength = obj.MovingAverageFilter1.WindowLength; end function set.WindowLength2(obj,WindowLength2) % Set the window length of one moving average filter obj.MovingAverageFilter2.WindowLength = WindowLength2; end function WindowLength = get.WindowLength2(obj) % Read window length from one of the moving average filters WindowLength = obj.MovingAverageFilter2.WindowLength; end ```

### 在 MATLAB 中使用互相关性对象

```x = rand(20,1); y = rand(20,1); crossCorr = crossCorrelationMovingAverages('WindowLength1',1,'WindowLength2',5); for iter = 1:100 x = rand(20,1); y = rand(20,1); [corr,lags] = crossCorr(x,y); stem(lags,corr) end```