I want to do the correlation of the following two plots
조회 수: 6 (최근 30일)
이전 댓글 표시
clc; clear all; Ts=1/200e6; t=Ts:Ts:0.00005; y=[ones(1,2000) zeros(1,8000)]; x=sin(1256e6*t+2198e10*t.^2); z=x.*y; subplot(2,1,1) plot(t,z) N=0; while N<4 t1=Ts+0.00002+0.00005*N:Ts:0.00002+0.00005*(N+1); j=@(t)x.*y; w=@(t)j(t-0.00002); subplot(2,1,2) plot(t1,w(t)) hold on N=N+1; end
댓글 수: 2
Star Strider
2020년 2월 23일
This line makes no sense and throws an error:
t1=Ts+0.00002+0.00005*N:Ts:0.00002+0.00 005*(N+1);
Please learn how to format your code. Hightlght the code, then use the left-most button in the CODE tab in the toolstrip at the top to format it so it is readable.
채택된 답변
Star Strider
2020년 2월 23일
Going back to using my code (because it is easier to work with):
Ts=1/200e6;
t=Ts:Ts:0.00005;
y=[ones(1,2000) zeros(1,8000)];
x=sin(1256e6*t + 2198e10*t.^2);
z=x.*y;
NR = 4; % Number Of Repeats Desired
z_extended = reshape(repmat(z(:), NR, 1), [], 1).'; % Duplicate & Convert To Vector
t_extended = linspace(Ts, max(t)*NR, numel(t)*NR); % Time Vector
figure
plot(t,z)
figure
plot(t_extended, z_extended) % Plot Original
xlim([0 max(t_extended)*1E-1])
and adding the cross-correlation:
[xc,lags] = xcorr(z, z_extended);
figure
plot(lags, xc)
grid
produces:
댓글 수: 12
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!