RMSE calculation problem-odd result

The fir_filter.m script saves in the workspace all the necessary variables so that i use them in simulink (using the load 'fir_filter.m' in callbacks). The first filter is in the library browser of matlab and the second filter is from the library browser of system generator. I am entering the same coefficient values and i want to calculate the error between the two filters. After the output of the first filter i integrated a transport delay which has a value of time delay equal to (N-1)/(2*Fs) where N is the number of taps and Fs is the sampling frequency. I chose to use the root mean square error to calculate the error depending on the value of the coefficient width i choose. The expected result would be to have a graph that the initial value is high and after coeff_width becomes 10 for example the RMSE stays at the same value. You can see in the graph that the RMSE gets a very low value at coeff_width and a higher as coeff_width increases which is odd. Can you spot any steps i did the wrong way ?
% MATLAB Code
% Equiripple Lowpass filter designed using the FIRPM function.
% All frequency values are in MHz.
Fs = 20; % Sampling Frequency
N = 14; % Order
Fpass = 5; % Passband Frequency
Fstop = 9; % Stopband Frequency
Wpass = 1; % Passband Weight
Wstop = 1; % Stopband Weight
dens = 16; % Density Factor
coefficients = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
{dens});
Hd = dsp.FIRFilter( ...
'Numerator',coefficients); % Calculate the coefficients using the FIRPM function.
%script for calculating root mean square error
for coeff_width = 3:8
sim('fir_compiler')
RMSE(coeff_width) = mean((error.data).^2);
end
save('rmse.mat');

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by