Create an image filter

I want to create a filter that looks like this:
I would like to create a filter that goes from 0 to alpha, then go to -alpha and go back to 0 in an interval called N.

7 Comments

WIth what rise time, and what hold time?
Is it correct that the rise slope for the initial rise should be the same as the descending slope and the same as the second rise?
Alber
Alber on 29 Apr 2020
The only thing they have told me is that it has that the time will be N, so I suppose that from 0 to the first 0 it will be N / 2 and from 0 to the third 0 it will be other N / 2 and yes, if it is correct because in the end it has I have to have this exact shape so that it does not produce high frequency components for a specific interpolation that I am doing.
Alber
Alber on 29 Apr 2020
What I want is for the 'key' values of my filter to be [0, alpha, 0, -alpha, 0] and to be uniformly distributed from 0 to N.
You still need to know the hold time or know the slope. The shorter you make your hold time, the shallower you can make your slope.
For example you might plausibly say that the first rise shuld be the first 1/6 of the time, the hold should be the next 1/6, that the descend should be the next 2/6, the negative hold should be the next 1/6, and the ascend to 0 should be the last 1/6.
But it would be equally valid to say that the hold time should be 0 and that the first 1/4 of the time should be rising, the next 2/4 should be falling, and the last 1/4 should be rising, with the flat areas being nearly non-existent.
Alber
Alber on 29 Apr 2020
The only thing I know is that when applying the Fourier transform I have to get what frequency corresponds to half the power (-3dB) in logarithm and I have to get a filter that does that. I don't know if that tells you something ...
That is not clear to me. Perhaps after I get some sleep...but I suspect what you are trying to say would still not be clear to me. Further explanation might help.
Alber
Alber on 29 Apr 2020
I think explaining it well will be much more complicated. Better if I want to do what you said before: "For example, you could say that the first climb should be the first 1/6 of the time, the hold should be the next 1/6, that the descent should be the next 2 / 6, negative hold should be the next 1/6, and rise to 0 should be the last 1/6 ", how would you do it? from there I think I can work.

Sign in to comment.

 Accepted Answer

NS = 180; %choose appropriate number of samples
N6 = NS/6;
pattern(1:N6) = linspace(0, alpha, N6);
pattern(N6+1:2*N6) = alpha;
pattern(2*N6+1:4*N6) = linspace(alpha, -alpha, 2*N6);
pattern(4*N6+1:5*N6) = -alpha;
pattern(5*N6+1:N6) = linspace(-alpha, 0, N6);
There are more efficient ways to handle this.
If this is to be part of a repeated pattern then you need to worry about where the leading and trailing 0s are coming from, and how many of those there should be.
If this is to be part of a repeated pattern, then you need to worry that the last sample does not close the pattern: for example [0 1 2 3 2 1 0] repeated is not [0 1 2 3 2 1 0 1 2 3 2 1 0], it is [0 1 2 3 2 1 0 0 1 2 3 2 1 0] because [0 1 2 3 2 1 0] closes back to the original value. Sometimes the easiest way to proceed is to compute with one more sample (the one that will return to the beginning) and then throw that away -- e.g., for NS = 180, planning for sample 181 to be the one that returns back to 0, and then throwing that away, so that 180 is the cycle width, 2 copies = 360 samples would start at 0, give the pattern twice, and end just before returning to 0.
This is important if you are going to be doing fourier transform. Do not start and end with at the same value "because it is easier", knowing that it means that you would get the repeated start value when you start making copies. That repeated start value will distort the fourier transform even though it is only a single extra sample. fft() mathematics only applies to cases where the signal is assumed to be repeated indefinitely.

More Answers (0)

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!