How can i determine the dominant frequency of a real sound signal recorded from microphone dirctly to matlab
2 views (last 30 days)
Show older comments
I want to plot the line spectra of a sound data recorded from microphone in wav format
I am not sure whether this code gives the right value or not
function line_spectra(z,Fs);
clear all
close all
clc
clf
%Initialize variab
[z,Fs] = wavread(normal_1.wav',2^17);Fs=44100Hz,data sample=131072
N=length(z);
b=bin2dec(fliplr(dec2bin(0:N-1)))+1;
%make it bit reversed order
MC=z(b);
alfa=N/2;
beta=1;
%calculate Twiddle factor
for n=1:N/2
W(n)=exp(-1i*2*pi*(n-1)/N);
Wr(n)=cos(2*pi*(n-1)/N);
Wi(n)=-sin(2*pi*(n-1)/N);
end
%calculate FFT using inplace non-recursive FFT,radix-2
for h=1:(log(N)/log(2));
b=2^(h-1);
a=1;
a0=1;
for d=1:alfa
c=1;
for e=1:beta
temp1=W(c)*MC(a+b);
temp2=MC(a);
MC(a)= MC(a)+temp1;
MC(a+b)=temp2-temp1;
a=a+1;
c=c+alfa;
end
a=a0+2^(h);
a0=a;
end
alfa=alfa/2;
beta=beta*2;
end
s=which('Exh_manifold_T3B.wav');%Modifying the figure window
set(gcf,'color',get(0,'DefaultUIcontrolBackgroundColor'),'NumberTitle',...
'off','Name',s,'Resize','on','Menubar','none');
%calculate the frequency
fr = (0:(N/256)-1)*Fs/N;
%plot the figure
p = abs(MC(1:N/256));
[Amax,f] = max(p);
fprintf('Max.Magn. of Amp1. is %6.4f db/n and the freq f is %4.2f\n',Amax,f);
pp=fftshift(p);
plot(fr,pp,'k')
xlabel('Frequency(Hz','Color','k','FontSize',12);
ylabel('Magnitude','color','k','FontSize',12);
title('Line spectrum plot for defective engine sound ','color','k','FontSize',12);
set(text (170,1660,'Background','b','EdgeColor','r'),'color','k','FontSize',12);
QUESTION
- fail to determine the fundamental frequency .
- How can I filter it
- the reading directly from the plot and from the code p = abs(MC(1:N/256));
[Amax,f] = max(p);
fprintf('Max.Magn. of Amp1. is %6.4f db/n and the freq f is %4.2f\n',Amax,f); not the same
4 Comments
Rick Rosson
on 11 Aug 2014
Why did you create your own implementation of the FFT? Why not use the fft function included in MATLAB?
Accepted Answer
Image Analyst
on 11 Aug 2014
How about you just call fft() and look for the location (frequency) of the maximum value? Looks like you're doing that - was there any problem with it?
More Answers (0)
See Also
Categories
Find more on Measurements and Spatial Audio in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!