how do I re-sample a continuous function; but maintain shape?
10 views (last 30 days)
Show older comments
I am trying to resample a vector that represents a voltage time-series from 200kHz to 50 kHz using the resample function (the two vectors are shown below).
The code I've used to resample is as follows:
x = resample(x,5e4,20e4);
When I measure what we call the 'half width' (the duration of time at half the height of the voltage peak) I notice that there is an increase, essentially the half width becomes longer. The increase also varies between waveforms.
I am curious if there is anyway to reduce this discrepancy, or at least perhaps have it consistent and based on the slower sampling rate? I've tried using filter coefficients that mimick the shape of these waveforms; but that seemed to make things worse.
Thank you in advance!
Eric
5 Comments
Accepted Answer
Daniel M
on 5 Nov 2019
Edited: Daniel M
on 5 Nov 2019
I see several potential reasons why this is occuring.
1) There will be general broadening of the signal due to downsampling.
2) Since the magnitude of the downsampled signal is potentially lower, then half of the max could also be lower. So you could be measuring a wider part of the signal.
3) You're measuring half-width from the left side. This combined with issue 2 could lead to measuring something like the blue line in "Capture" (attachment). I would have defined the half-width as something more like the red line, which is the HWHM from the left side.
4) You're using discrete values to calculate width. Probably not an issue because the sampling rates are still quite high, but could lead to something occuring like in "Capture2" attachment. If you find this is a big issue, then you could interpolate between the first point <halfHeight and first point >halfHeight.
I'm not really sure what to suggest other than to try using the functions pulsewidth and/or statelevels in the signal processing toolbox.
More Answers (1)
Daniel M
on 6 Nov 2019
You can unaccept the answer if you want to keep it open, but also consider this answer.
(For 3, I meant you're measuring from right side, and could try from left. I think you understood what I meant).
Here are some ideas. I'm not saying they are robust, but this is certainly a potential direction to go in.
% create sample data
fs = 4e6;
t = (0:99).*1/fs;
y = [ones(1,45) 1+sin(2*pi*320000*t(1:10)) zeros(1,45)+2e4.*t(1:45) ] + 0.1.*rand(1,length(t));
% that looks ridiculous I know..., but it isn't a bad approximation to your signal
% get the statelevels
levs = statelevels(y);
% if you call it without the output, it will display the attached figure "levels"
% get the overshoot value, need to flip y
% I'm sure using max or findpeaks is sufficient here too.
% I'm just showing you the utility of these functions
[os,oslev,osinst] = overshoot(fliplr(y),t,'StateLevels',levs);
% if you plot without outputs, get attached figure "overshoot"
% we care about 'upper state' and 'post-overshoot'
% get the pulse width, the crossings, and the midlevel
[width,init,fin,midl] = pulsewidth(y,t,'StateLevels',[levs(2) oslev]);
% width = fin-init
% see attached figure "pulsewidth"
As you can see, these functions can be pretty useful! I believe these functions have the ability to work on trains of pulses too, so you don't even need to epoch your data.
If nothing in here quite works for you, then I am curious what the application of your problem is for. Maybe there is another way to circumvent the issue.
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!