Perform FFTW of a song

3 次查看(过去 30 天)
Cesar Lobo
Cesar Lobo 2020-11-29
回答: Mathieu NOE 2020-11-30
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');

采纳的回答

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

更多回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2020-11-30
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

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by