In the previous article we found how to create a simple audio music file. Here, we are going to analyze it, i.e., to find out the fundamental frequency and other parameters. The code given below plots the .wav file and it power spectrum.
%Code Starts here
[y, Fs] = wavread(file); % y is sound data, Fs is sample frequency.
t = (1:length(y))/Fs; % time
ind = find(t>0.1 & t<0.12); % set time duration for waveform plot
figure; subplot(1,2,1)
plot(t(ind),y(ind))
axis tight
title(['Waveform of ' file])
N = 2^12; % number of points to analyze
c = fft(y(1:N))/N; % compute fft of sound data
p = 2*abs( c(2:N/2)); % compute power at each frequency
f = (1:N/2-1)*Fs/N; % frequency corresponding to p
subplot(1,2,2)
semilogy(f,p)
axis([0 4000 10^-4 1])
title(['Power Spectrum of ' file])
%Code ends here
querrymail@gmail.com
Thursday, 16 April 2009
Analyzing a .wav file
Posted by Sukunath B A at 4/16/2009 10:16:00 pm
Labels: matlab, Sound Analysis, Technical-Electronics
Subscribe to:
Post Comments (Atom)
3 comments:
eh i like the way u explained. something innovative..
Thank you
this doesn't actually... find the fundamental frequency. i see where the power spectrum peaks, but not. much. else useful.
Post a Comment