-
Notifications
You must be signed in to change notification settings - Fork 1
/
qpc_detection.m
89 lines (67 loc) · 1.72 KB
/
qpc_detection.m
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
80
81
82
83
84
85
86
function [] = qpc_detection(signal,fs)
signal = detrend(signal,14); % Remove the 14th degree polyonomial trend (removes peak at 0 Hz)
% Estimate power spectrum using basic spectral analysis
fftsignal = (fft(signal));
n = length(fftsignal); % number of samples
f = (0:n-1)*fs/n; % frequency range
power = abs(fftsignal).^2/n; % power of the DFT
power = (power/max(power)); % normalize the values
figure;
plot(f,power)
xlabel('Frequency')
ylabel('Power')
set(gca,'ylim',[0 2])
set(gca,'xlim',[0 20])
% Estimate bispectrum using direct method
M = 1024;
K = floor(length(signal)/M);
signal = signal(1:(K*M));
Y = reshape(signal,M,K);
Nfft = 512; % It will go up to 1024 inside the bispecd function
% Bispectrum
[bspec,waxis] = bispecd(Y,Nfft,1,M,0);
SS = Nfft/2+1;
waxis1 = waxis(SS:end)*fs;
figure
subplot(121)
bspec1 = bspec(SS:end,SS:end);
contour(waxis1,waxis1,abs(bspec1),10);
grid on
set(gca,'ylim',[-20 20])
set(gca,'xlim',[-20 20])
title('bispectrum')
xlabel('f1'),ylabel('f2')
% Bispectrum symmetries
hline1 = refline(0, 0);
hline1.Color = 'k';
hline2 = refline(-1, 0.5);
hline2.Color = 'k';
hline3 = refline(1, 0);
hline3.Color = 'k';
[X1,Y1] = meshgrid(waxis1,waxis1);
subplot(122)
mesh(X1,Y1,abs(bspec1))
axis tight;
set(gca,'ylim',[-20 20])
set(gca,'xlim',[-20 20])
ylabel('f1')
ylabel('f2')
zlabel('range')
title('bispectrum')
% Frequency ranges do not match with bispectrum
[co_bis,co_waxis] = bicoher(Y,Nfft,1,M,0);
waxis2 = co_waxis(SS:end)*fs;
figure()
subplot(121)
contour(waxis2,waxis2,abs(co_bis(SS:end,SS:end)),4);
grid on
title('coherent bispectrum')
xlabel('f1'),ylabel('f2')
subplot(122)
mesh(X1,Y1,abs(co_bis(SS:end,SS:end)));
axis tight
xlabel('f1')
ylabel('f2')
zlabel('range')
title('coherent bispectrum')
end