Saturday, September 29, 2018

matlab - Different way to separate a particular frequency from a signal


Let's say I have a signal which is composed of 2Hz,10Hz,17Hz,19Hz and 25Hz discrete time sinusoidal waves and I need to allow only 17Hz component to pass.


As far as I know, the standard way to approach the problem is implementing a Band Pass Filter.( Analog Prototype Filter -> Analog Filter -> Digital filter using Bilinear Transformation).


We can also implement DFT on the signal and use the information from the spectrum and then reconstruct the 17Hz component,right? If yes, which method is preferred and why?



Answer



If the frequencies to be rejected are the discrete frequencies given, and the sampling rate can be commensurate with these frequencies, then a moving average filter with the coefficients complex rotated to shift the response to 17 Hz can be done to reject all other integer frequencies as in the plot below.


rotated moving average


This is the concept of "homodyning the coefficients" rather than homodyning the signal. When we homodyne a signal, the signal is multiplied by a complex rotator ($e^{-j\omega t})$ which will in the process shift it in frequency according to the rate of rotation. In similar fashion, rotating your coefficients will shift the response of the filter. So you can either move your signal to the filter as in a downconversion followed by a low pass filter... or move your filter to the signal as in this case!



Here is the Matlab/Octave code that implemented this filter.


In this case the sampling rate is 26 Hz with a complex (I and Q) signal path.


z=exp(j*2*pi/26);
coeff=z.^([0:25]*17);
[h,w]=freqz(coeff,26,2048,'whole');
plot(w/pi*13,20*log10(abs(h)))
grid on
axis([0 26 -50 0])

(Note, this is the same frequency response as one bin in the DFT)



The coefficients themselves follow the pattern as shown in the following complex diagram, where the first 5 coefficients are labeled, and the rest can be followed along the trajectory lines shown. Observe that the magnitude of each coefficient is one (as in a moving average filter) but the phase is continuously rotated which causes the frequency response to shift at the rate of rotation.


complex taps


Update: As further suggested by @MarcusMüller in the comments, actually doing the signal homodyne followed by a low pass filter may likely be simpler in this case given that the OP has variable conditions for the signal of interest. Assuming the interference to be rejected is still discreet tones with an integer spacing relationship to the signal of interest (the signals need not be integer frequencies, but the multiplies of their spacing must be, as the nulls of a moving average filter will be located at n/T Hz where n is any integer and T is the time duration of the moving average in seconds).


So in this case we would first multiply the signal by $e^{-j2\pi 17 t}$ and then follow the (complex) output with a moving average filter (which means two filters, one for the I (in phase or real) path and one for the Q (quadrature or imaginary) path. In this case the moving average length as a minimum must be:


2Hz,10Hz,17Hz,19Hz and 25Hz


Move 17 to 0:


-12Hz, -7Hz, 0 Hz, 2Hz, 8Hz


And the least common multiple is 1 so a 1 second moving average is required with a commensurate sampling rate. Further as @MarcusMüller has suggested, this moving average structure could be implemented as a CIC decimating filter. The output would be the "DC Equivalent" of the signal of interest, with the same amplitude and phase as the signal at 17 Hz. Further if the signal that is desired changes in frequency, the phase rotator can be changed in one place rather than updating the taps as I had done.


For further reading see:


Phase rotator: Numerically Controlled Oscillator (NCO) for phasor implementation?



CIC: CIC Cascaded Integrator-Comb spectrum


Note also to be considered as a filtering approach is the 2nd order resonator (or cascade of two of these structures), based on a rotated exponential averaging filter. (see FFT analysis for Vibration Signal). The image of this filter structure is duplicated below (see link for details on what the variables mean and how to compute them):


tuned exponential averager


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...