Code covered by the BSD License

# MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".

### Ilias Konsoulas (view profile)

29 Oct 2012 (Updated )

These files are the MatLab solutions of exercises contained in the above DSP lab textbook.

ifftreal2(X)
```function x = ifftreal2(X)
% This function computes the ifft of an N-point complex DFT sequence which corresponds
% to a real signal x[n]. i.e. Re{X[k]} should be even and Im{X[k]} should be odd
% in order for this to work properly.
% Caution: Works well only for N even.

N = length(X);
x = zeros(1,N);

k = 0:N/2-1;
W = exp(1i*2*pi*k/N);

g = zeros(1,N/2);
h = zeros(1,N/2);

even_freq_ind = 1:2:N-1;
odd_freq_ind = 2:2:N;

G = X(even_freq_ind); % Form the even-indexed sequence X[0], X[2], X[4], ..., X[N-2].
H = X(odd_freq_ind);   % Form the odd-indexed sequence X[1], X[3], X[5], ..., X[N-1].

% IT WOULD'VE BEEN GREAT IF we were able to use ifft241.m to compute the two N/2 IDFT's by:
% [g  h] = ifft241(G,H) !!! However, it's not possible. Why so?  Because only G[k] is a DFT of a real sequence.
% while H[k] is the DFT of a complex sequence.
% Otherwise, Re{G[k]} and Re{H[k]} should both have even symmetry of even or odd length around the middle sample.
% at the same time, Im{G[k]} and Im{H[k]} should  both have odd symmetry of even or odd length
% around the middle sample.Unfortunately, due to the way those 2 sequences
% are formed, G[k] has odd-length symmetry while H[k] presents even-length symmetry around the middle sample
% and the function ifft241.m cannot be applied. For a definition about even and odd  length symmetries see page 79.

% Therefore, we have to resort to 2 classic N/2 point iffts.
g = ifftreal(G);  % This is of some gain...
h = ifft(H);         % While this is not!

% Use Decimation-In-Frequency (DIF) Relations:
x(1:N/2)      = 1/2*(g + h.*W);
x(N/2+1:N) = 1/2*(g - h.*W);
```