Skip to content

Instantly share code, notes, and snippets.

@stephenHartzell
Created July 26, 2017 03:29
Show Gist options
  • Save stephenHartzell/2d12f18f888a792021e0a81bf21696d5 to your computer and use it in GitHub Desktop.
Save stephenHartzell/2d12f18f888a792021e0a81bf21696d5 to your computer and use it in GitHub Desktop.
Fs = 10; % Sampling frequency
Ts = 1/Fs; % Sampling period
N = 128; % Total number of samples
n = 0:N-1; % Samples
t = Ts*(n); % Sampled times
fc1 = 1; % Frequency of first sinusoid
fc2 = 1.5; % Frequency of second sinusoid
y1 = cos(2*pi*fc1*t); % Discrete first sinusoid
y2 = cos(2*pi*fc2*t); % Discrete second sinusoid
y = y1+y2; % Total discrete signal
Y = fft(y); % The fft of the signal
df = 1/(N*Ts); % The frequency resolution
k = n; % Frequency spectrum samples
f = k*df; % Frequency values at the k samples
% Plot the useful fft of the signal with more samples
figure
stem(f,abs(Y)./N,'filled')
title('Useful Fourier Transform of y')
ylabel('Scaled |fft(y)|')
xlabel('frequency (Hz)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment