Skip to content

Instantly share code, notes, and snippets.

@pavhofman
Created January 7, 2020 11:12
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 pavhofman/1aad923d254e52ca425673ff06bbc158 to your computer and use it in GitHub Desktop.
Save pavhofman/1aad923d254e52ca425673ff06bbc158 to your computer and use it in GitHub Desktop.
Plotting undersampled signals
pkg load signal;
FS = 48000;
MULTIPLE = 100;
CONT_FS = MULTIPLE * FS;
F = 20000; % 20kHz
tCont = transpose(0:1/CONT_FS:5 * 1/F);
fundCont = 0.5 * sin(2*pi *F * tCont);
h2Cont = 0.25 * sin(2*pi *2 *F * tCont);
framesCont = [tCont, fundCont + h2Cont];
plot(framesCont(:, 1), framesCont(:, 2));
hold on;
% downsampling to FS without filtering - simply keeping every MULTIPLEth sample
framesSampled = downsample(framesCont, MULTIPLE);
stem(framesSampled(:, 1), framesSampled(:, 2), '.o', 'linewidth', 2, 'markersize', 20);
F_SPUR = 8000;
spuriousCont = -0.125 * sin(2*pi *F_SPUR * tCont);
framesCont = [tCont, fundCont + 0.5 * h2Cont + spuriousCont];
plot(framesCont(:, 1), framesCont(:, 2));
% sampling at FS - keeping every MULTIPLEth sample
framesSampled = downsample(framesCont, MULTIPLE);
stem(framesSampled(:, 1), framesSampled(:, 2), '.x', 'linewidth', 2, 'markersize', 20);
hold off;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment