-
Notifications
You must be signed in to change notification settings - Fork 5
/
NonUniformTest.m
165 lines (132 loc) · 6.09 KB
/
NonUniformTest.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
close all;
clear all;
clc;
%----------------Few Initializations-----------------------------------%
T = 0.001; % Sampling interval
a = 0; % t minimum
b = 1; % t maximum
t_cont = [a:T*.001:b]; % Dense
t= [a:T:b]; % Uniformly spaced
fontSize = 14;
lineWidth = 2;
%----------------------------------------------------------------------%
%------------------------------Creating Jittered Sampling---------------%
Non_Uni_Samples = length(t);
modifiedt = zeros (1, Non_Uni_Samples);
min = -5; % Min value
max = 5; % Max value
r = (max-min).*rand(1,Non_Uni_Samples) + min; % Randomly distributed Values
for i = 2:Non_Uni_Samples % Jittered model with additive non-uniform sampling
modifiedt(i) = modifiedt(i-1) + T + r(i)*T*10^-1;
end
% figure,
% hold on
% stem(t,ones(size(t)), 'b','LineWidth',2)
% stem(modifiedt,ones(size(modifiedt)),'r','LineWidth',2)
% axis([0.02 0.04 -.5 1.5])
% Ax = legend( 'Uniform Sampling', 'Additive Nonuniform Sampling')
% leg = findobj(Ax,'type','text')
% set(leg,'fontsize', fontSize)
% grid on
% hold off
%------------------------------------------------------------------------%
%-------------------------Specified parameters for the ANF----------------%
gamma = 0.001;
xi = .15;
%-------------------------------------------------------------------------%
%--------------------------Speficied Parameters for the signal----------%
N = length(t);
A = 1;
phi = pi/2;
stable = ( (gamma / (4*xi)) < 1)
% f = 60;
f = 170;
f_Est = zeros(size(f));
SNRdB = 5;
%------------------------------------------------------------------------%
%-----------------------Generating the Signals ---------------------------%
Y_Uniform = A * sin (2*pi*f*t + phi ) - 1+ awgn(zeros(size(t))+1,SNRdB,'measured'); % infecting the signal with additive noise
Y_NonUniform = A * sin (2*pi*f*modifiedt + phi ) -1 + awgn(zeros(size(modifiedt))+1,SNRdB,'measured'); % infecting the signal with additive noise
% Y_NonUniform = A* sin (2*pi*f*modifiedt + phi ) + A * sin (2*pi*230*modifiedt + phi )+ A * sin (2*pi*207.8*modifiedt + phi )+ + A * sin (2*pi*507.8*modifiedt + phi )+ + A * sin (2*pi*407.8*modifiedt + phi ) -5 + awgn(zeros(size(modifiedt))+5,SNRdB,'measured'); % infecting the signal with additive noise
%
% - 1+ awgn(zeros(size(modifiedt))+1,SNRdB,'measured');
% + A * sin (2*pi*230*modifiedt + phi )+ A * sin (2*pi*207.8*modifiedt + phi )+ + A * sin (2*pi*507.8*modifiedt + phi )+ + A * sin (2*pi*407.8*modifiedt + phi ) -5 + awgn(zeros(size(modifiedt))+5,SNRdB,'measured'); % infecting the signal with additive noise
Y_Continuous = A * sin (2*pi*f*t_cont + phi );
figure,
hold on
plot (t_cont,Y_Continuous, 'g','LineWidth',lineWidth)
stem(t,Y_Uniform, 'b','LineWidth',2)
stem(modifiedt,Y_NonUniform,'r','LineWidth',lineWidth)
hold off
axis([0.02 0.04 -2 2])
Ax = legend( 'Continuous (Noiseless)','Uniform (SNR = 5dB)', 'Nonuniform (SNR = 5dB)')
Ax.FontSize = fontSize;
% leg = findobj(Ax,'type','text')
% set(leg,'FontSize', fontSize)
ylabel ('Amplitude (units)')
xlabel ('Time(s)')
grid on
% print -depsc2 SignalUnifNonUnif
%-----------------------------------------------------------------------%
%------------------------Processing Frequency Estimation-----------------%
flag = (rand() < .5) ;
% if (flag == 0 )
freqError = +17;
% freqError = +6;
% else
% freqError = -17;
% freqError = -6;
% end
initialFreq = 2*pi*(f+ freqError);
% initialFreq = 2*pi*205;
[S1, S2,S3]= FourthOrderANFFixedBlock(Y_Uniform, T, initialFreq, gamma, xi); % This is a uniformly sampled system
[H1, H2,H3]= NonUniform4thOrderANFFixedBlock(Y_NonUniform, modifiedt, initialFreq, gamma, xi); % This is a non-uniformly sampled system
% % bandPassFreq = initialFreq;
% % xi_c = xi ;
% [ M1,M2,M3] = SpecialBP_NonUniform4thOrderANFFixedBlock (Y_NonUniform, modifiedt, initialFreq, gamma, xi, initialFreq, xi+.2, 0);
%
% [ X1,X2,X3] = Special4thOderBP_NonUniform4thOrderANFFixedBlock (Y_NonUniform, modifiedt, initialFreq, gamma, xi, initialFreq, xi+.2);
%
% [G1,G2,G3] = SpecialComplementary_NonUniform4thOrderANFFixedBlock(Y_NonUniform, modifiedt, initialFreq, gamma, xi);
% figure, plot (modifiedt,Y_NonUniform, modifiedt,BP1)
% legend('True/Desired', 'BP output')
figure, plot(t_cont,f*ones(size(t_cont)),'g', 'LineWidth', lineWidth)
title('(a)')
hold on
plot (t, S3/(2*pi),'b' ,'LineWidth', lineWidth)
plot (modifiedt, H3/(2*pi),'r', 'LineWidth', lineWidth)
% plot (modifiedt, M3/(2*pi),'k', 'LineWidth', lineWidth)
% plot (modifiedt, X3/(2*pi),'m', 'LineWidth', lineWidth)
% plot (modifiedt, G3/(2*pi),'c', 'LineWidth', lineWidth)
hold off
str1 = 'Estimated Uniform';
str2 = 'Estimated Nonuniform';
% str3 = 'Estimated with BP Intergrated'
% str4 = 'Estimated with BP 4th order Intergrated'
% str5 = 'Estimated with Complementary Intergrated'
% Ax = legend('True Value',str1, str2,str3,str4, 'Location','North')
Ax = legend('True Value',str1, str2, 'Location','North')
Ax.FontSize = fontSize;
% leg = findobj(Ax,'type','text')
% set(leg,'fontsize', fontSize)
ylabel ('Frequency (Hz)')
xlabel ('Time(s)')
% axis([a b 155 190])
grid on
axis tight
% print -depsc2 FreqConverUnifNonUnif % Higher Freq initialization, 170
% print -depsc2 FreqConverUnifNonUnif1 % Lower Freq initialization
% print -depsc2 FreqConverUnifNonUnif2 % Higher Freq initialization, 60
% print -depsc2 FreqConverUnifNonUnif3 % Lower Freq initialization
%------------------------------------------------------------------------%
%------------Plotting the first derivative of the approximation--------%
% Y_derivative = A *2*pi*f* cos (2*pi*f*modifiedt + phi );
% Y_Estimated_Derivatives = H1 .* H3 *(-2*xi);
% figure, plot (modifiedt, Y_derivative, modifiedt, Y_Estimated_Derivatives, 'LineWidth' , 2.3)
% Ax = legend ('True 1^{st} Derivative of y', 'Discrete ANF Approx, Dy')
% Ax.FontSize = fontSize;
% axis([.4 .6 -600 600])
% % axis([.4 .5 -1200 1200])
% ylabel ('Amplitude (units)')
% xlabel ('Time(s)')
% grid on