I want to do the correlation of the following two plots
6 views (last 30 days)
Show older comments
Devesh Yadav
on 23 Feb 2020
Commented: Star Strider
on 18 Mar 2020
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 Comments
Star Strider
on 23 Feb 2020
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.
Accepted Answer
Star Strider
on 23 Feb 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!