MATLAB Answers

Finding different length pulses

3 views (last 30 days)
David Jones
David Jones on 18 Sep 2020
Commented: Star Strider on 21 Sep 2020
I have attached a screen shot of some pulses with diiferent lenghts my question is what is the best way clean these up and show them.
Thank You


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 Sep 2020
Note that ‘clean them up’ is ever so slightly ambiguous.
Assuming that the objective is to remove some of what might be considered ‘noise’, first calculate the Fourier transform of the signal, then using that information to determine where the ‘noise’ frequencies begin, design a lowpass filter to remove the undesirable higher frequencies. (For all of these, the sam;ing intervals must be constant. If it is not, use the resample function to interpolate them to a constant sampling frequency first.)
The Fourier transform is straightforward (assuming ‘x’ is the signal vector):
Fs = ... ; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
L = numel(x); % ‘x’ Is A Vector
xm = mean(x);
xfft = fft(x - xm)/L; % Subtract Mean & Normalise By ‘L’
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
plot(Fv, abs(xfft(Iv))*2)
xlabel('Frequency (Hz)')
With that information, use the lowpass function to design the filter, or use command-line arguments in a script to design your own filter. This is straightforward with the Signal Propcessing Toolbox functions.


Show 1 older comment
Star Strider
Star Strider on 18 Sep 2020
My pleasure!
I am not certain that I understand what you want to do.
If you want to convert all the pulses to square waves, and if ‘x’ is your vector, simply do:
sqwvx = sign(x);
All the positive values will be +1, all the negative values will be -1 and any 0 values remain 0.
Example —
t = linspace(0, 61, 100);
x = randn(1, 100);
sqwvx = sign(x);
plot(t, x)
hold on
plot(t, sqwvx, 'LineWidth',1.25)
hold off
David Jones
David Jones on 20 Sep 2020
As always great Job, I am new to Matlab and in the previous message you mentioned resample I had a look at this but dont understand I have 16000 samples sample rate 5mS can you please explain in a little more detail
Thank you for all your help
Star Strider
Star Strider on 20 Sep 2020
My pleasure!
Thank you.
Essentially all digital signal processing requires that the signals be regularly sampled (constant sampling intervals). If your signal already has a uniform sampling rate (all sampling intervals are the same), then you do not need to use the resample funciton. If they are not, there is no guarantee that the results of any signal processing action will be in any way correct.
The resample function interpolates signals with varying sample times to signals with constant sampling times, allowing normal signal processing procedures to be applied to the resampled signals. (It actually does more than interpolate, since it also uses an anti-aliasing filter to remove spurious signals that might result from the resampling process, the resason that it is superior to interp1 for signal processing purposes.)

Sign in to comment.

More Answers (1)

David Jones
David Jones on 21 Sep 2020
Thank you

  1 Comment

Star Strider
Star Strider on 21 Sep 2020
As always, my pleasure!

Sign in to comment.





Community Treasure Hunt

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

Start Hunting!