# Filter design

1. Dec 4, 2005

### guru

I posted the details of myquestions earlier but no help. Maybe I need to rephrase it.
I basically generated a square wave and added noise to it using Matlab.
The question is how do I design a filter to reduce as much noise as possible to retain most of the square wave. The SNR is OdB.

2. Dec 4, 2005

### Staff: Mentor

Sounds like a Cheby filter with ripples in the passband (or an elliptical with ripples everywhere) would work the best, with the ripples matching the spectra of the square wave (fundamental, 3rd harmonic, etc.).

3. Dec 4, 2005

### guru

thanks for the help!
How do I determine the cutoff (corner) frequency to use given the frequency of the square wave and the sampling frequency.

4. Dec 5, 2005

### Staff: Mentor

If you want to keep it simple, just use the fundamental of the square wave, and put the cutoff right above that. A little fancier is what I was mentioning, to match a Cheby/elliptical filter's ripples to the 1/f rollof of the square wave's harmonics. The best solution, though, would be to do a correlation with a square wave of the same frequency. Do you always know the frequency of the original square wave?

5. Dec 5, 2005

### Staff: Mentor

Edit -- I think a straight digital correlator design would give you the best results, if you know what the frequency of the original signal is. A digital correlator is where you have a shift register that you feed your input digitized signal into one end, and at each sample clock tick, you shift the data through the ganged registers. For each sample clock tick, you multiply each register value by some coefficient, and take the overall sum of the multiplications as the correlator output for that clock tick. To correlate against a bipolar square wave, for example, the coefficients for the first half of the ganged registers would be something like +1, and for the second half they would all be -1. The correlator is one period long for the square wave, measured in sample clock ticks.

So when you feed in your bipolar square wave plus noise, the output of the correlator will be +A (A=amplitude of the input signal) when the input signal lines up with the square wave coefficients, and -A when it lines up opposite of the coefficients. The correlator output is not a square wave -- instead it has peaks where the correlation is max and min, and zero crossings between these peaks. To convert the correlator output back to a square wave, use the A number and the zero crossings to take your best guess at the original signal. You will get very good noise rejection by using a correlator, especially if you have lots of samples per cycle, and as many bits per sample as possible. You should be able to get well below a 0dB SNR with a good correlator design. You can do this all in MatLab, so try it out! -Mike-