Program :
clc;
clear all;
x = input('Enter the input sequence = ');
N = length(x);
for k = 1:N
y(k) = 0;
for n = 1:N
y(k) = y(k)+x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N);
end
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,x);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence');
grid on;
magnitude = abs(y); % Find the magnitudes of individual FFT points
disp('FFT Sequence = ');
disp(magnitude);
%code block to plot the FFT sequence
t = 0:N-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude ---->');
xlabel('K ---->');
title('FFT Sequence');
grid on;
R = length(y);
for n = 1:R
x1(n) = 0;
for k = 1:R
x1(n) = x1(n)+(1/R)*y(k)*exp(1i*2*pi*(k-1)*(n-1)/R);
end
end
%code block to plot the IFFT sequence
t = 0:R-1;
subplot(2,2,3);
stem(t,x1);
disp('IFFT Sequence = ');
disp(x1);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IFFT sequence');
grid on;
Output :
Enter the input sequence = [1 4 2 5 2]
FFT Sequence =
14.0000 2.8124 4.3692 4.3692 2.8124
IFFT Sequence =
Columns 1 through 4
1.0000 - 0.0000i 4.0000 - 0.0000i 2.0000 - 0.0000i 5.0000 + 0.0000i
Column 5
2.0000 + 0.0000i
Waveforms:
clc;
clear all;
x = input('Enter the input sequence = ');
N = length(x);
for k = 1:N
y(k) = 0;
for n = 1:N
y(k) = y(k)+x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N);
end
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,x);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence');
grid on;
magnitude = abs(y); % Find the magnitudes of individual FFT points
disp('FFT Sequence = ');
disp(magnitude);
%code block to plot the FFT sequence
t = 0:N-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude ---->');
xlabel('K ---->');
title('FFT Sequence');
grid on;
R = length(y);
for n = 1:R
x1(n) = 0;
for k = 1:R
x1(n) = x1(n)+(1/R)*y(k)*exp(1i*2*pi*(k-1)*(n-1)/R);
end
end
%code block to plot the IFFT sequence
t = 0:R-1;
subplot(2,2,3);
stem(t,x1);
disp('IFFT Sequence = ');
disp(x1);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IFFT sequence');
grid on;
Output :
Enter the input sequence = [1 4 2 5 2]
FFT Sequence =
14.0000 2.8124 4.3692 4.3692 2.8124
IFFT Sequence =
Columns 1 through 4
1.0000 - 0.0000i 4.0000 - 0.0000i 2.0000 - 0.0000i 5.0000 + 0.0000i
Column 5
2.0000 + 0.0000i
Waveforms:
k, this is a bit confusing for me, if i need to insert this code in a function block in simulink, for ifft and fft side, how it should look and what should i have on the input side
ReplyDeleteIs there any possibility to apply FFT algorithm in MATLAB. i.e. butterfly computation???
ReplyDeletei dint get wht you meant by " applying fft algorithm in matlab".. can u explain a bit more about your need ???
Deleteabsolutely why not
Deletethat was a really useful and helpful one...... very simple as well.......thank you.....
ReplyDeleteIt is DFT and IDFT algorithm not FFT/IFFT.
ReplyDeleteright this is not FFT
ReplyDeletei need to calculate the inverse fourier transform of an already calculated spectrum (which is not computed by fft)in matlab.I tried using ifft function but not getting the desired results.
ReplyDeleteDo put your code to have a look. The issue can prevail due to length of input. The built in function is for length 2^n.
ReplyDeletenice one
ReplyDeletegearse
ReplyDelete