Skip to main content

DFT and IDFT using Matrix Multiplication Method in Matlab

dftidft3
clc
clear all
close all

X=input('Enter the Input Sequence');
N=input('Enter the value of N such taht N-point DFT is to be calculated');
%Inputs are taken%

n=0:1:N-1;
k=0:1:N-1;
nk=n'*k; %n transpose * k gives us a N*N matrix%

W=exp(-(j*2*pi)/N); % Twiddle Factor %

Wnk=W.^nk; % Twiddle Factor matrix is generated %

Y= Wnk*X' ; % Twiddle factor matrix multiplied by X transpose%

%Reason behing going to Transopose of the input matrix is : when we enter a matrix sequence we usually use ROW Matrix, in order to convert ROW to COLUMN we are using Transpose%


L=length(Y);
n=0:1:L-1;

figure,plot(n,abs(Y)),title('Magnitude Response of DFT')
figure, plot(n, angle(Y)), title('Phase Response of DFT')
%MAGNITUDE and PHASERESPONSE OF DFT SIGNAL IS PLOTTED%


W=exp((j*2*pi)/N); % Twiddle Factor %

Wnk=(W.^nk)/N; % Twiddle Factor matrix is generated %

Yinv= Wnk*Y ; % Twiddle factor matrix multiplied by Y%

L=length(Y);
n=0:1:L-1;

figure,plot(n,abs(Yinv)),title('Magnitude Response of IDFT')
figure, plot(n, angle(Yinv)), title('Phase Response of IDFT')
%MAGNITUDE and PHASERESPONSE OF ORIGINAL SIGNAL IS PLOTTED%
Error using input
Cannot call INPUT from EVALC.

Error in dftidft3 (line 5)
X=input('Enter the Input Sequence');

Comments

Popular posts from this blog

DFT and IDFT using FFT command in Matlab

dftidft1 clc clear all close all X=input( 'Enter the Input Sequence' ); N=input( 'Enter the Value of N such that N-point DFT is to be Calculated' ); % INPUTS ARE GIVEN % Y= fft(X,N) %DFT IS CALCULATED% L=length(Y); n=0:1:L-1; figure,plot(n,abs(Y)),title( 'Magnitude Response of DFT' ) figure, plot(n, angle(Y)), title( 'Phase Response of DFT' ) %MAGNITUDE and PHASERESPONSE OF DFT SIGNAL IS PLOTTED% Yinv=ifft(Y,N) %IDFT IS CALCULATED% figure,plot(n,abs(Yinv)),title( 'Magnitude Response of IDFT' ) figure, plot(n, angle(Yinv)), title( 'Phase Response of IDFT' ) %MAGNITUDE and PHASERESPONSE OF ORIGINAL SIGNAL IS PLOTTED% Error using input Cannot call INPUT from EVALC. Error in dftidft1 (line 5) X=input('Enter the Input Sequence'); Published with MATLAB® R2013b

Linear Convolution of two sequences

The program code is : clc clear all close all X1=input('ENTER THE SEQUENCE 1 >'); i1=input('ENTER THE STARTING INDEX OF THE SEQUENCE 1 >'); X2=input('ENTER THE SEQUENCE 2 >'); i2=input('ENTER THE STARTING INDEX OF THE SEQUENCE 2 >'); m1=length(X1); m2=length(X2); Y=conv(X1,X2) n1=i1:i1+m1-1; n2=i2:i2+m2-1; n3=(i1+i2):(i1+i2+length(Y)-1); subplot(3,1,1) stem(n1,X1,'r') xlabel('n'); ylabel('Amplitude'); title('Sequence 1'); subplot(3,1,2) stem(n2,X2,'g') xlabel('n'); ylabel('Amplitude'); title('Sequence 2'); subplot(3,1,3) stem(n3,Y,'c') xlabel('n'); ylabel('Amplitude'); title('Linear Convolution of the Above two sequences'); output : Please feel free to ask your questions in the comment session

Circular Convolution of the two Sequences

The program code is : clc clear all close all X1=input('ENTER THE SEQUENCE 1 >'); i1=input('ENTER THE STARTING INDEX OF THE SEQUENCE 1 >'); X2=input('ENTER THE SEQUENCE 2 >'); i2=input('ENTER THE STARTING INDEX OF THE SEQUENCE 2 >'); m1=length(X1); m2=length(X2); if(m1>m2)     Y=cconv(X1,X2,m1)     n3=(i1+i2):(i1+i2+m1-1); else     Y=cconv(X1,X2,m2)     n3=(i1+i2):(i1+i2+m2-1); end Yref=conv(X1,X2) n1=i1:i1+m1-1; n2=i2:i2+m2-1; n4=(i1+i2):(length(Yref)-1+i1+i2); subplot(4,1,1) stem(n1,X1,'r') xlabel('n'); ylabel('Amplitude'); title('Sequence 1'); subplot(4,1,2) stem(n2,X2,'g') xlabel('n'); ylabel('Amplitude'); title('Sequence 2'); subplot(4,1,3) stem(n3,Y,'c') xlabel('n'); ylabel('Amplitude'); title('Circular Convolution of the Above two sequences'); subplo...