I tried to execute this code but for some reason the graph of the ifft is not a perfect sine wave. Can someone please instruct me as to what I did wrong? I got the fft code from the internet and I want to get the ifft
Main Code
fo = 4; %frequency of the sinewave
Fs = 100; %sampling rate
Ts = 1/Fs; %sampling time interval
t = 0:Ts:1-Ts; n = length(t); %number of samples
y = sin(2*pi*fo*t);figure(1)plot(t,y)grid on[YfreqD,freqRng] = positiveFFT(y,Fs);figure(2)stem(freqRng,abs(YfreqD));B = ifft(YfreqD)*length(y);t1 = (0:(1-Ts)/(length(B)-1):1-Ts);figure(3)plot(t1,B)grid on
Positive fft code
function[X,freq] = positiveFFT(x,Fs)N = length(x);k = 0:N-1;T = N/Fs;freq = k/T; %create the frequency range
X = fft(x)/N; %normalize the data
cutOff = ceil(N/2);X = X(1:cutOff);freq = freq(1:cutOff);
Best Answer