Audio fft shape is too strange.

6 次查看(过去 30 天)
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')

采纳的回答

David Goodmanson
David Goodmanson 2019-5-16
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])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by