## Overdriven Sine Wave through DSP Filter

Started by 3 years ago●17 replies●latest reply 3 years ago●274 viewsHello,

I'm not a DSP practitioner or even have the math background to fully comprehend the topic, but hoping to get a grasp on something. If a sine wave that is over-driven resulting in a square wave is applied through an FIR filter what is the result? Is the result different through an IIR filter? Is one better

suited to handling this condition?

Thanks!

Gary

Depends on the filter cutoff. Let's call Fa the square wave fundamental frequency. If the filter cutoff is between Fa and 2xFa, you'll get a sinusoid back with frequency Fa. If it is > 2xFa, you get back a rippled sinewave, with the ripple being a factor of how many harmonics remain after the filter cutoff. If it is less than Fa, you'll get nothing.

FIR will have linear phase, i.e. no phase shift across the frequency band, which is commonly important in audio applications. But it will most often require a longer filter for the same response, than IIR, which are generally more efficient.

Which is better, depends on your application, processor capability, etc.

Robert

Hi,

Sorry, I should have known to put down the frequencies which might be useful in such a question. And also didn't mention this requires a bandpass. Since the IIR is more efficient and phase is not an issue, just magnitude and as ripple free as possible output let's say it will be an IIR. Your point on FIR, I have worked with the FIR in CMSIS and found it takes too many taps and too much processing to get the desired result in this non-audio application.

The stuff I am working with, pretty low frequency right now. I'm trying to filter at 100Hz, and there's a potential interfering tone at 70Hz, and one at 185Hz. So it will be a band-pass IIR. Incidentally, I am using ASN filter designer to derive coefficients to be used in a CMSIS-DSP lib based M4 device.

With the amplifier at "high" gain there is a risk the auto-gain may not respond fast enough and the sine wave will be overdriven for some cycles. Also, since amp gain is up so will the amplitude any potential interfering frequencies. So if I understand you correctly it should adequately filter out anything up to 200Hz and result in a sine wave out. How does this work out for the lower side since 2Fa is at DC ?

Thanks again for taking the time.

Hi Groger,

What is the sample rate of your A/D converter? Are you using an anti-aliasing (AA) filter? What is the AA filter's stopband frequency/attenuation?

Note that for a square wave, harmonics not attenuated sufficiently by the AA filter may appear as aliases, depending on the sample frequency.

Finally, depending on the cutoff frequency of the AA filter, any squarewave will have some harmonics filtered, so the digital filter will not see a very "square" signal.

regards,

Neil

The BPF is an active filter with gain followed by another gain stage, so clearly it's the post BPF gain stage that needs AGC to limit the clipping!

Thanks for your feedback.

I'm not necessarily an expert in these matters, but you'll need to design your bandpass to give sufficient attenuation at +/- 30 Hz, to take out the 70 Hz. Typically -55 dB or more, i.e. attenuation 0 dB@100 Hz, -55 dB@70 Hz. The 185 Hz will be taken out as a consequence, as long as your sampling frequency is > 370 Hz, otherwise the 185 will alias back in. Not sure how many taps that'll require. I've had best luck with Elliptical.

My 2Fa was just general discussion. But your situation needs to take out less than 2Fa, per comments above. If designed as above, anything from 70 Hz to DC will be gone (and anything from 130 Hz and above).

Robert

Some quick thoughts.

There are two things to consider:

- the amount of overdrive, i.e. just a little clipping, or large overdrive giving a trapezoid shape, or the massive overdrive that creates the almost square shape you have noted
- the size of the filters (number of terms) relative to the sample rate

The frequency content of the clipped signal can be predicted, so have a quick compare of those frequency spectra.

The IIR nominally can do a bit better, given a known single sine wave, but modern digital systems often have plenty of capacity either way.

thanks philipoakley.

Are you familiar with the CMSIS DSP libs? I am thinking that given the filter coefficients generated by ASN (about 12 entries) this must be more efficient to crunch for the DSP than the 128 tap filter of the FIR.

I will model it and see directly the results.

Hello all,

Many thanks for all these responses. Again, I missed a key piece of info, sorry. The sampling rate will be 1024 Hz. Seems a base 2 value works well or better with the CMSIS lib calls.

In front of it will be a Butterworth-Bessel 4th order bandpass filter with about -8dB at 70Hz and around -18dB at the 180Hz mark. SO this will at least provide some attenuation, but in reality it will also cause a bit of ringing which should be acceptable.

So, are you only interested in a 100Hz tone? ...or a band around 100Hz? ...and, if you are only interested in the 100Hz tone, what about that tone is of interest to you?

Hi ,

The signal of interest is just 100Hz, that's all. Amplitude only with as little distortion as possible from noise, phase doesn't matter

Got it. My thoughts immediately go to using a lock-in amplifier. ...but noise interference is always better avoided than grappled with.

fred is explaining it well. As soon as you sample the clipped sine, you have higher order harmonics polluting your Nyquist band.

The 70 Hz and 185 Hz may be your biggest concerns, but they are not necessarily your only concerns. Even with a solid 100 Hz signal extraction technique, you can't know that one of those unwanted harmonics hasn't already landed on top of your signal of interest. If so, you won't know what of that magnitude is your signal and what is artifact.

Sometimes, an analog filter is the most elegant solution.

Hope this helps.

Yes, these explanations make a lot of sense. in fact, I have previously observed a "regurgitated" signal that had to have come from harmonics at 100Hz (using a FIR) Yes, a decent 4th to 8th order filter will be used with AGC. My only concern with using such a filter is the step response and time lag, but that is the lesser of the evils.

Thanks!

Hi Gary,

You don't want to do what you say you are doing. A nonlinearity in the DSP domain will generate harmonics in the signal spectrum which will appear in the primary Nyquist zone if the harmonics are below the half sample rate frequency. The harmonics which spill into higher order Nyquist zones will alias back into the primary Nyquist zone and can appear below the fundamental as well as above. The first rule of DSP signal processing is that any linear operator in the analog domain has a counterpart in the sampled data domain. (not true in reverse). This is guaranteed to not be so for non-linear operators due to the spectral aliasing. If you want to protect the signal integrity of an input sinusoid with known frequency but with unknown variable amplitude, you are better off doing so with a simple AGC circuit. I can help with the design and implementation. let me know if you want additional assistance.

The best approach is to use a short recursive hilbert transform to make the signal complex. Then use a log AGC loop to control the amplitude of the complex envelope (which is available at every sample position. See attached

fred h

Hi Fred, that is interesting. What is the file you sent? Not familiar with the extension/type.

I should have been a bit more clear on the AGC. I *can* design the gain control in analog, but I was hoping to bypass that and do processing for an over driven signal using DSP. So it seems like it's best to handle the signal properly first, and that indeed makes sense. So it's back to square one..or thereabouts. I will go with an IIR and do some testing with that and a bread boarded circuit.

Thanks!

Hi groger,

I think you missed the thrust of my first response. You can not hard limit a sampled data signal and filter out the harmonics the same way you can an equivalent continuous analog signal. In the continuous analog domain, the harmonics go on and on till they fall below the noise floor of the process.

In the sampled data domain, the harmonics reach out to the half sample rate and then start wrapping around (sometimes, incorrectly called folding back into) the fundamental Nyquist zone. Even if you extract the single desired tone with an amazingly good filter and hard limit the signal, the spectrum will be filled to the brim with aliased frequency terms which will defeat any reasonable filtering operation you use to try to again isolate the desired tone.

see attached figures

fred h

Hard_Limited_Tones_.pdfhi,

Just wanted to give an update. After some testing I discovered how an overdriven signal causes fold back even when a strong IIR filter is used. In addition I'm processing the signal in HW through an 8th order bandpass with pretty good suppression. So the real story is not only can a interfering signal cause a problem, but the signal of interest must be kept under control with AGC. These problems very evident when reconstructing through the DAC.

Thanks for the insight and help! The science of DSP is simply amazing.

gary