Audio fft shape is too strange.

3 Ansichten (letzte 30 Tage)
EUNBAE LEE
EUNBAE LEE am 16 Mai 2019
ideal graph type is
Original sound is different. 'fft shape' is too different. I think there is a mistake on my code. Please help me.
%This is my code and graph
[data,Fs]=audioread('1st pipe sound.m4a');
N=length(data);
ts=1/Fs;
t=0:ts:N*ts-ts;
F=0:Fs/N:Fs-Fs/N;
FFT_data=fft(data);
subplot(1,2,1)
plot(t,data);
xlabel('time[sec]')
ylabel('Amplitude')
title('1st pipe sound')
subplot(1,2,2)
plot(F,abs(FFT_data)/N);
xlabel('Frequency')
ylabel('Amplitude')
title('1st sound fft result')

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 16 Mai 2019
Hi eunbae,
The code is pretty close. The fft of a real signal has positive and negative frequencies, and what you are seeing at the right end of the frequency plot is just the negative frequencies. After [1] using the fftshift function to swap halves of the array and [2] making a frequency grid with 0 in the center, you get the plot in fig. 2 which better displays positive and negative frequency contributiions.
The amplitudes for pos and neg frequency have the same absolute value, so what people do for plotting purposes is double the size of the positive amplitudes and throw away the negative amplitudes. Except the first point in the array, which is frequency 0, is not doubled.
Not having your signal file I made up some data. The example assumes tha N is even.
% make up some data
Fs = 48000;
N = 30*Fs;
ts=1/Fs;
t=0:ts:N*ts-ts;
data = .8*sin(2*pi*200*t).*exp(-1.5*t);
% shift the data, show positive and negative frequencies
Fdat=abs(fft(data)/N);
F_shift=(0:Fs/N:Fs-Fs/N)-Fs/2;
Fdat_shift=fftshift(Fdat);
figure(2)
plot(F_shift,Fdat_shift);
xlim([-500 500])
% existing code modified
N=length(data);
ts=1/Fs;
t=0:ts:N*ts-ts;
F=0:Fs/N:Fs-Fs/N;
Fdat=abs(fft(data)/N);
% take positive frequencies only, multiply by 2
F = F(1:N/2);
Fdat=Fdat(1:N/2);
Fdat(2:end) = 2*Fdat(2:end);
figure(1)
subplot(1,2,1)
plot(t,data);
xlabel('time[sec]')
ylabel('Amplitude')
title('1st pipe sound')
subplot(1,2,2)
plot(F,Fdat)
xlabel('Frequency')
ylabel('Amplitude')
title('1st sound fft result')
xlim([0 500])

Weitere Antworten (0)

Kategorien

Mehr zu Simulation, Tuning, and Visualization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by