I need help to fix my ifft function (not inbuilt)

10 views (last 30 days)
Qudus Thanni on 30 Nov 2021
Edited: Qudus Thanni on 2 Dec 2021
I have been able to figure out my fft function however i need help with my inverse fft function. It is not working exactly like that of the matlab inbuilt ifft function. Please, kindly help look through my codes. Thank you.(modified question)
%function
%%%%%%%%%%%%%%%%%%%%
function [ifft] = My_ifft(x)
% build an orthogonal an orthogonal basis set of exp(iwt)
[m,n]= size(x);
w=0:(floor(n/2));
t=((0:n-1)/n)*2*pi;
W=exp(i*t'*w)/sqrt(n);
ifft=x.*W';
end
%Script
%%%%%%%%%%%%%%%%%%%%
close all;
clear;
clc;
Fs = 1024; % Sampling frequency (s)
T = 1/Fs; % Sampling period (Hertz)
L = 2048; % Length of signal
t = (0:L-1)*T; % Time vector
f = Fs*(0:(L/2))/L; % Hertz single-sided frequency
f2 = (-L/2:L/2-1)*Fs/L; % Hertz double-sided frequency
w = 100;
c = cos(2*pi*w*t);
figure
B = My_ifft(c);
% plot single-sided only postive frequencies
figure
plot(f, real(B(1:L/2+1)));
xlabel('Hertz (1/s)');
ylabel('Real Amplitude');
title('Single-Sided Spectrum B');
Qudus Thanni on 30 Nov 2021
Thank you for your response and the resource.