I want to do the correlation of the following two plots

6 views (last 30 days)
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
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.
Devesh Yadav
Devesh Yadav on 23 Feb 2020
There was a typing mistake from my side. Please check it once more

Sign in to comment.

Accepted Answer

Star Strider
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
Devesh Yadav
Devesh Yadav on 18 Mar 2020
Can you please tell me the no. of computations done in this correlation :- [xc,lags] = xcorr(z, z_extended);
Star Strider
Star Strider on 18 Mar 2020
I cannot.
I doubt that would be possible to determine.

Sign in to comment.

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!