Borrar filtros
Borrar filtros

FFT not giving the desired result

7 visualizaciones (últimos 30 días)
Edward  Jones
Edward Jones el 9 de Oct. de 2017
Comentada: Star Strider el 10 de Oct. de 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?
I have attached the two files post audio read saved as Bolt and Squid.
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])

Respuesta aceptada

Star Strider
Star Strider el 9 de Oct. de 2017
You did not state what your sampling frequencies are, or include them in your files, so I assume they is the same for both files. My code accommodates separate sampling frequencies for each signal. My code is reliable, based on this version of the fft (link) documentation (it works for all versions), and has worked successfully in the past. (I did not try to troubleshoot your code. I am simply posting mine. This is based on the files you attached to your previous Question.)
I cannot specifically reply to you statement about the frequencies, since I have no idea what you are doing.
Here is my Fourier transform analysis of your data.
DBolt = load('Edward Jones Bolt.mat');
DSquid = load('Edward Jones Squid.mat');
Bolt = DBolt.y2;
Squid = DSquid.y2;
FsB = 44100; % Assumed Sampling Frequency (Bolt)
FsS = 44100; % Assumed Sampling Frequency (Squid)
FnB = FsB/2; % Nyquist Frequency (Bolt)
FnS = FsB/2; % Nyquist Frequency (Squid)
LBolt = length(Bolt);
LSquid = length(Squid);
NFFTB = 2.^nextpow2(LBolt);
NFFTS = 2.^nextpow2(LSquid);
FT_B = fft(Bolt,NFFTB)/LBolt;
FT_S = fft(Squid,NFFTS)/LSquid;
FvB = linspace(0, 1, fix(length(FT_B)/2)+1)*FnB; % Frequency Vector (Bolt)
IvB = 1:length(FvB); % Index Vector (Bolt)
FvS = linspace(0, 1, fix(length(FT_B)/2)+1)*FnB; % Frequency Vector (Squid)
IvS = 1:length(FvS); % Index Vector (Squid)
figure(1)
subplot(2,1,1)
plot(FvB, abs(FT_B(IvB,:))*2)
title('Bolt')
set(gca, 'XLim',[0 5E+2])
grid
subplot(2,1,2)
plot(FvS, abs(FT_S(IvS,:))*2)
title('Squid')
set(gca, 'XLim',[0 5E+2])
grid
You can break out the subplot calls to plot the Fourier transform of each channel in your signals as well. I plotted both channels for each file in each subplot in my code.
  8 comentarios
Edward  Jones
Edward Jones el 10 de Oct. de 2017
will the sampling frequency just be 44100 like all audio files?
Star Strider
Star Strider el 10 de Oct. de 2017
It is whatever you set it to be when you set up your experiment. The sampling frequency should be recorded as ‘metadata’ in the same file that your recording equipment created when it saved the file.
Set the sampling frequency to at least 2 times the maximum expected frequency of your signal, if possible.
The 44100 Hz value is the standard CD audio sampling frequency, because the Nyquist frequency, 22050 Hz, spans normal the human hearing range, and being slightly oversampled, allows for effective digital signal processing.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by