Skip to content

Instantly share code, notes, and snippets.

@Arunprakash-A
Last active July 17, 2018 10:12
Show Gist options
  • Save Arunprakash-A/79481937789ed132b18671c87ea0c3ae to your computer and use it in GitHub Desktop.
Save Arunprakash-A/79481937789ed132b18671c87ea0c3ae to your computer and use it in GitHub Desktop.
%% Computing FFT for Basic Signals and plot the spectra %%
%% Author: A Arun Prakash Mail:a.arun283@gmail.com %%
clc
close all;
%Generae sin signal of 10 Hz
Fs=1000; % Sampling Frequency > 2 * fmax , here fmax = 10
t=0:(1/Fs):1;
x=sin(2*pi*10*t);
%%% Your COde Goes Here to plot the spectra of x %%%
% First compute length of input
L=length(x);
% Check whether length is in power of 2
NFFT = 2^nextpow2(L)
% use this length to compute N-point FFT to the input
Y = fft(x,NFFT)/L;
% Plot the spectrum
f = Fs/2*linspace(-1,1,NFFT);
Y=fftshift(Y);
plot(f,2*abs(Y))
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
%% Approx 4 lines of code %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment