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 Center および File ExchangeFourier 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