2
$\begingroup$

I'm trying to understand the behavior of two different methods of decimating and frequency translating a signal. At this point, I'm only swapping the translation and decimation; I'm not doing any polyrate processing. The graphic below depicts the basic idea. I have a linear phase filter around cf. The signal is translated by (for now offset is 0)

shift = -cf + FsOut/4 + offset

and then complex filtered, decimated down to FsOut/4, and converted back to real. The input rate is either 2, 4, 8, or 16 times the output rate.

Narrowband signal translation

I thought I might as well speed things up a bit by re-ordering the filter and decimation with the translation. Basically it's the same thing, except I multiply the frequency translation rate by the decimation factor. As it turns out, when offset is zero, the two different methods result in bit exact replicas of the signal. Note I'm quantizing to 8 bits. I believe when the decimation ratio is 16 and offset is a multiple of FsOut/8, the two methods may also be the same or at least somehow very close.

More generally, when offset is not zero, the time domain signal is out of phase, but I get approximately the same power spectrum. Now as frequency translation is not a linear operator, it's not immediately obvious why I would get the same time domain signal in this special case. I thought maybe it happens to work out that there is a simple linear relationship between the two different methods, so I spent some time trying to find a phase offset as a function of the offset and decimation ratio that would make the time domain signals always identical, but I couldn't come up with anything. I also tried looking at the phase of the cross-spectrum, which should be a line if one signal is just a delayed copy of the other, but it only works for offset equal to zero (obviously since they are identical).

After thinking about it for a while, my best guess is that if you were to write this as a poly-phase structure and commute the translation operation with the filter and decimate operations, it would just happen to work out that in the special case of FsOut/4, frequency translation could be pushed all the way across the final sum (after taking the real part). But normally, is it correct that there is no linear relationship between these two different methods, or have I just got something wrong here? Also, practically, is there any reason why it would matter which way I do it? I'm only comparing the two methods to make sure I've done it correctly.

EDIT

I can't give out my code. But I can try to provide more detail. Also, I just realized I forgot to take the real part in method 2, but it doesn't appear to change anything. In method 1, the LPF (h) is centered about FsOut/4. So we have something like the following in Matlab.

f0 = shift/fsIn*2*pi;
y = x .* exp(1j*(0:blen-1)*f0);
y = filter(h,1,y);
y = real(y(1:dec:end));

In method 2, the same filter is located at cf. I reorder the operations.

y = filter(h,1,x);
y = y(1:dec:end);
f0 = shift/fsIn*2*pi*dec;  % note decimation multiple
y = real(y .* exp(1j*(0:blen/dec-1)*f0));

To rephrase the question, is there a linear operator that takes the output of method 1 and yields the output of method 2 for offset not zero? I believe it only happens to work for FsOut/4 as described above. But I'm not sure...

EDIT 2

Maybe there is a problem with translating the filter to high-frequency?

-Maximilian

You were correct. Now that I've had some time to look this over, I see it was as simple as that. In fact, there is no correction factor needed at all. I don't know why I wasn't seeing a simple linear phase relationship between the two methods. I may have done something wrong when taking the cross-spectral phase, or maybe it was related to something else, like an issue with the quantization. Lesson learned. I should have distilled my simulation down to the simplest possible code when I got stuck as you did in your post.

So the issue was I was translating the upper filter to fc instead of (fc-offset). As you can see in the plot on top, the black lines are the center of the two filters. The red lines are where the filtering occurs. The center of the upper filter needed to be shifted by offset so that the phase change would be the same.

It's easy to calculate the phase offset introduced. The bottom diagram shows the linear phase slope for a unit delay filter. Using the filter I provided in the comments, the slope would be 640π/(FsIn/2). Thus the correction factor is exp(-i*640π/(FsIn/2)*offset). Of course, it doesn't make sense to fix the problem this way since you will still get some error due to ripple in the pass band. If you filter in the exact same place relative to the center frequency of each filter, the only error should be numerical.

I also noted that you happen get very small error if shift is a multiple of FsIn/(group delay) (e.g. 1e6/640), even with the offset error. The reason is obvious now; plug into the exponential above and you get exp(-i*2π) == 1. The error is probably due to slight magnitude response differences in the pass band and/or possibly due to the stop band of the negative sine frequencies. One last thing I noted empirically; there is no phase change due to decimation and aliasing of the upper filtered signal -- obviously, or this wouldn't work without phase correction.

