我想知道如果我正確使用MATLAB中的傅立葉變換。我想擁有歌曲中所有頻率的平均幅度。出於測試目的,我使用a free mp3 download of Beethovens "For Elise",我使用Audacity將其轉換爲8 kHz單聲道波形文件。我是否正確使用傅里葉變換?
我的MATLAB代碼如下:然後
clear all % be careful
% load file
% Für Elise Recording by Valentina Lisitsa
% from http://www.forelise.com/recordings/valentina_lisitsa
% Converted to 8 kHz mono using Audacity
allSamples = wavread('fur_elise_valentina_lisitsa_8khz_mono.wav');
% apply windowing function
w = hanning(length(allSamples));
allSamples = allSamples.*w;
% FFT needs input of length 2^x
NFFT = 2^nextpow2(length(allSamples))
% Apply FFT
fftBuckets=fft(allSamples, NFFT);
fftBuckets=fftBuckets(1:(NFFT/2+1)); % because of symetric/mirrored values
% calculate single side amplitude spectrum,
% normalize by dividing by NFFT to get the
% popular way of displaying amplitudes
% in a range of 0 to 1
fftBuckets = (2*abs(fftBuckets))/NFFT;
% plot it: max possible frequency is 4000, because sampling rate of input
% is 8000 Hz
x = linspace(1,4000,length(fftBuckets));
bar(x,fftBuckets);
輸出看起來是這樣的:
- 有人可以告訴我,如果我的代碼是正確的?我特別想知道約爲0的峯值。
- 對於正常化,我必須除以
NFFT
或length(allSamples)
? - 對我來說,這看起來並不像條形圖,但我猜這是由於我繪製的許多值?
感謝您的任何提示!
你見過本頁:[使用FFT獲取簡單光譜分析圖](http://www.mathworks.com/support/tech-notes/1700/1702.html)。它有很多解釋的例子 – Amro