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.

my_conv(x,h,nx,nh)
```function [ny  y] = my_conv(x,h,nx,nh)
% This function computes the linear convolution of input signals x[n] and h[n].
% Outputs:
% y: is the linear convolution between sequences x[n] and h[n] in a row vector format.
% ny: is a vector containing the time indices of the linear convolution of x[n] and h[n].
% Inputs:
% x: row vector containing the input signal x[n].
% h: row vector containing the input signal h[n].
% nx: vector conatining the time indices of the input signal x[n].
% nh: vector conatining the time indices of the input signal h[n].
x = x(:).';
h = h(:).';

N = length(x);
M = length(h);
L = N+M-1;

% The time indices of the convolution sum are computed as:
ny = nx(1)+nh(1):nx(end)+nh(end);

% Zeropad h[n] to make it of length N+M-1.
hext = [h zeros(1,L-M)].';

y = zeros(1,L);
A = zeros(L,N);

% Create a Toeplitz matrix from the filter kernel h[n]:
for k=1:N
A(:,k) = shiftdown(hext,k-1);
end

% Compute the convolution sum as a product of the Toeplitz matrix A
% and the input signal x[n]:
y = x*A.';  % Output computed as a row vector on purpose. Note that it;s the same as: A*x.'```