enter image description here

$\endgroup$
  • $\begingroup$ I dont really get your exact question. PLease describe more exactly (in (pseudo-code) or equations), what you currently do and what you want to do to speed it up and what is your question/problem that occurs. $\endgroup$ – Maximilian Matthé Dec 15 '16 at 6:55
0
$\begingroup$

In method2 you run into the problem of aliasing: After filtering your signal, it has a bandwidth of FsOut/2 in the bandpass region. Though, your sampling frequency is FsIn, and the maximum frequency in your signal is still Cf+FsOut/4. So, if you decimate down to FsOut you run into aliasing. This aliasing creates a mirror image of the spectrum somewhere else in your downsampled signal. Then, in your frequency shift-step you again shift this spectrum to somewhere and take the real part.

I assume that for off=0, you have some numbers for cf, FsIn and FsOut that work such that the spectrum in the end comes to the same position with both methods. With off~=0, it just does not.

So, to answer your question: These, there is a linear operator. This operator is another frequency shift (which can be combined with your first one), which shifts the spectrum to the correct frequency. However, without knowing the numbers, we cannot give you the exact solution.

Taking the values from your comment, I can guess the following:

FsIn = 1e6;
fc = 3e5;
f1 = fc;
f2 = fc+0.01e5;

t = 0:1/FsIn:0.1;


x = sin(2*pi*f1*t) + sin(2*pi*f2*t);


dec = 2;
FsOut = FsIn / dec;
offset = 1000;
shift = -fc + FsOut/4 + offset;

% method 1:
y = x .* exp(2j*pi*t*shift); % Downconvert
y1 = real(y(1:dec:end));     % Downsample

% method 2
y = x(1:dec:end);            % Downsample
y = y .* exp(2j*pi*t(1:dec:end)*shift);  % Downconvert. 
% (This equals multiplying the shift by dec, and just taking the first N/dec samples from t.)

y2 = real(y);

hold off;
plot(t(1:dec:end), y1, 'r-x');
hold on;
plot(t(1:dec:end), y2, 'b-o');

xlim([0.022, 0.0222]);

enter image description here

As you can see, both methods yield the same signals. Here, I omitted the filtering, cause I dont know what filter you use. Maybe there is a problem with translating the filter to high-frequency?

$\endgroup$
  • $\begingroup$ I'm aliasing intentionally. I've verified by using two closely spaced sinusoids that they end up in the correct place (using 310e3 and 300e3 cf with FsIn 1e6 and the decimation ratios in my post). The issue is the phase is different. So the spectrum looks right, but the time domain signal differs. At FsOut/4 the signals are identical. $\endgroup$ – Todd Dec 16 '16 at 15:14
  • $\begingroup$ Also, frequency shift isn't linear. Since I know the signal is in the right place, and I believe the power is correct up to error in the filter, the only possible linear operator would be a delay. $\endgroup$ – Todd Dec 16 '16 at 15:42
  • $\begingroup$ frequency shift (i.e. multiplication by complex exponential) is a linear operation. And I know that you are aliasing intentionally. Maybe, if you provide some example of a signal, FsIn, FsOut, c and filter we can find out what's going on? $\endgroup$ – Maximilian Matthé Dec 16 '16 at 16:23
  • $\begingroup$ I appreciate your help, but I can't spend more time on this right now. It should work with the cf and FsIn provided in my last comment and decimations of 2, 4, 8, or 16 and any signal so long as the passband is narrow enough. Am I mistaken in that a linear operator only maps complex exponentials onto complex exponentials? Therefore, any translation of a frequency component would not be linear. $\endgroup$ – Todd Dec 16 '16 at 16:41
  • $\begingroup$ I've added some test based on your values, showing that both methods are equal. Regarding linear operator: Linear, time-invariant operators (i.e. convolutions) map complex exponentials to complex exponetials of the same frequency. However, general linear operators can do a frequency shift (just check the property for linearity). Also, e.g. the Fourier Transform or time-reversal operator are linear. $\endgroup$ – Maximilian Matthé Dec 16 '16 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.