✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.

Fast Fourier Transform in MATLAB®

An example of FFT audio analysis in MATLAB® and the fft function.


sigtext = urlread('https://raw.githubusercontent.com/plotly/documentation/master/aux/fft-matlab');

sig = str2num(sigtext);

fs = 44100;

dur = 1;

t = linspace(0,dur,fs);

N = 4096;

freq = linspace(0,fs,N);

F = fft(sig,N);

maxFreq = N/16; 

fig = figure;
subplot(2,1,1)
plot(t, sig)
title('GUITAR C4 TEMPORAL/SPECTRAL VISUALIZATION');
ylabel('AMPLITUDE');
xlabel('TIME(s.)')

subplot(2,1,2)
plot(freq(1:maxFreq),abs(F(1:maxFreq)));
ylabel('MAGNITUDE');
xlabel('FREQUENCY(Hz.)');

fig2plotly(fig);