[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
showing frequency and amplitude after doing fft on signal
From: |
Rick T |
Subject: |
showing frequency and amplitude after doing fft on signal |
Date: |
Tue, 27 Nov 2012 07:14:51 -1000 |
Greetings All I execute an fft on a wav file of a person saying "ahhh"
which shows the frequency and amplitude of the audio file. The
problem I'm having is when I run it on a wav file it shows the
frequency 0hz with having the highest amplitude. I'm not sure where
the problem is within my code and how I can fix it.
How does 0hz have the max amplitude? The reason I'm trying to fix
this is that I want to find the frequency with the highest amplitude
in the wave file then run some calculation against it but running
calculations against 0hz doesn't make any sense to me especially when
I have to do multiplication with it.
When I look at **array_sort variable** it says the frequency is **0hz
and 0.117341 as it's amplitude.**
Here's the wave file an m file I'm using
http://dl.dropbox.com/u/6576402/questions/fft/11262012_44100ahh.wav
http://dl.dropbox.com/u/6576402/questions/fft/test_rtfftphase_question.m
clear all, clc,clf,tic
dirpathtmp=strcat('/tmp/');
[vp_sig_orig, fs_rate, nbitsraw] =
wavread(strcat(dirpathtmp,'/nov26/11262012_44100ahh.wav')); %must be
mono
fs=fs_rate;
t_rebuilt=linspace(0,2*pi,fs); %creates same size time for new
signal as orginal signal good for error checking
vp_sig_len=length(vp_sig_orig); %get sample rate from vp fs_rate
needs to be an even number?
% Use next highest power of 2 greater than or equal to length(x)
to calculate FFT.
nfft= 2^(nextpow2(length(vp_sig_orig)));
% Take fft, padding with zeros so that length(fftx) is equal to nfft
fftx = fft(vp_sig_orig,nfft);
sigfft= fft(vp_sig_orig);
sigifft=ifft(sigfft);
sigphase = unwrap(angle(sigfft')); %get phase of orginal signal
% Calculate the number of unique points
NumUniquePts = ceil((nfft+1)/2);
% FFT is symmetric, throw away second half
fftx = fftx(1:NumUniquePts);
% Take the magnitude of fft of x and scale the fft so that it is
not a function of the length of x
mx = abs(fftx)/length(vp_sig_orig); %replaced for testing from stackexchage
if rem(nfft, 2) % odd nfft excludes Nyquist point
mx(2:end) = mx(2:end)*2;
else
mx(2:end -1) = mx(2:end -1)*2;
end
amp=mx;
ampinv=abs(amp-max(amp));
% This is an evenly spaced frequency vector with NumUniquePts points.
freq_vect = (0:NumUniquePts-1)*vp_sig_len/nfft;
freq=freq_vect';
%get phase of new signal
phase = unwrap(angle(fftx)); %get phase of orginal signal
array=[freq,amp];
array_sort=sortrows(array,-2); %sort by largest amplitude first
Any ideas?
PS: I'm using octave 3.2.4 on linux ubuntu 64bit
Thanks
- showing frequency and amplitude after doing fft on signal,
Rick T <=