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

1 visualizzazione (ultimi 30 giorni)
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');
  2 Commenti
Steven Lord
Steven Lord il 30 Nov 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
If this is not homework, why not just use the built-in fft function?
Qudus Thanni
Qudus Thanni il 30 Nov 2021
Thank you for your response and the resource.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by