Perform FFTW of a song
1 view (last 30 days)
Show older comments
Hi there. I was wondering if someone here could help me write a code to performe a fft of a song. i im trying to write a code to perfrorm the fft because i want to use the tranfromation to make a motor vibrate according to the frequency output. i have tried a few codes i found but none of them work.
so basically the code consists of having an imported song file and then the fft of the same.
I can plot the amplitude vs time graph, but i dont know how to plot the amplitude vs frequency graph.... I know i have to to the fft, but from there im confused.
clc
[y, fs] = audioread('C:\Users\cesar\Dropbox\My PC (LAPTOP-JN8DA0O5)\Downloads\cb.mp3');
%-----------------------------------------------
tD = (1 : length(y)) / fs;
tDouble1 = tD / 60;
tvar = datetime(0,0,0) + minutes(tD);
%---------------------------------------------
t = 0:0.001:tD;
N = size(t,1);
X = fftshift(fft(y));
dF = fs/N;
r=abs(X)/N;
f = -fs/2:dF:fs/2-dF;
figure(1)
plot(tvar, y(:, 1))
figure(2)
plot(r,f);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Magnitude');
0 Comments
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 30 Nov 2020
Instead of using the fft, that calculates one fourier-transform of the entire time-series, have a look at the spectrogram function that will allow you to calculate the spectral components over shorter periods of time, it uses windowed short-time-fourier-transforms. That way you might have an easier time to match the frequencies to the melody (beat?) of your song.
HTH
0 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!