Effacer les filtres
Effacer les filtres

Perform FFTW of a song

3 vues (au cours des 30 derniers jours)
Cesar Lobo
Cesar Lobo le 29 Nov 2020
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');

Réponse acceptée

Mathieu NOE
Mathieu NOE le 30 Nov 2020
hello
I have exactly what you need ! you lucky man !
enjoy it

Plus de réponses (1)

Bjorn Gustavsson
Bjorn Gustavsson le 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

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by