fft of a signal

19 ビュー (過去 30 日間)
Mangesh KAle
Mangesh KAle 2022 年 9 月 27 日
回答済み: Star Strider 2022 年 9 月 27 日
I would like to know whether the code is right or wrong because I am not getting the frequency plot
clc;
%% load a signal
[y,Fs] = audioread("bodytune.wav"); % Fs= Sampling Frequency
% y = 393216*2 double and Fs= 16000
info = audioinfo("bodytune.wav");
y1= y(:,1);
L = length(y); % Length of a signal
dt= 1/Fs;
t = (0:L-1)*dt; % Time vector
%% plot and label the graph
figure(1)
plot(t,y1);
xlabel('time')
ylabel('Amplitude')
grid on
%% fourier transform
nfft = 2^( nextpow2(length(y1)) );
df = Fs/nfft;
f = 0:df:Fs/2;
X_fft = fft(y1,nfft);
X_fft = X_fft(1:nfft/2+1);
figure(2);
plot(f,abs(X_fft));
xlabel('Frequency')
ylabel('Amplitude')
grid on

採用された回答

Star Strider
Star Strider 2022 年 9 月 27 日
You need to normalise the fft result by the length of the signal:
X_fft = fft(y1,nfft)/L;
Otherwise, using my test signal, it appears to be correct —
% clc;
% % load a signal
% [y,Fs] = audioread("bodytune.wav"); % Fs= Sampling Frequency
% y = 393216*2 double and Fs= 16000
% info = audioinfo("bodytune.wav");
Fs = 44100;
t = linspace(0, 5*Fs-1, 5*Fs)/Fs;
y = sum(sin([1; 5000; 10000; 15000]*2*pi*t)).';
y1= y(:,1);
L = length(y); % Length of a signal
dt= 1/Fs;
t = (0:L-1)*dt; % Time vector
%% plot and label the graph
figure(1)
plot(t,y1);
xlabel('time')
ylabel('Amplitude')
grid on
%% fourier transform
nfft = 2^( nextpow2(length(y1)) );
df = Fs/nfft;
f = 0:df:Fs/2;
X_fft = fft(y1,nfft)/L;
X_fft = X_fft(1:nfft/2+1);
figure(2);
plot(f,abs(X_fft));
xlabel('Frequency')
ylabel('Amplitude')
grid on
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by