Skip to content

Instantly share code, notes, and snippets.

@caiorss
Forked from morganp/fft_demo.m
Created December 25, 2016 21:17
Show Gist options
  • Save caiorss/fcde755ac7d025c2a124553f4ba5d752 to your computer and use it in GitHub Desktop.
Save caiorss/fcde755ac7d025c2a124553f4ba5d752 to your computer and use it in GitHub Desktop.
Basic Matlab FFT
%% Trial FFT
% http://www.mathworks.co.uk/help/matlab/math/fast-fourier-transform-fft.html
fs = 48000; % Sample Rate
n = 4096; % Power of 2 number of samples/ length of FFT
% Get/Generate data
t = 0:1/fs:10-1/fs; % 10 sec sample
x = (1.3)*sin(2*pi*15*t) ... % 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)) ... % 40 Hz component
+ (2.5)*randn(size(t));
%# Frequency Bins
bins = (0:1:n-1)*(fs/n);
y = fft(x,n);
%# plot fft
% plot(bins, abs(y));
% title('FFT')
% xlabel('Frequency (Hz)')
% ylabel('Magnitude')
plot(bins, 20*log(abs(y)));
title('FFT')
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment