OpenCores
URL https://opencores.org/ocsvn/iqcorrection/iqcorrection/trunk

Subversion Repositories iqcorrection

[/] [iqcorrection/] [branches/] [implemented with real variables/] [IQCorrectGain_Phase.m] - Blame information for rev 26

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 Abraxas3d
% New IQ Correction algorithm, yet the third one
2
close all;
3
clear all;
4
e1 = 0.1; %gain error
5
 
6
%phase error
7
a1 = 10*pi/180;
8
%a1 = -10*pi/180;
9
 
10
%original noise
11
sgma = 0.01; %noise sigmage
12
 
13
%original sample length
14
%n_dat = 250000; % number of samples
15
n_dat = 100000; % number of samples
16
 
17
freq = 0.03;  % relative frequency
18
 
19
amplitude = 1;
20
 
21
%in phase signal, or I
22
x1=amplitude*cos(2*pi*(0:n_dat-1)*freq)+sgma*randn(1,n_dat);
23
 
24
%quadrature signal, or Q
25
y1=amplitude*(1+e1)*sin(2*pi*(0:n_dat-1)*freq+a1) + sgma*randn(1,n_dat);
26
 
27
reg_1 = 0;
28
reg_2 = 1;
29
 
30
%original mu
31
%mu_1 = 0.0002;
32
%mu_2 = 0.0001;
33
 
34
%mu adjusted to closest powers of two in order to match VHDL implementation
35
mu_1 = 0.000244;
36
mu_2 = 0.000122;
37
 
38
 
39
y2=zeros(1,n_dat);
40
y3=zeros(1,n_dat);
41
reg_1_sv = zeros(1,n_dat);
42
reg_2_sv = zeros(1,n_dat);
43
 
44
 
45
 
46
 
47
 
48
 
49
 
50
 
51
 
52
 
53
I_data = fopen('I_data_octave', 'w+t', 'native');
54
Q_data = fopen('Q_data_octave', 'w+t', 'native');
55
 
56
phase_estimate = fopen('phase_error_estimate_octave', 'w+t', 'native');
57
gain_estimate = fopen('gain_error_estimate_octave', 'w+t', 'native');
58
 
59
 
60
 
61
for nn=1:n_dat
62
    y2(nn) = y1(nn)-reg_1*x1(nn);
63
    reg_1_sv(nn) = reg_1;
64
    reg_1 = reg_1 + mu_1*x1(nn)*y2(nn);
65
 
66
    fprintf (I_data, '%f\r\n', x1(nn));
67
    fprintf (Q_data, '%f\r\n', y1(nn));
68
    fprintf (phase_estimate, '%f\r\n', reg_1);
69
 
70
    y3(nn) = y2(nn)*reg_2;
71
    reg_2_sv(nn) = reg_2;
72
 
73
    %original reg_2
74
    %reg_2 = reg_2+mu_2*(abs(x1(nn))^2 - abs(y3(nn))^2);
75
 
76
    %proposed reg_2
77
    reg_2 = reg_2+mu_2*((x1(nn))^2 - (y3(nn))^2);
78
    fprintf (gain_estimate, '%f\r\n', reg_2);
79
end
80
 
81
 
82
fclose(I_data);
83
fclose(Q_data);
84
 
85
fclose(phase_estimate);
86
fclose(gain_estimate);
87
 
88
 
89
 
90
 
91
 
92
figure(1)
93
subplot(2,1,1);
94
plot(reg_1_sv);
95
hold on;
96
plot([0 n_dat], [1 1]*a1*(1+e1), 'r');
97
hold off;
98
grid on;
99
title('Phase Error Estimate Trajectory')
100
 
101
subplot(2,1,2)
102
plot(reg_2_sv);
103
hold on
104
 
105
%original plot
106
%plot([0 n_dat], [1.0 1.0]/(1.0+e1), 'r');
107
 
108
%proposed plot
109
plot([0 n_dat], [1.0 1.0]/((1.0+e1)*(cos(a1))), 'r');
110
hold off
111
grid on
112
title('Gain Error Estimate Trajectory')
113
%added following line to make pngs
114
print("figure1_longer.png", "-dpng")
115
 
116
figure(2)
117
subplot(1,3,1)
118
plot(x1,y1)
119
hold on
120
plot(x1,y1,'r.')
121
plot([1 1 -1 -1 1],[1 -1 -1 1 1],'-r')
122
hold off
123
grid on
124
axis('square')
125
axis([-1.2 1.2 -1.2 1.2])
126
title('Lissajou Diagram, Gain & Phase Offset')
127
 
128
subplot(1,3,2)
129
plot(x1, y2)
130
hold on
131
plot(x1,y2, 'r.')
132
plot([1 1 -1 -1 1],[1 -1 -1 1 1],'-r')
133
hold off
134
grid on
135
axis('square')
136
axis([-1.2 1.2  -1.2 1.2])
137
title('Lissajou Diagram, Phase Offset Corrected')
138
 
139
subplot(1,3,3)
140
plot(x1, y3)
141
hold on
142
plot(x1,y3, 'r.')
143
plot([1 1 -1 -1 1],[1 -1 -1 1 1],'-r')
144
hold off
145
grid on
146
axis('square')
147
axis([-1.2 1.2  -1.2 1.2])
148
title('Lissajou Diagram, Gain & Phase Offset Corrected')
149
 
150
%added following line to make pngs
151
print("figure2_longer.png", "-dpng")
152
 
153
 
154
figure(3)
155
subplot(3,1,1)
156
 
157
%original MATLAB code used kaiser window function
158
%is commented out in this section.
159
%kaiser is in the package octave-windows
160
%this package turned out to be hard to install
161
%kaiser was replaced with blackman-harris window function.
162
%ww=kaiser(1024,12)';
163
 
164
ww=blackman(1024)';
165
 
166
 
167
ww=ww/sum(ww);
168
tt=n_dat-1023:n_dat;
169
plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft((x1(tt)+1i*y1(tt)).*ww)))))
170
% z=zeros(1,1024);
171
% for kk=1:1024
172
%    z(kk)=(x1(tt(kk))+1i*y1(tt(kk)))*ww(kk);
173
% end
174
% plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft(z)))))
175
grid on
176
axis([-0.5 0.5 -140 10])
177
title('Output Spectrum with Gain and Phase Offset')
178
 
179
subplot(3,1,2)
180
tt=n_dat-1023:n_dat;
181
% z=zeros(1,1024);
182
% for kk=1:1024
183
%     z(kk)=(x1(tt(kk))+1i*y2(tt(kk)))*ww(kk);
184
% end
185
% plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft(z)))));
186
plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft((x1(tt)+1i*y2(tt)).*ww)))))
187
grid on
188
axis([-0.5 0.5 -140 10])
189
title('Output Spectrum with Phase Offset Corrected')
190
 
191
subplot(3,1,3)
192
tt=n_dat-1023:n_dat;
193
% z=zeros(1,1024);
194
% for kk=1:1024
195
%     z(kk)=(x1(tt(kk))+1i*y3(tt(kk)))*ww(kk);
196
% end
197
% plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft(z)))));
198
plot(-0.5:1/1024:0.5-1/1024,fftshift(20*log10(abs(fft((x1(tt)+1i*y3(tt)).*ww)))))
199
grid on
200
axis([-0.5 0.5 -140 10])
201
title('Output Spectrum with Gain & Phase Offset Corrected')
202
 
203
%added following line to make pngs
204
print("figure3_longer.png", "-dpng")
205
 
206
disp('last reg_1 is ')
207
reg_1
208
disp('last reg_2 is ')
209
reg_2

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.