- Minor changes
git-svn-id: http://moon:8086/svn/vhdl/trunk@220 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
function tb_results()
|
function tb_results()
|
||||||
fa = 100.0;
|
fa = 100.0;
|
||||||
R = TEXTREAD('ratio.txt');
|
R = TEXTREAD('ratio.txt');
|
||||||
N = 3;
|
N = TEXTREAD('nstages.txt');;
|
||||||
M = 1;
|
M = 1;
|
||||||
fa_dec = fa/R
|
fa_dec = fa/R
|
||||||
N_pfir = 63;
|
N_pfir = 63;
|
||||||
@@ -12,18 +12,27 @@ Q_out_dec = TEXTREAD('q_dec.txt')';
|
|||||||
I_out_fir = TEXTREAD('i_fir.txt')';
|
I_out_fir = TEXTREAD('i_fir.txt')';
|
||||||
Q_out_fir = TEXTREAD('q_fir.txt')';
|
Q_out_fir = TEXTREAD('q_fir.txt')';
|
||||||
|
|
||||||
|
I_out_fir = I_out_fir(1:2:length(I_out_fir));
|
||||||
|
Q_out_fir = Q_out_fir(1:2:length(Q_out_fir));
|
||||||
|
|
||||||
N_dec = length(I_out_dec)-2*N_pfir;
|
N_dec = length(I_out_dec)-2*N_pfir;
|
||||||
N_fft_dec = N_dec
|
N_fft_dec = N_dec
|
||||||
N_fft2_dec = N_fft_dec/2;
|
N_fft2_dec = N_fft_dec/2;
|
||||||
|
|
||||||
fft_y2_fir = 2/N_fft_dec*abs(fft(I_out_fir(2*N_pfir+1:N_fft_dec+2*N_pfir).*hann(N_fft_dec)'));
|
N_fir = length(I_out_fir)-2*N_pfir;
|
||||||
|
N_fft_fir = N_fir
|
||||||
|
N_fft2_fir = N_fft_fir/2;
|
||||||
|
|
||||||
|
fft_y2_fir = 2/N_fft_fir*abs(fft(I_out_fir(2*N_pfir+1:N_fft_fir+2*N_pfir).*hann(N_fft_fir)'));
|
||||||
|
|
||||||
pfir_b = sinc(0.2*(-(N_pfir-1)/2:1:(N_pfir)/2));
|
|
||||||
pfir_b = pfir_b/sum(pfir_b).*blackman(N_pfir)';
|
|
||||||
I_out_dec = I_out_dec;
|
|
||||||
Q_out_dec = Q_out_dec;
|
|
||||||
fft_y2_dec = 2/N_fft_dec*abs(fft(I_out_dec(2*N_pfir+1:N_fft_dec+2*N_pfir).*hann(N_fft_dec)'));
|
fft_y2_dec = 2/N_fft_dec*abs(fft(I_out_dec(2*N_pfir+1:N_fft_dec+2*N_pfir).*hann(N_fft_dec)'));
|
||||||
|
|
||||||
|
f = (1:N_fft_dec)/N_fft_dec;
|
||||||
|
g = (R*M)^N;
|
||||||
|
H = abs(sin(pi*M.*f)./sin(pi.*f/R)).^N;
|
||||||
|
|
||||||
|
H = max(fft_y2_fir(1:2))*H ./ g;
|
||||||
|
|
||||||
wavwrite(0.45*[I_out_fir'-mean(I_out_fir) Q_out_fir'-mean(Q_out_fir)], 8000, 16, 'iq_cfir.wav');
|
wavwrite(0.45*[I_out_fir'-mean(I_out_fir) Q_out_fir'-mean(Q_out_fir)], 8000, 16, 'iq_cfir.wav');
|
||||||
wavwrite(0.45*[I_out_dec'-mean(I_out_dec) Q_out_dec'-mean(Q_out_dec)], 8000, 16, 'iq.wav');
|
wavwrite(0.45*[I_out_dec'-mean(I_out_dec) Q_out_dec'-mean(Q_out_dec)], 8000, 16, 'iq.wav');
|
||||||
|
|
||||||
@@ -36,8 +45,14 @@ figure;
|
|||||||
cic_plot(M, N, R);
|
cic_plot(M, N, R);
|
||||||
|
|
||||||
figure;
|
figure;
|
||||||
plot(fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_fir(1:N_fft2_dec+1)), '-', fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_dec(1:N_fft2_dec+1)), '-');
|
subplot(2,1,1)
|
||||||
legend('CFIR', 'no CFIR');
|
plot(fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_dec(1:N_fft2_dec+1)), '-', fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(H(1:N_fft2_dec+1)), 'r-');
|
||||||
|
legend('CIC', 'Droop');
|
||||||
|
xlabel('MHz');
|
||||||
|
grid;
|
||||||
|
subplot(2,1,2)
|
||||||
|
plot(fa/(2*R*N_fft_fir)*(0:N_fft2_fir),20*log10(fft_y2_fir(1:N_fft2_fir+1)), '-');
|
||||||
|
legend('CFIR');
|
||||||
xlabel('MHz');
|
xlabel('MHz');
|
||||||
grid;
|
grid;
|
||||||
|
|
||||||
|
|||||||
@@ -306,8 +306,6 @@ BEGIN
|
|||||||
rfgen_q_out_f <= to_real(rfgen_dout_q);
|
rfgen_q_out_f <= to_real(rfgen_dout_q);
|
||||||
|
|
||||||
tb : PROCESS
|
tb : PROCESS
|
||||||
file RESULT_FREQ: text open write_mode is "ratio.txt";
|
|
||||||
variable L: line;
|
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
@@ -315,8 +313,6 @@ BEGIN
|
|||||||
wait for 4*PERIOD;
|
wait for 4*PERIOD;
|
||||||
rst <= '0';
|
rst <= '0';
|
||||||
|
|
||||||
fprint(RESULT_FREQ, L,"%s\n", natural'image(cic_ratio));
|
|
||||||
|
|
||||||
wait for 2*PERIOD;
|
wait for 2*PERIOD;
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
-- Program gains
|
-- Program gains
|
||||||
@@ -353,6 +349,21 @@ BEGIN
|
|||||||
wait;
|
wait;
|
||||||
END PROCESS;
|
END PROCESS;
|
||||||
|
|
||||||
|
tb_param : PROCESS
|
||||||
|
file RESULT_R: text open write_mode is "ratio.txt";
|
||||||
|
file RESULT_N: text open write_mode is "nstages.txt";
|
||||||
|
variable L: line;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- Wait 100 ns for global reset to finish
|
||||||
|
wait until rising_edge(clk) and rst = '0';
|
||||||
|
fprint(RESULT_R, L,"%s\n", natural'image(cic_ratio));
|
||||||
|
fprint(RESULT_N, L,"%s\n", natural'image(cic_nstages));
|
||||||
|
wait;
|
||||||
|
|
||||||
|
END PROCESS;
|
||||||
|
|
||||||
tb_fo : PROCESS(clk)
|
tb_fo : PROCESS(clk)
|
||||||
file RESULT_Ii: text open write_mode is "i_in.txt";
|
file RESULT_Ii: text open write_mode is "i_in.txt";
|
||||||
file RESULT_Qi: text open write_mode is "q_in.txt";
|
file RESULT_Qi: text open write_mode is "q_in.txt";
|
||||||
@@ -363,21 +374,22 @@ BEGIN
|
|||||||
variable L: line;
|
variable L: line;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
if rising_edge(clk) and fileout_enable = '1' then
|
if rising_edge(clk) then
|
||||||
if ddc_din_vld = '1' then
|
if fileout_enable = '1' then
|
||||||
fprint(RESULT_Ii, L,"%s\n", REAL'image(to_real(rfgen_dout_i)));
|
if ddc_din_vld = '1' then
|
||||||
fprint(RESULT_Qi, L,"%s\n", REAL'image(to_real(rfgen_dout_q)));
|
fprint(RESULT_Ii, L,"%s\n", REAL'image(to_real(rfgen_dout_i)));
|
||||||
end if;
|
fprint(RESULT_Qi, L,"%s\n", REAL'image(to_real(rfgen_dout_q)));
|
||||||
if ddc_dout_vld = '1' then
|
end if;
|
||||||
fprint(RESULT_Ifir, L,"%s\n", REAL'image(to_real(ddc_dout_i)));
|
if ddc_dout_vld = '1' then
|
||||||
fprint(RESULT_Qfir, L,"%s\n", REAL'image(to_real(ddc_dout_q)));
|
fprint(RESULT_Ifir, L,"%s\n", REAL'image(to_real(ddc_dout_i)));
|
||||||
end if;
|
fprint(RESULT_Qfir, L,"%s\n", REAL'image(to_real(ddc_dout_q)));
|
||||||
if ddc_dec_vld = '1' then
|
end if;
|
||||||
fprint(RESULT_Idec, L,"%s\n", REAL'image(to_real(ddc_dec_i)));
|
if ddc_dec_vld = '1' then
|
||||||
fprint(RESULT_Qdec, L,"%s\n", REAL'image(to_real(ddc_dec_q)));
|
fprint(RESULT_Idec, L,"%s\n", REAL'image(to_real(ddc_dec_i)));
|
||||||
|
fprint(RESULT_Qdec, L,"%s\n", REAL'image(to_real(ddc_dec_q)));
|
||||||
|
end if;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
END PROCESS;
|
END PROCESS;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
|
|||||||
Reference in New Issue
Block a user