Monday 4 April 2016

fft - Finding the dominant tone in a signal


I am given 256 samples at a sampling rate of 48k and am asked to find the frequency of dominate tones and the amplitude of the largest tone. The data looks like this when plotted:


n


I assume I must use a FFT transform to do this. I've tried this in matlab:


Fs = 48000;

x = dataSet; % 256 samples data set
xdft = fft(x);
maxAmp = max(abs(xdft));
%Not sure how I can grab the tones here
freq = 0:Fs / length(x):Fs/2;

Not really sure how to proceed, Any ideas?



Answer



I think you are having trouble constructing your frequency axis properly. Once you do this, you can do a simple peak pick. I have re-written the code for you:


Fs = 48000;

x = dataSet; % 256 samples data set
fftLength = length(x); % Always make sure to be at least as long as your data.
xdft = fft(x,fftLength);
maxAmp = max(abs(xdft));

freq = [0:fftLength-1].*(Fs/fftLength); % This is your total freq-axis
freqsYouCareAbout = freq(freq < Fs/2); % You only care about either the pos or neg
% frequencies, since they are redundant for
% a real signal.


xdftYouCareAbout = abs(xdft(1:round(fftLength/2))); % Take the absolute magnitude.

[maxVal, index] = max(xdftYouCareAbout); % maxVal is your (un-normalized) maximum amplitude

maxFreq = freqsYouCareAbout(index); % This is the frequency of your dominant signal.

No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...