Skip to content

Instantly share code, notes, and snippets.

@stephenHartzell
Created July 26, 2017 02:37
Show Gist options
  • Select an option

  • Save stephenHartzell/b7cca5c92a664077e2a35701a4e14778 to your computer and use it in GitHub Desktop.

Select an option

Save stephenHartzell/b7cca5c92a664077e2a35701a4e14778 to your computer and use it in GitHub Desktop.
Fs = 10; % Sampling frequency
Ts = 1/Fs; % Sampling period
N = 32; % Total number of samples
n = 0:N-1; % Samples
t = Ts*(n); % Sampled times
y = cos(2*pi*t); % Discrete 1 Hz signal
yp = cos(18*pi*t); % Discrete 9 Hz signal
ypp = cos(20*pi*t); % Discrete 10 Hz signal
% Plot the 1 Hz signal and its discrete counter-part
figure
subplot(3,1,1)
stem(t,y,'filled')
hold on;
% The 'continuous signal' (interpolated and highly sampled signal)
plot(linspace(min(t),max(t),length(0:.01:max(t))),cos(2*pi*(0:.01:max(t))))
title(['Sampled 1 Hz Signal with Fs = ',num2str(Fs)])
% Plot the 9 Hz signal and its discrete counter-part
subplot(3,1,2)
stem(t,yp,'filled')
hold on;
% The 'continuous signal' (interpolated and highly sampled signal)
plot(linspace(min(t),max(t),length(0:.01:max(t))),cos(18*pi*(0:.01:max(t))))
title(['Sampled 9 Hz Signal with Fs = ',num2str(Fs)])
% Plot the 10 Hz signal and its discrete counter-part
subplot(3,1,3)
stem(t,ypp,'filled')
hold on;
% The 'continuous signal' (interpolated and highly sampled signal)
plot(linspace(min(t),max(t),length(0:.01:max(t))),cos(20*pi*(0:.01:max(t))))
title(['Sampled 10 Hz Signal with Fs = ',num2str(Fs)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment