📄 check_wimax_duc_s3sd_v1.m
字号:
%--------------------------------------------------------------------------
%Copyright (c) 2007 Xilinx, Inc.
%This code is confidential and proprietary of Xilinx, All Rights Reserved.
%--------------------------------------------------------------------------
%Filename: check_wimax_duc_s3sd_v1.m
%Purpose: This program checks that the output of the wimax_duc_s3sd_v1
% system generator design matches a bit-true behavioral model.
%--------------------------------------------------------------------------
BitTrue = 1;
DitherOn = 1;
Fs = 89.6;
Nfft = 1024;
%-------------------------------------------------------------------%
%Capture the design inputs and outputs after reset is released
%-------------------------------------------------------------------%
if find(Reset)
tResetOff = max(find(Reset))+1;
else
tResetOff = 1;
end
DataInAfterReset = Iin(tResetOff:end) + j*Qin(tResetOff:end);
SyncAfterReset = Sync(tResetOff:end);
DataOutAfterReset = Iout(tResetOff:end) + j*Qout(tResetOff:end);
ValidAfterReset = Valid(tResetOff:end);
x = DataInAfterReset(find(SyncAfterReset));
%-------------------------------------------------------------------%
%Model the interpolation filters
%-------------------------------------------------------------------%
load coefficients
if BitTrue %Use simple round (matches hardware)
y1 = floor(upfirdn(x,h1,2,1)*2^15 + 0.5 + 0.5*j)/2^15;
y2 = floor(upfirdn(y1,h2,2,1)*2^15 + 0.5 + 0.5*j)/2^15;
y3 = floor(upfirdn(y2,h3,2,1)*2^15 + 0.5 + 0.5*j)/2^15;
y4 = floor(upfirdn(y3,h4,2,1)*2^15 + 0.5 + 0.5*j)/2^15;
else %Use symmetric round (ideal)
y1 = round(upfirdn(x,h1,2,1)*2^15)/2^15;
y2 = round(upfirdn(y1,h2,2,1)*2^15)/2^15;
y3 = round(upfirdn(y2,h3,2,1)*2^15)/2^15;
y4 = round(upfirdn(y3,h4,2,1)*2^15)/2^15;
end
if BwSel(1)
yfilt = y3;
D = 10;
else
yfilt = y4;
D = 21;
end
%-------------------------------------------------------------------%
%Model the mixer
%-------------------------------------------------------------------%
if BitTrue
%Make the frequency command a 32-bit unsigned integer
FreqCmd = Freq(1);
%Accumulate and wrap modulo 2^32.
Accum = FreqCmd*[(1+D):1:length(yfilt)+D]';
Accum = mod(Accum, 2^32);
%Divide by 2^19 to obtain 13 bits of integer and 19 bits of fraction
Accum = Accum/(2^19);
%Add the dither sequence (modulo 2^13 to wrap on overflow)
if DitherOn
load dither_sequence
Sum = Accum + floor(2^6*dither_sequence(2+D:length(Accum)+1+D))/2^7;
Sum = mod(Sum, 2^13);
else
Sum = Accum;
end
%Truncate to 13 bits of integer and then shift to be all fractional
Phase = floor(Sum)/2^13;
%Compute the sine and cosine
Delta = (0.5/8192);
coswt = cos(2*pi*(Phase + Delta));
sinwt = sin(2*pi*(Phase + Delta));
%Quantize to 16 bits (signed)
width = 16;
maxvalue = 2^(width-1) - 1;
xnorm = coswt/cos(2*pi*Delta);
coswt = round(xnorm*maxvalue)/2^(width-1);
xnorm = sinwt/cos(2*pi*Delta);
sinwt = round(xnorm*maxvalue)/2^(width-1);
%Multiply the I and Q data by the cosine and sine
yfilti = real(yfilt);
yfiltq = imag(yfilt);
ymixeri = floor((yfilti.*coswt - yfiltq.*sinwt)*2^15 + 0.5)/2^15;
ymixerq = floor((yfiltq.*coswt + yfilti.*sinwt)*2^15 + 0.5)/2^15;
ymixer = ymixeri + j*ymixerq;
else %Multiply by a complex sinusoid
f0 = (Freq(1)/2^32)*Fs;
ymixer = yfilt.*exp(j*2*pi*(f0/Fs)*([1+D:1:length(yfilt)+D]' + 0.5/8192));
ymixer = round(ymixer*2^15)/2^15;
end
%-------------------------------------------------------------------%
%Model the gain control
%-------------------------------------------------------------------%
y = round(2^15*Gain(1)*ymixer)/2^15;
%-------------------------------------------------------------------%
%Check that the implementation matches the bit-true model
%-------------------------------------------------------------------%
z = DataOutAfterReset(find(ValidAfterReset));
N = length(z((1+D):end-1));
err = y(1:N) - z((1+D):end-1);
if find(err)
fprintf('Error: Mismatches found.\n');
fprintf('Max Abs Error (LSBs): %d\n', max(max(abs([real(err), imag(err)])))*2^15);
fprintf('Number of Mismatches: %d (out of %d)\n', length(find(err)), length(err));
else
fprintf('Check Passed!\n');
end
figure
subplot(211)
plot(real(y(1:N)))
hold on; grid on; zoom on;
ylim([-1,1]);
plot(real(z((1+D):end-1)), 'm');
subplot(212)
plot(imag(y(1:N)))
hold on; grid on; zoom on;
ylim([-1,1]);
plot(imag(z((1+D):end-1)), 'm');
plot_psd2(y(1:N), z((1+D):end-1), Fs, Nfft);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -