DSPRelated.com
Forums

plot of cross correlation of two signals

Started by kostas October 24, 2008
Hi guys i have the following problem  i have two signals
x=500*cos(2*pi*fc*t)*rect((t-0.5T)/T) and x1 which is delayed by 0.1
sec fc=1250   T=40msec and fs=5000Hz i have to plot the correlation
Rx1x and i used the following code but the plot ( i have to plot tau
in msec) seems that is not right with the theoretical calculations

                        Thanks in advance KS

figure(1)
format long
A=500;      %a(t)=A is a constant%
fc=1250;
theta=0;
T=0.04;    %Is the pulse Length in seconds%
fs=5000;
ts=0.0002;
tlast=0.04;
tstart=0;
w=rectwin(201);
t=[0:ts:tlast];
x=(A*cos((2*(pi)*fc*t)+theta)).*w';
x1=(A*cos(2*(pi)*fc*(t-0.1)+theta)).*w';
plot(t,x)
rid
title(' Plot of Transmitted Signal x(t) versus time' )
xlabel('t in seconds')
ylabel('x(t) for fs=5KHZ, for 0<=t<=0.04 sec')
figure(2)
plot(t,x1)
grid
title(' Plot of Transmitted Signal x(t-0.1) versus time' )
xlabel('t in seconds')
ylabel('x(t) for fs=5KHZ, for 0<=t<=0.04 sec')


figure(2)
n = [1:200];
A=500;
fc=1250;    %   fc=1.25kHZ carrier freq
N=5000;
Ts=1/fs;
x = A*cos(2*pi*(n-1)*fc*Ts);
x1= A*cos(2*pi*(n-1)*fc*Ts-2*pi*fc*0.1);


figure(3)
Rxx=abs(xcorr(x1,x,5000))/5000;
R=cplxf1(Rxx,0.000001)
t=[1/50000:1/50000:10001/50000];
plot(t-1/50000,R)
axis([0.060 0.140 0 5001])


% Function that removes  distortion at correlation
function ff=cplxf1(f,threshold)
 fr = f;
 irz = find(fr<threshold);
 fr(irz) = 0.0000000000000;
 ff = fr;

On 24 Okt, 10:01, kostas <kostasspyri...@hotmail.com> wrote:
> Hi guys i have the following problem &#4294967295;i have two signals > x=500*cos(2*pi*fc*t)*rect((t-0.5T)/T) and x1 which is delayed by 0.1 > sec fc=1250 &#4294967295; T=40msec and fs=5000Hz i have to plot the correlation > Rx1x and i used the following code but the plot ( i have to plot tau > in msec) seems that is not right with the theoretical calculations
There is too much going on in your plots for me to follow. First of all, use SUBPLOT to get a new axis in the existing figure. There is no problems having three or four axes in one plot; juggling three or four figures is a mess. Second, compute the AUTO correlation of one simple signal (e.g. a square pulse [*]) to get a handle on the timing. You know that the resulting sequence is supposed to be 2N-1 long with the peak at tau = 0 (which will be at index N in the array). That way you get a clear grip on what you try to do. Next, plot the CROSS correlation between two square pulses of different lengths [**]. Now you need to deal with the fact that the resulting signal will be of length N1+N2+1, with the correlation maximumat will be either N1 or N2, depending on eacatly what cross correlation you plot, cxy or cyx. Now you can test your approach by plotting the cross correlation of a delayed square pulse [***]. The correlation maximumwill be at N1+D or N2+D, where D is the delay, depending on if you plot cxy or cyx. So the idea is to take one step at the time, make sure you understand what is going on, that you get the correct answers at each step, and only then proceed to the next step. Engineering craftmanship. Rune [*] N = 100; x = zeros(N,1); M = round N/10; x(1:M) = ones(M,1); [**] N1 = 100; N2 = 50; M1 = round(N1/10); M2 = round(N2/10); x = zeros(N1,1); x(1:M1) = ones(M1,1); y = zeros(N2,1); y(1:M2) = ones(M2,1); [***] N1 = 100; N2 = 50; M1 = round(N1/10); M2 = round(N2/10); D = 5; x = zeros(N1,1); y = zeros(N2,1); x = zeros(N1,1); x(D+1:M1) = ones(M1,1); y = zeros(N2,1); y(1:M2) = ones(M2,1);