Perform FFTW of a song

2 visualizaciones (últimos 30 días)
Cesar Lobo
Cesar Lobo el 29 de Nov. de 2020
Respondida: Mathieu NOE el 30 de Nov. de 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');

Respuesta aceptada

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

Más respuestas (1)

Bjorn Gustavsson
Bjorn Gustavsson el 30 de Nov. de 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

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by