## Trending News

# 如何使用Matlab將信號作correlation?

我需要用matlab作 correlation

1. 先自定x[n] 有限長度, 作auto correlation (信號跟信號本身)

2. delay一個N (把信號作一個delay) 作auto correlation

y[n]=x[n-N] ,(N=4 ,delay4次)

3. 信號加亂數noisy, 作auto correlation

4. 作cross correlation

請將上面四個結果並列

請問有人可以教我要如何做嗎,,感謝~~~

### 1 Answer

- 小魚Lv 69 years agoFavorite Answer
clear

% x is sin wave

n = 1024+10;

dt = 1/4096;

t = [0:n-1]*dt;

f = 100;

xt = sin(2*pi*f*t);

x = xt(5:1024+4); y = xt(1:1024);

% auto-correlation of x

Rx = autocorr(x);

% auto-correlation of y

Ry = autocorr(y);

% auto-correlation of x with noise

nl = 1;% noise level

xn = x + nl*rand(1,1024);

Rxn = autocorr(xn);

% cross-correlation of x and y with noise

yn = y + nl*rand(1,1024);

Rxnyn = xcorr(xn,yn);

%

clf;figure(1)

subplot(421);plot(1:1024,x);ylabel('x');

subplot(422);plot(1:length(Rx),Rx);ylabel('Rx');

subplot(423);plot(1:1024,y);ylabel('y');

subplot(424);plot(1:length(Ry),Ry);ylabel('Ry');

subplot(425);plot(1:1024,xn);ylabel('xn');

subplot(426);plot(1:length(Rxn),Rxn);ylabel('Rxn');

subplot(427);plot(1:1024,yn);ylabel('yn');

subplot(428);plot(1:length(Rxnyn),Rxnyn);ylabel('Rxnyn');

圖片參考：http://imgcld.yimg.com/8/n/AC01979561/o/1611102804...