Clear Filters
Clear Filters

Determining frequency content of a .wav file

10 views (last 30 days)
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 Comments
Edward  Jones
Edward Jones on 7 Oct 2017
Edited: Edward Jones on 7 Oct 2017
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 on 9 Oct 2017
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:

Sign in to comment.

Answers (0)

Categories

Find more on Audio I/O and Waveform Generation 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!