?? fouriertransform.m
字號:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PMC January 2008
% [f,Y] = FourierTransform (y,t)
%
% This function receives as input a sequence of samples of a waveform
% in the time domain and calculates the corresponding frequency spectrum
%
% Input:
% - y[] = vector of samples
% - t[] = vector of time values
% Output:
% - Y[] = Fourier transform of y
% - f[] = vector of frequency values
%
% NOTE: the Fourier transform vector is divided by the number of samples to
% get results applicable to continuous-time functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Y] = FourierTransform(y,t)
% Calculate the Discrete Fourier Transform
Y = fftshift(fft(y))/length(y); %; divide by N to normalize
% Y = fft(y)/length(y); %; divide by N to normalize
delta_f = 1/(length(Y)*(t(2)-t(1)));
% If the vector length is odd, the DC component will be localized at
% the center of the vector
if mod(length(Y),2)
tmp = ceil(length(Y)/2); % Find the center of the array
f(tmp) = 0; % DC frequency
for nn=1:floor(length(Y)/2)
f(tmp + nn) = f(tmp + nn - 1) + delta_f;
f(tmp - nn) = -f(tmp + nn);
end
% If the vector length is even, the DC component will be localized at
% the first element of the right-hand side
else
tmp = (length(Y)/2) + 1; % Find the center of the array
f(tmp) = 0; % DC frequency
for nn=1:tmp-2
f(tmp + nn) = f(tmp + nn - 1) + delta_f;
f(tmp - nn) = -f(tmp + nn);
end
f(1) = f(2) - delta_f;
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -