필터 지우기
필터 지우기

Determining frequency content of a .wav file

조회 수: 10 (최근 30일)
Edward  Jones
Edward Jones 2017년 10월 7일
댓글: Abhi Sundararaman 2017년 10월 9일
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