Determining frequency content of a .wav file

10 次查看(过去 30 天)
Hi all,
The code I have written I think is correct. I am comparing two sound sources and not getting the desired outcome, one of the sound sources has a higher frequency content when it should be lower! I think there is something wrong with my Fourier Transform?
My code is as follows, any help would be much appreciated:
read in the .wav file
[y,fs]= audioread('CD152DEP1_20170829_160000.wav');
% y=samples
% fs=sampling frequency
Starttime=0;
Endtime=30;
time= Endtime-Starttime;
Sample=time.*fs;
Starty=Starttime.*fs
Endy=Endtime.*fs
t=linspace(Starttime,Endtime,Sample);
%linspace function that creates evenly spaced time vector
y2=y((Starty+1):Endy,:);
figure;
subplot(3,1,1)
plot(t,y2);
xlabel('Time (seconds)')
ylabel('Amplitude')
title('Day 1 Bolt 16.00')
hold on
%a is normalised into seconds for plot
%xlim([0 350])
%b= 45/350
%X = [b, b];
%Y = [0.8,0.5];
%a = annotation('textarrow',X,Y,'String','Lander crossing');
%%frequnecy analysis
Nfft=2048;
f=linspace(0,fs,Nfft);
%f is freq vector, 0 starting freq, fs is end freq, Nfft is length of
%vector
G=abs(fft(y2,Nfft));
%G is the fft of y in the same number of points as the sample
%calculating the phase
phase = unwrap(angle(fft(y,Nfft)));
%subplot of phase and freq
subplot(3,1,2),plot((f(1:Nfft/2)),(G(1:Nfft/2)))
xlabel('Frequency(Hz)')
ylabel('Amplitude')
xlim([0 1000])
hold on
subplot(3,1,3), plot((f(1:Nfft/2)),(phase(1:Nfft/2)))
xlabel('Frequency(Hz)')
ylabel('Phase(radians)')
xlim([0 1000])
  4 个评论
Edward  Jones
Edward Jones 2017-10-7
编辑:Edward Jones 2017-10-7
Thank you for the responses, what would be the best approach to a extract the frequency content and plot it against the amplitude? I do not understand what you mean about it being two sided? I have tried pwelch but it does not seem to work for just plotting frequency vs amplitude?
The two files post audio read are attached
Abhi Sundararaman
Abhi Sundararaman 2017-10-9
I recommend walking through the example in our documentation for "fft", like Star Strider said. It will give you the process for plotting the fft in the way you expect:

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by