Skip to content

Instantly share code, notes, and snippets.

@tobin
Created October 8, 2012 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobin/3855279 to your computer and use it in GitHub Desktop.
Save tobin/3855279 to your computer and use it in GitHub Desktop.
Effect of zero-padding a DC signal
What happens when we take a non-zero but constant signal and upsample it by inserting zeros?
function y = applysos(soscoef, x)
% Apply a matrix of SOS cofficients to some time series.
%
% Tobin Fricke
% 2012-02-07
if size(soscoef,2) ~= 6
error('soscoef is not the right size');
end
y = x;
for ii=1:size(soscoef,1)
y = filter(soscoef(ii,1:3), soscoef(ii,4:6), y);
end
0 101
1.52588e-05 100
3.05176e-05 100
4.57764e-05 99
6.10352e-05 99
7.6294004e-05 98
9.15528e-05 96
0.0001068116 95
0.0001220704 127
0.0001373292 92
0.00015258801 95
0.0001678468 97
0.0001831056 99
0.0001983644 100
0.00021362321 101
0.000228882 101
0.0002441408 101
0.00025939959 101
0.00027465841 100
0.0002899172 100
0.00030517601 100
0.0003204348 100
0.00033569359 100
0.00035095241 100
0.0003662112 100
0.00038146999 100
0.00039672881 100
0.0004119876 100
0.00042724641 100
0.0004425052 100
0.00045776399 101
0.00047302281 101
0.0004882816 101
0.00050354039 100
0.00051879918 100
0.00053405802 99
0.00054931681 99
0.0005645756 98
0.00057983439 96
0.00059509318 95
0.00061035203 127
0.00062561082 92
0.00064086961 95
0.0006561284 97
0.00067138718 99
0.00068664597 100
0.00070190482 101
0.00071716361 101
0.0007324224 101
0.00074768119 101
0.00076293998 100
0.00077819882 100
0.00079345761 100
0.0008087164 100
0.00082397519 100
0.00083923398 100
0.00085449283 100
0.00086975162 100
0.00088501041 100
0.00090026919 100
0.00091552798 100
0.00093078677 100
0.00094604562 101
0.00096130441 101
0.0009765632 101
0.00099182199 100
0.0010070808 100
0.0010223396 99
% What is the effect of upsampling by inserting zeros
% on a constant nonzero (DC) signal?
%
% Tobin Fricke 2012-10-08
% timeseries with 2048 sampling rate
x = ones(16, 1);
tx = (0:length(x)-1) * 1/2048;
% upsample to 64kHz (factor of 32) by inserting zeros
y = upsample(x, 32);
ty = (0:length(y)-1) * 1/(2048*32);
% Here is the digital anti-imaging filter used in CDS:
gain = 0.010581064947739;
sos = [ -1.90444302586137, 0.91078434629894, -1.96090276933603, 0.99931924465090; ...
-1.92390910024681, 0.93366146580083, -1.84652529182276, 0.99866506867980];
% Put it into standard form
%
% The coefficients stored in the C code assume a form of the second order
% section where the leading coefficient in the numerator and the
% denominator are both 1. Here we insert those two 1's into the matrix,
% and also swap the numerator and denominator.
rows = size(sos,1);
sos = [ ones(rows,1) sos(:,3:4) ones(rows,1) sos(:,1:2) ];
Y = applysos(sos, y) * gain;
plot(ty, Y, '-o');
%% Load the experimental data for comparison, and plot it
data = dlmread('DACtimeseries.txt');
N=121+10*32; % time offset to line up properly and avoid startup transient
plot(data(:,1), 100*ones(size(data(:,2))), 'o-r', 'linewidth',2);
hold all
plot(data(:,1), data(:,2), 'o-', 'linewidth',3);
plot(ty(1:68), Y(N:N+67)*3220, 'x-g','linewidth',2);
hold off
axis tight
legend('what I expected', 'observed DAC timeseries', 'predicted timeseries \times arbitrary scaling');
title('Effect of zero-padded upsampling on a constant DC offset');
grid on
xlabel('time [seconds]');
ylabel('counts');
orient landscape
print -dpdf zeropadding_effect.pdf
orient portrait
print -r100 -dpng zeropadding_effect.png
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment