Let's first look at your unfiltered upsampled signal xu
(from your previous question) in the frequency domain to better understand what is going on:
As you can see there are 8 replications of the original low-frequency signal (often referred to as images) at Fs/8
, 2*Fs/8
, ..., 7*Fs/8
. Those images includes both the positive and the negative frequency components, so the image around Fs/8
extends from approximately Fs/16
to 3*Fs/16
.
Correspondingly, the design cutoff frequency of your filter should be around Fs/(2*M) = Fs/16
or
Fpass = 1200000/2; % Passband Frequency
Fstop = 1250000/2; % Stopband Frequency
The resulting magnitude response of the filter designed with:
N = 20;
b = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
{dens});
can be seen with freqz(b,1)
:
As you may notice, the filter offers very little attenuation in the stopband. The images I alluded to earlier will thus still be providing a fairly significant contribution to the filtered output. Increasing the number of coefficients will help a little but you're likely to find out that you need a lot of coefficients (on the order of 500-1000) to get a decent stopband attenuation and a sharp transition band.
Comparatively, the filter coefficients generated with fir1(60, 0.125)
(as used in my previous answer) provide a much better attenuation where the images are the strongest in the frequency domain, but also has a much wider transition band and uses more filter coefficients. The resulting filtered signal in the frequency are then:
So the question then come down to a tradeoff between the number of coefficients (which affect the computing requirements and the filter delay), the transition band width and the stopband attenuation. To properly answer we would need to know what are your specific application's requirements.
Provided you are trying to interpolate signals with similar bandwidth as the half Gaussian pulse you've used as input (thus not requiring as sharp a transition band as the 50000Hz you specified) and the number of coefficients is the primary concern, you may find the following design performs a little better (although it would still have some significant artifacts) for the same number of coefficients (i.e. 21):
Fpass = 550000/2;
Fstop = 1250000/2;
Wpass = 1;
Wstop = 22;
N = 20;
b = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
{dens});
Of course, increasing the number of coefficients (as well as relaxing the transition band requirements as done above) would further reduce the interpolation filter's error. Alternatively, using a multi-stage filters (e.g. upsample by 2 then filter, three times in cascade) could also reduce the interpolation error with the same overall number of coefficients and transition bandwidth.