0

I have a task to select only the area I need from the signal and shift its spectrum.

I am digitizing the signal at 48kHz. A useful signal for me is in the region of 5500-5995Hz and 6005-6500Hz. In order to extract it, I multiply the digitized signal by $$\cos(2\pi n/(48000/6000))$$ and $$-\sin(2\pi n/(48000/6000))$$ and then pass these two signals through a low-pass filter with a cutoff frequency of 500Hz and a high-pass filter with a cutoff frequency of 5Hz. After that, I transfer the received signal to the right by 500 Hz. So that it takes the region I need from 0-1000Hz by multiplying each component by $$\cos(2\pi n/(48000/500))$$ and $$\sin(2\pi n/(48000/500)).$$

In this picture, perhaps it is expressed in a more understandable form:

enter image description here enter image description here

But when I transferred this algorithm to the microcontroller, I noticed that it works, as I think, not quite right. Help me to understand what I'm doing wrong? Can you describe in more detail how the spectrum is transferred to the desired area?

P.S. I am also interested in if I want to do signal decimation, when is the best time to do it? After LPF and HPF (before transferring the signal to the right by 500Hz.) Or after all the transformations?

Peter K.
  • 25,714
  • 9
  • 46
  • 91
red15530
  • 95
  • 6
  • Can you explain what you're seeing that's not quite right ? – Peter K. Apr 18 '22 at 18:01
  • @Peter K. I see those frequencies, which should not be as I think. As if some spectrum is additionally superimposed on my signal and changes its amplitude. – red15530 Apr 18 '22 at 18:25

1 Answers1

1

There is no allowance for transition band between the passband of interest (5.5KHz to 6.5 KHz less a notch in the center) and the frequencies in aliasing zones to reject based on the translation frequencies chosen. This means implementing the required anti-alias filters is not possible. One solution is to maintain a complex signal by implementing a full complex multiplier as the aliasing occurs in the final conversion to a real output, otherwise the frequency of the second translation must be increased to allow for transition bands for realizable filters, or the actual bandwidth of interest reduced.

I suspect that this is the primary effect in that the signal quality is limited by the actual attenuation of the filters with finite noise and signal in the image locations. There also is the possibly for amplitude and phase imbalance in the quadrature mixing- quadrature phase and amplitude imbalance between the I and Q paths would be more likely if any of that is done in the analog while the OP appears to be doing all quadrature multiplication in the digital — still there is opportunity if care is not taken to have delay, phase or amplitude imbalances which will show up through the testing detailed further below.

Below shows spectrum diagrams of the processing if the filter rejection and quadrature balances were perfect. This is the operation the OP desires:

quadrature frequency conversions

Consider the first translation as multiplying a real signal as represented by the top spectrum (which would have a Hermitian symmetric spectrum: same magnitude in positive and negative frequencies but opposite phase) with the complex tone $e^{-j2\pi 6000 t} = e^{-j2\pi6n/24}$ once sampled. This shifts the entire spectrum to the left just as the OP has shown which is then selected by the low pass and high pass filter. The performance of the low pass if of particular interest as that sets the image rejection for the next translation.

