Filter löschen
Filter löschen

Determining frequency content of a .wav file

10 Ansichten (letzte 30 Tage)
Edward  Jones
Edward Jones am 7 Okt. 2017
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 Kommentare
Edward  Jones
Edward Jones am 7 Okt. 2017
Bearbeitet: Edward Jones am 7 Okt. 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 am 9 Okt. 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:

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by