Is this the correct representation of Filter Transfer function coefficient matrix in MATLAB ?

54 次查看(过去 30 天)
So basically I am calculating the matrix for the filter transfer function .Here is my code :
% Step 1: Set up the Vandermonde Matrix V for N
clc
clear varse
close all
N=3;
for M = 3% Order of polynomial order
x = 0:M;
V =fliplr(vander(x)) ;
end% Vandermonde matrix with powers increasing from left to right
disp('The Vandermonde Matrix V:')
The Vandermonde Matrix V:
disp(V);
1 0 0 0 1 1 1 1 1 2 4 8 1 3 9 27
Q = inv(V); % Farrow Lagrange Coefficients
disp("The filter Coeffiecients of Q:")
The filter Coeffiecients of Q:
disp(Q)
1.0000 0 0 0 -1.8333 3.0000 -1.5000 0.3333 1.0000 -2.5000 2.0000 -0.5000 -0.1667 0.5000 -0.5000 0.1667
%Delay vector of Farrow
%The transformation Matrix of Delay vector
T_z = calculate_Tz(M);
Unrecognized function or variable 'calculate_Tz'.
disp('Matrix T_z:');
%Matrix T_z:
disp(T_z);
%Transformation delay matrix 2
Td2 = compute_Td2(M);
disp('T_d^2:');
disp(Td2);
%Transformation delay matrix 1
Td1 = compute_Td1(M);
disp('T_d^1:');
disp(Td1);
%Total Td
Td = kron(Td1,Td2);
disp('T_d:')
disp(Td);
%Z vector of the Farrow Rate Converter
syms z n
% Generate the del Z(z) vector dynamically for the given M
Z = z.^(-(0:M-1)).';
% Compute the inverse Z-transform for each element of Z
t = iztrans(Z, z, n);
disp('Inverse Z-transform of Z(z):');
disp(t);
%Z vector of the Farrow Rate Converter
%Generate grad Z for the Newton Structure
gradt = T_z.*t;
disp('Inverse Z-transform of gradZ(z):');
disp(gradt);
%The delay vector of Farrow Rate Converter
%The Delay factor
mu = -0.5 + (0.5 - (-0.5)) * rand();
%Create the mu vector
mu_vec = (mu.^(0:M-1)); % Construct the vector with powers of mu
% Display the vector
disp('The vector mu:');
disp(mu_vec);
% Compute d using the given formula
d = mu - (M - 1) / 2;
% Initialize the d^T vector
d_T = zeros(1, M); % Preallocate space for the d^T vector
% Compute the values in d^T
d_T(1) = 1; % The first element is always 1
for i = 2:M
d_T(i) = prod(d:(d+i-2)); % Compute the product for each subsequent element
end
% Display the result
disp('The vector d^T is:');
disp(d_T);
% Transpose of delay matrix T^td
T_dtran = Td';
T_dtraninv = inv(T_dtran);
disp("The transposed inverse transformation delay matrix: ");
disp(T_dtraninv);
%Inv of T_Z
T_zinv =inv(T_z);
disp("The inverse of transformation of Z matrix:");
disp(T_zinv);
S = kron(T_dtraninv,Q);
NewtonC = (kron (S,T_zinv)); % Newton Coefficient matrix
disp("The Newton Filter Coefficient Matrix is :")
disp(NewtonC);
% Example matrix A
A = NewtonC; % Replace with your matrix
% Threshold below which elements are set to zero
threshold = 0.1;
A_sparse = A .* (abs(A) > threshold); % Set elements below the threshold to zero
% Convert to sparse representation
A_sparse = sparse(A_sparse);
% A_sparse is now a sparse representation of A
disp(nnz(A_sparse)); % Display the number of non-zero elements
%The Filter Matrix construction
H_1 = kron(d_T,A_sparse);
H_2 = kron(H_1,gradt);
disp("The Transfer function matrix H_Z:")
disp(H_2);
The Mathematical representation is also given below :%Note I used Q as Farrow Lagrange Coefficient filter matrix for notation of P .Instead of Q I used NewtonC as notation for Newton Coefficient filter matrix .I attached the pdf so that you can refer to the details.
I just want to know wether it is correct or not or how can I optimize it?????

采纳的回答

Gayathri
Gayathri 2024-11-7,7:13
I went through the code and the document attached for reference.
  • “del Z(z)” is defined as “T_z * Z(z)” in the paper attached. Hence, “gradt” variable should be defined as follows.
gradt = T_z*Z;
  • Also, another thing which I understood is that these equations involve matrix multiplications rather than dot product. Please verify the code with the paper attached to confirm if the equations really involve dot products or matrix multiplications.
  • I can see that the “kron” function is used to model the equation in screenshot attached. I doubt if they should be replaced with matrix multiplications.
  • We can remove the “for loop” in line 5 and replace it with code given below.
M=3;
x=0:M;
V =fliplr(vander(x));
The other implementations seem fine. You can proceed with this approach.
To know more about the “kron” function, please refer to the below link.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by