Is centredFFT function really exist?

i try to run this code that i get from a website. however, the MATLAB cannot read the "centeredFFT" whenever i try to enter this line: function [X,f] = centeredFFT(x,Fs); it will return this line: ??? Undefined function or method 'centeredFFT' for input arguments of type 'double'. may i know what is the reason behind this?
i am thinking that i need to use extra toolbox, which i don't know its name.
below is the code
[y,Fs,bits] = auread('bird_chirping2.au');
x = y(:,1);
clear y; N = length(x);
time = [1:N].*(1/Fs);
han = plot(time,x); xlab = xlabel('Seconds'); ylab = ylabel('Amplitude'); grid on; set(han,'LineWidth', 2); set([xlab, ylab],'FontSize', 24, 'FontName', 'Times'); set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')
% wavwrite(x,Fs,bits,'test.wav');
[X,f] = centeredFFT(x,Fs);
figure; han1 = plot(f,abs(X)); axis([-8000,8000,0,max(abs(X))]); grid on; xlab1=xlabel('Frequency(Hz)'); ylab1=ylabel('|X[k]|'); set(han1,'LineWidth', 2); set([xlab1, ylab1],'FontSize', 24, 'FontName', 'Times'); set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')
% sound(x,Fs,bits);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
fc = 2000; fNorm = fc / ( Fs/2); [b,a] = butter(10, fNorm, 'low'); x_Low = filtfilt(b, a, x);
figure; freqz(b,a,bits,Fs/2); grid on;
% sound(x_Low,Fs,bits); % wavwrite(x_Low,Fs,bits,'x_Low_.wav');
[X_LOW,f_low] = centeredFFT(x_Low,Fs);
figure; han2=plot(f_low,abs(X_LOW)); axis([-.8e4,.8e4,0,max(abs(X))]); grid on; xlab2=xlabel('Frequency(Hz)'); ylab2=ylabel('|X[k]|)'); set(han2,'LineWidth', 2); set([xlab2, ylab2],'FontSize', 24, 'FontName', 'Times'); set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')
figure; han3=plot(time,x_Low); grid on; xlab3=xlabel('Frequency(Hz)'); ylab3=ylabel('|X[k]|)'); set(han3,'LineWidth', 2); set([xlab3, ylab3],'FontSize', 24, 'FontName', 'Times'); set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')

 Accepted Answer

hi Nadiah , no its not built-in function, but wherever you found the program you must find the related material.. here is the function you are looking for :
%===============================================================
%%taken from e80 course at Harvey Mudd College
function [X,freq]=centeredFFT(x,Fs)
%x is the signal that is to be transformed
%Fs is the sampling rate
N=length(x);
%this part of the code generates that frequency axis
if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end
T=N/Fs;
freq=k/T; %the frequency axis
%takes the fft of the signal, and adjusts the amplitude accordingly
X=fft(x)/N; % make up for the lack of 1/N in Matlab FFT
X=fftshift(X); %shifts the fft data so that it is centered
%========================================================================
For friendly use function, try my Submission :

2 Comments

ok now i understand. I need to setpath to use the function right? thank you.
yes , you manage that , put it in \Documents\MATLAB

Sign in to comment.

More Answers (1)

Thorsten
Thorsten on 21 Feb 2013
Edited: Thorsten on 21 Feb 2013
Can Matlab find your downloaded function?
which centeredFFT
If not, move your function to your current directory or another directory in Matlab's search path.

1 Comment

Nadiah
Nadiah on 22 Feb 2013
Edited: Nadiah on 22 Feb 2013
it says 'centeredFFT' is not found. how can i move the function to the current directory?
for this syntax, in what Toolbox it is used?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!