fft(x,n) NO BUILT IN FUNCTION WHERE n > size(x)
4 次查看(过去 30 天)
显示 更早的评论
Hi
I'm looking for fft & ifft function code for fff(x,n) where n > size(x).
I found this here :
and it works well for all fft(x) & ifft(x) where n=size(x) but not for n>size(x)
function Xk = myfft(x)
N = length(x); % The fundamental period of the DFT
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1i*2*pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = x * WNnk; % row vector for DFT coefficients
function x_hat = myifft(ftx)
N = length(ftx); % The fundamental period of the DFT
n = 0:1:N-1;
k = 0:1:N-1;
WN = exp(-1i*2*pi/N);
nk = n'*k;
WNnk = WN .^ (-nk); % IDFS matrix
x_hat = (ftx * WNnk)/N; % row vector for IDFS values
x_hat=real(x_hat);
How can I modify this code (or to take an other one) for my task?
Thanks!
0 个评论
采纳的回答
AL
2023-3-16
To modify the existing code for the FFT function, you can use the following code:
function Xk = myfft(x,n)
N = length(x); % The fundamental period of the DFT
if N<n
x=[x,zeros(1,n-N)];
N=n;
end
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1i2pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = x * WNnk; % row vector for DFT coefficients
The modifications include passing an additional parameter 'n' to the function to specify the desired size of the output FFT, and checking if the length of input 'x' is less than 'n', in which case zero-padding is done to make the length equal to 'n'.
Similarly, to modify the existing code for the IFFT function, you can use the following code:
function x_hat = myifft(ftx,n)
N = length(ftx); % The fundamental period of the DFT
if N<n
ftx=[ftx,zeros(1,n-N)];
N=n;
end
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1i2pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^(-nk); % IDFS matrix
x_hat = (ftx * WNnk)/N; % row vector for IDFS values
x_hat=real(x_hat);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!