-
Notifications
You must be signed in to change notification settings - Fork 46
/
plot_result.asv
79 lines (68 loc) · 2.27 KB
/
plot_result.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
% PLOT RESULT:
% Test wather the C program FFT and XCORR is right
%
% RESULT:
% Good
close all;
clc
clear all;
x = load('test_fft.txt');
y = complex(x(:,1),x(:,2));
figure,
subplot(2,1,1),plot(abs(y(1:128)));
title('FFT Result');
subplot(2,1,3),plot(y(129:256));
title('IFFT Result');
subplot(2,1,2),plot(abs(y(1:128)));
title('FFT Result');
subplot(2,1,4),plot(y(129:256));
title('IFFT Result');
if exist('test_xcorr.txt', 'file')
dy = 2048;
x = load('test_xcorr.txt');
y = complex(x(:,1),x(:,2));
figure,
subplot(3,2,1);plot(y(1:dy));title('SIGNAL1');xlim([0,2048]);
subplot(3,2,3);plot(y(dy+1:2*dy));title('SIGNAL2');xlim([0,2048]);
subplot(3,2,5);plot(y(2*dy+1:3*dy));title('SIGNAL3');xlim([0,2048]);
subplot(3,2,2);plot(abs(y(3*dy+1:4*dy)));title('FFT1');xlim([0,2048]);
subplot(3,2,4);plot(abs(y(4*dy+1:5*dy)));title('FFT2');xlim([0,2048]);
subplot(3,2,6);plot(abs(y(5*dy+1:6*dy)));title('FFT3');xlim([0,2048]);
figure,
subplot(3,2,1);plot(abs(y(6*dy+1:7*dy)));title('CONJ1');xlim([0,2048]);
subplot(3,2,3);plot(abs(y(7*dy+1:8*dy)));title('CONJ2');xlim([0,2048]);
subplot(3,2,5);plot(abs(y(8*dy+1:9*dy)));title('CONJ3');xlim([0,2048]);
subplot(3,2,2);plot(real(y(9*dy+1:10*dy)));title('IFFT1');xlim([0,2048]);
subplot(3,2,4);plot(real(y(10*dy+1:11*dy)));title('IFFT2');xlim([0,2048]);
subplot(3,2,6);plot(real(y(11*dy+1:12*dy)));title('IFFT3');xlim([0,2048]);
y01 = abs(y(9*dy+1:10*dy));
y01(21:dy-20) = 0;
y02 = abs(y(10*dy+1:11*dy));
y02(21:dy-20) = 0;
y12 = abs(y(11*dy+1:12*dy));
y12(21:dy-20) = 0;
[m t01] = max(y01);
[m t20] = max(y02);
[m t12] = max(y12);
% MatlabË÷ÒýÖµ´Ó0¿ªÊ¼
% If txy>0 means x is ahead y abs(txy) nodes
t01 = t01 - 1;
t20 = t20 - 1;
t12 = t12 - 1;
if (t01>dy/2)
t01 = t01 - dy;
end
if (t20>dy/2)
t20 = t20 - dy;
end
if (t12>dy/2)
t12 = t12 - dy;
end
fprintf('\n==== Delay Time Calculate By Matlab ====\n');
fprintf('t01=%.2f, t20=%.2f, t12=%.2f\n', t01, t20, t12);
t01 = y(12*dy + 1);
t20 = y(12*dy + 2);
t12 = y(12*dy + 3);
fprintf('\n==== Delay Time Calculate By C ====\n');
fprintf('t01=%.2f, t20=%.2f, t12=%.2f\n', t01, t20, t12);
end