how do I re-sample a continuous function; but maintain shape?
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
Just curious what the relative percent error is? abs(width50 - width200)/width200 * 100
Note that the filtering within the resample function assumes that the signal is zero at the beginning at end points. It would help with your issue of edge effects if you subtracted out the mean before resampling and then added it back later.
Eric Kuebler
on 5 Nov 2019
Wow. That's a large number. Are you sure the second version is capturing the correct half width? The figures themselves don't even look visually different. Guessing visually I would have said 1-2% difference.
How are you calculating half width?
Also note that in general when downsampling a signal, there is a loss of what is called the Q-factor of a sharp signal. (That is, a peak will get smaller in magnitude and broader in width).
Eric Kuebler
on 5 Nov 2019
Edited: Eric Kuebler
on 5 Nov 2019
Eric Kuebler
on 5 Nov 2019
Accepted Answer
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.
1 Comment
Eric Kuebler
on 6 Nov 2019
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!