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.

conv_DHT(x,y)
```% Linear Convolution calculated via the Discrete Hartley Transform (DHT).
% Warning: It is good for convolution calculation of real input sequences only.
function z = conv_DHT(x,y)

% Make sure x and h are row vectors.
x = x(:).';
y = y(:).';

N = length(x);
M = length(y);

L  = 2^nextpow2(N+M-1);

x1 = [x zeros(1,L-N)];  % Zero-pad as required to make the length
y1 = [y zeros(1,L-M)];  % of both sequences equal to L=2^n for max fft() performance.

% Calculate the DHT of h1[n] and x1:
X = my_DHT(x1);
Y = my_DHT(y1);

% Next calulate the even and odd parts of H:
Yeven = (Y + circshift(fliplr(Y),[0 1]))/2;
Yodd  = (Y - circshift(fliplr(Y),[0 1]))/2;

%Calculate the DHT of the output using the given formula:
Z = X.*Yeven + circshift(fliplr(X),[0 1]).*Yodd;

z = 1/L*my_DHT(Z);

% Now keep only the valid samples:
z = z(1:N+M-1);```