Filter the rows or columns of a matrix with the following rational transfer function,

Create a 15-by-2 matrix of random input data. Initialize the random number generator to make the output of `rand` repeatable.

rng default
x = rand(15,2)

x =
0.8147 0.1419
0.9058 0.4218
0.1270 0.9157
0.9134 0.7922
0.6324 0.9595
0.0975 0.6557
0.2785 0.0357
0.5469 0.8491
0.9575 0.9340
0.9649 0.6787
0.1576 0.7577
0.9706 0.7431
0.9572 0.3922
0.4854 0.6555
0.8003 0.1712

Define the numerator and denominator coefficients for the rational transfer function.

b = 1;
a = [1 -0.2];

Apply the transfer function along the first dimension (default) and return the 1-D digital filter of each column.

y = filter(b,a,x)

y =
0.8147 0.1419
1.0687 0.4501
0.3407 1.0058
0.9815 0.9934
0.8287 1.1582
0.2633 0.8874
0.3312 0.2132
0.6131 0.8918
1.0801 1.1123
1.1809 0.9012
0.3938 0.9380
1.0494 0.9307
1.1670 0.5784
0.7188 0.7712
0.9440 0.3254

Compare the original data and the filtered data using an overlaid plot for each column.

Plot the first column of input and filtered data.

t = 0:length(x)-1;
plot(t,x(:,1))
hold on
plot(t,y(:,1))
grid on
legend('Input Data','Filtered Data','Location','BestOutside')
title('Plot of Input and Filtered Data from Column 1')

Plot the second column of input and filtered data.

figure
plot(t,x(:,2))
hold on
plot(t,y(:,2))
grid on
legend('Input Data','Filtered Data','Location','BestOutside')
title('Plot of Input and Filtered Data from Column 2')

Alternatively, you can filter the rows of a matrix by specifying `dim = 2`.

Consider the 2-by-15 matrix, `x'`, whose rows contain the data to filter.

Filter the matrix along the second dimension. Use the default initial conditions for filter delays.

dim = 2;
y2 = filter(b,a,x',[],dim)

y2 =
Columns 1 through 7
0.8147 1.0687 0.3407 0.9815 0.8287 0.2633 0.3312
0.1419 0.4501 1.0058 0.9934 1.1582 0.8874 0.2132
Columns 8 through 14
0.6131 1.0801 1.1809 0.3938 1.0494 1.1670 0.7188
0.8918 1.1123 0.9012 0.9380 0.9307 0.5784 0.7712
Column 15
0.9440
0.3254

`y2` is the transpose of `y` from above.