To obtain the coefficient value matrix Transforma​tionStateD​elayMatrix for for a method of a class definition NewtonRateConverter

26 views (last 30 days)
I have tried to defined a class definition
classdef (StrictDefaults)NewtonRateConverter< dsp.FarrowRateConverter &...
dsp.internal.SupportScalarVarSize & ...
dsp.internal.MultirateEngine &...
dsp.internal.FilterAnalysisMultirate
%Constructor
methods
function obj = NewtonRateConverter(varargin)
% Constructor for the NewtonRateConverter class
setProperties(obj, nargin, varargin{:}, ...
'InputSampleRate', ...
'OutputSampleRate', ...
'OutputRateTolerance', ...
'PolynomialOrder');
end
end
basically it overrides the Farrow Rate Converter and introduce certain conversions over it .
Now for it two Transformation Delay Matrices Td1 and Td2 are required. Mathematically Td1
M is the Polynomial Order
So I created function file for Td1
function Td1 = compute_Td1(M)
% Create a matrix of binomial coefficients
[I, J] = ndgrid(1:M, 1:M);
binomials = zeros(M, M);
for i = 1:M
binomials(i, 1:i) = arrayfun(@(ii, jj) nchoosek(ii-1, jj-1), I(i, 1:i), J(i, 1:i));
end
% Create a matrix for powers
powers = ((- (M - 1) / 2) .^ (I - J)) .* (J <= I);
% Element-wise multiplication to get Td1
Td1 = binomials .* powers;
end
This I defined as a static method in NewtonRateConverter
>> compute_Td1(3)
ans =
1 0 0
-1 1 0
1 -2 1
>> compute_Td1(5)
ans =
1 0 0 0 0
-2 1 0 0 0
4 -4 1 0 0
-8 12 -6 1 0
16 -32 24 -8 1
I entered this as a function as a property and method in this class definition NewtonRateConverter
properties
TransformationDelayMatrix1
PolynomialOrder
end
methods
function computeTransformationDelayMatrix1(obj)
% Access PolynomialOrder from superclass
M = obj.PolynomialOrder;
% Compute TransformationDelayMatrix1 using compute_Td1
obj.TransformationDelayMatrix1 = compute_Td1(M);
end
end
When I tried to access this object TransformationDelayMatrix1
% Initialization
myNRC = NewtonRateConverter('InputSampleRate', 44100, 'OutputSampleRate', 48000, 'PolynomialOrder', 3);
myNRC.TransformationDelayMatrix1
In the command window it displays :
>> myNRC.TransformationDelayMatrix1
ans =
[]
Why is this an empty array shown please could you clear out this doubt ?Please could you debugg ?I have tried to defined a class definition
classdef (StrictDefaults)NewtonRateConverter< dsp.FarrowRateConverter &...
dsp.internal.SupportScalarVarSize & ...
dsp.internal.MultirateEngine &...
dsp.internal.FilterAnalysisMultirate
%Constructor
methods
function obj = NewtonRateConverter(varargin)
% Constructor for the NewtonRateConverter class
setProperties(obj, nargin, varargin{:}, ...
'InputSampleRate', ...
'OutputSampleRate', ...
'OutputRateTolerance', ...
'PolynomialOrder');
end
end
basically it overrides the Farrow Rate Converter and introduce certain conversions over it .
Now for it two Transformation Delay Matrix Tz are required. Mathematically Tz
M is the Polynomial Order
So I created function file for Tz
function T_z = calculate_Tz(M)
% Initialize the matrix T_z with zeros
T_z = zeros(M, M);
% Fill the matrix T_z using the given formula
for i = 1:M
for j = 1:i % j goes from 1 to i
T_z(i, j) = nchoosek(i-1, j-1) * (-1)^(j+1);
end
end
end
This I defined as a static method in NewtonRateConverter
>> calculate_Tz(3)
ans =
1 0 0
1 -1 0
1 -2 1
I entered this as a function as a property and method in this class definition NewtonRateConverter
properties
TransformationStateDelayMatrix
end
methods
function computeTransformationStateDelayMatrix(obj)
% Access PolynomialOrder from superclass
M = obj.PolynomialOrder;
% Compute TransformationStateDelayMatrix using calculate_Tz
obj.TransformationStateDelayMatrix = calculate_Tz(M);
end
end
When I tried to access this object TransformationDelayMatrix1
% Initialization
myNRC = NewtonRateConverter('InputSampleRate', 44100, 'OutputSampleRate', 48000, 'PolynomialOrder', 3);
myNRC.TransformationDelayMatrix1
In the command window it displays :
>> myNRC.TransformationStateDelayMatrix
ans =
[]
Why is this an empty array shown please could you clear out this doubt ?Please could you debugg or suggest solution for the problem?

Answers (1)

Gayathri
Gayathri on 18 Nov 2024 at 6:42
I understand that you are getting an empty array for "TransformationStateDelayMatrix". This is because the function for calculating the matrix is not invoked yet.
myNRC = NewtonRateConverter('InputSampleRate', 44100, 'OutputSampleRate', 48000, 'PolynomialOrder', 3);
myNRC.computeTransformationDelayMatrix1();
myNRC.TransformationDelayMatrix1
Now, we will be getting a non-empty array for "TransformationStateDelayMatrix1".
Also, there is no need to mention "PolynomialOrder" in the properties section as this is already inherited.

Community Treasure Hunt

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

Start Hunting!