The next translation is multiplying this complex result (we can refer to the upper path in the OP's functional sketch as "real" (I) and the lower path as "imaginary" (Q) and then treat the two path output in the filter stage as a complex signal given as $I + JQ$) with another complex tone when sampled at $e^{j 2\pi n/48}$ which shifts the entire spectrum to the right as shown, and then we effectively take the real part of this full complex multiplication by not doing two of the multiplications required for an actual full complex multiplication:

$$(I_1+jQ_1)(I_2+jQ_2) = I_1 I_2 - Q_1Q_2 + j(I_1 Q_2 + I_2Q_1)$$

The real part of the above represents the processing actually done in the second translation stage ($I_1 I_2 - Q_1Q_2$) where $I_1, Q_1$ is the signal path and $I_2, Q_2$ is the cosine and sine used for translation. The result of the full complex signal is centered at +0.5 KHz. When you take the real part it will be centered at +/-0.5 KHz.

Any leakage from the filter that results in signals at -1 KHz prior to the second stage will be centered at -0.5 KHz after the frequency translation. When you take the real of that, it will also end up at +/-0.5 KHz and be distortion in the result. This depicted in the next graphic below showing how spectral content in the alias region from 4.5 KHz to 5.5 KHz will fold onto the desired signal at the output if not filtered out (either at the very front-end, or after the first multipliers:

aliasing

The issue here is the OP is interested in maintaining the input spectrum from 5.5 KHz to 6.5 KHz (ignoring the center notch which is of no consequence). The band that will alias in from the second frequency translation (once converted to real) is from 4.5 KHz to 5.5 KHz (at the real input). This allows for no transition between the band to reject and the band to pass whether the filter is implemented at the front-end or after the first frequency translation! Filter complexity and performance is dictated by how much frequency we allow to transition from a passband to a stopband.

Any quadrature amplitude and phase imbalances will also lead to such image distortion. This is less likely in an all digital implementation, but to show the effect consider the spectrum plot below showing how quadrature imbalance in the first multiplier stage would appear and how distortion results:

imbalance

To test and validate against these effects (regardless of final frequency plan and bandwidth used), consider using a single tone at the frequency of interest and measure the “conversion gain” from input to output. Then put this tone at the image frequency locations and measure the image suppression. For example, to confirm the -6 KHz balance try a tone just at 6.25KHz and see how much appears at 0.75 KHz in the output as it should versus how much appears at 0.25 KHz which is dues to quadrature amplitude and phase imbalance in either of the two multiplier stages. (I suspect this should be quite good if done digitally but worth confirming). Then put a tone just at 4.75KHz to test the filter rejection. This will end up at -1.25 in the middle stage which will be rejected by the low pass filter (to some degree) and whatever is not rejected will shift to -0.75KHz after the second stage multiplier, and when you take the real of that will also be at +/-0.75KHz. (From this we also see as currently done, the appropriate filtering as we approach the 5.5 KHz edge is not feasible).

The best place to do decimation is after the filters and prior to translating to a higher frequency. Although depending on decimation ratios and approach it may not make any different. To decimate properly, understand where all the aliasing frequency bands are given the sampling rate and decimation ratio and ensure there is sufficient rejection in these zones specifically. See this post for further details on aliasing bands with decimation.

If the operations in the above spectrum plots are confusing, this post provides further detailed insight into the frequency translation of complex signals.

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
  • Part of the information I didn’t quite understand... If I’ve got something wrong please correct me:
    1. I tried to use high-pass filter with 5Hz band to cut the unnecessary part of the spectrum 5995-6005Hz, after I shifted the spectrum to the left by 6kHz. If I’ve got this right, won’t it work?
    2. In the second figure you explain that a nearby lying spectrum can penetrate the main signal. I take it you can fight this if you use a low-pass filter with a steeper cut bar (use a larger filter order or use, for example, an elliptical filter)
    – red15530 Apr 19 '22 at 06:43
  • Now I see a solution like this (correct me if I misunderstood something): First, I left-shift the original signal by 6kHz by multiplying by cos and -sin of the appropriate frequency. Next, I pass the received signals through a low-pass filter with a cutoff frequency of 500 Hz (Elliptical low-pass filter of the 6th order). Next, I can decimate the signal by a factor of 24 and then shift the signal to the right by 0.5 kHz by multiplying by cos and sin of the corresponding frequency and take only the real part. – red15530 Apr 19 '22 at 06:46
  • Also now I have a question about the last transformation - Complex Output (if full complex multiplier was used)->Real Output. At first I only have a real signal, after I multiply it with cos and -sin I get a complex signal. And then I work only with a complex signal, and at the end of all transformations, if I take only the real part. On the last graph, you showed that if you take only the real part, I will see a copy of the signal in negative frequency. I can't understand, since in the real world there is no negative frequency, how does this affect the positive frequency region? – red15530 Apr 19 '22 at 07:09
  • No in your solutions you are not able to reject the pattern that will interfere. In the “real world” you mean a signal that you can measure with just one scope probe, you absolutely have negative frequencies. The only way to not have negative frequencies is to have a complex signal (which you have in the real world when you use two scope probes to measure the signal: the output after your first multiplier is a single complex waveform, where you need two scope probes to measure after each multiplier). As another example review the FT of a sinusoid- it has a positive and negative frequency. – Dan Boschen Apr 19 '22 at 12:20
  • Your issue in all your cases where you shift by 0.5 KHz and want a bandwidth that extends out 0.6 KHz from your center frequency and you want the output to be real only is that you have allowed no transition band for your filter- there is no possible filter that can both pass 5.5KHz and reject 5.4999999 KHz. So everything at 5.5KHz and below will fold as I’ve shown. Please read through the link I pasted at the bottom of the answer- that will help you. – Dan Boschen Apr 19 '22 at 12:23
  • I think the reason you may think real signals don’t have negative frequencies is that for the case of real signals we can plot just the positive frequencies since the negative frequencies are complex conjugate symmetric (same magnitude opposite phase)- so they are redundant and don’t need to be shown. However they are there regardless – Dan Boschen Apr 19 '22 at 12:27
  • Thanks a lot for your answers. It became much clearer to me! So the whole problem is that I can't make a perfect LPF filter? This means that always after a shift to the right for 0.5 kHz, I will see parts of the signal at frequencies of 5-5.5 kHz that will be mixed into the signal I need. Is there any other way to isolate the 5.5-6 kHz signal I need and get rid of the rest of the frequencies? – red15530 Apr 19 '22 at 13:16
  • One more thing I want to understand to support the material. At the input from ADC, I have one signal - let it be “x”. Next, to shift left: xcos(pi6n/24)-jxsin(pi6n/24). Next LPF Next to shift right (xcos(pi6n/24)-jxsin(pi6n/24))(cos(pin/48)+jsin(pi n/48))= (xcos(pi6n/24))(cos(pin/48)) + (xcos(pi6n/24))(j sin(pin/48)) – (jxsin(pi6n/24))( cos(pin/48)) + (xsin(pi6n/24 ))(sin(pin/48)). And then I take only the real part ((xcos(pi6n/24))(cos(pin/48)) + (xsin(pi6n/24))( sin(pin/48))) of this signal for further processing. Did I understand correctly? – red15530 Apr 19 '22 at 13:20
  • Yes you can’t make perfect LPF- the part about keeping a complex output is one solution and not converting to real. – Dan Boschen Apr 19 '22 at 13:25
  • Yes it looks like you did it right and hopefully start to see how cumbersome it is to try and do that with sines and cosines. See my link and how I do all the analysis with exponential form and how much easier that is— then in final implementation I break it into real and imaginary data paths. – Dan Boschen Apr 19 '22 at 13:29
  • @red15530 did I answer your original question? – Dan Boschen Apr 19 '22 at 17:35
  • Yes, thank you very much!!! – red15530 Apr 19 '22 at 17:41
  • I tried to write this algorithm on a microcontroller, but only to select several frequencies: 4.5-5.5;5.5-6.5;6.5-7.5kHz to see how adjacent frequencies can penetrate each other. If I send a signal from the generator at one frequency (for example, 6kHz), I clearly see it at 5.5-6.5kHz and it does not penetrate into neighboring frequencies. If the signal is at the border (for example, 5.5kHz), then I see it at 4.5-5.5 and 5.5-6.5. But as soon as I apply a whole set of frequencies, as in my picture, some kind of confusion begins... – red15530 Apr 19 '22 at 17:41
  • I do not see clear levels, as if the frequencies are simply mixed with each other. What could be my mistake? – red15530 Apr 19 '22 at 17:42
  • They are mixing with each other (see my diagram at the bottom how they will be superimposed when you send a broad range of frequencies—- just follow through the math very carefully and make sure you really understand and agree with the aliasing that is happening and then it will make more sense—- we should avoid long ongoing discussion in the comments (per our esteemed moderators) so can’t do a full debug here, but if you can narrow it down to a new and different question, please post it – Dan Boschen Apr 19 '22 at 19:42