Resampling data without altering the frequency of the data

Dear matlab forum,
For my research I have to normalise EMG data for different subjects, so they all have the same amount of samples.
Now, via your forum someone recommend me to use 'interp1' and 'pchip'.
I tested this on a sinusoid with 1000 samples, that runs exactly 1 second.
When I plot this sinusoid, with % reduction in samples, I see that the frequency is affected (see picture).
I'm afraid that this also happens in my EMG data when I resample using this method. Since the end result of the research
is to assess the complexity of EMG signals, I want to preserve as much of the frequency content as possible, but I have to 'resample' to normalise
the amount of samples between subjects, since it is shown that a difference in samples causes different complexity outcomes.
What method could you recommend me to use to resample my data?
Hope to hear,
Jeroen

 Accepted Answer

The problem with the procedure you describe is that the requirements appear to be incompatible. Ideally, all the records will have the same sampling frequency.
I would use the Signal Ptocessing Toolbox resample function to resample them to the same sanpling frequency, then truncate all of them to the length of ths shortest record. Exactly how you do that is your choice.

10 Comments

The thing is, the signals already have the same sample frequency of fs=1000 Hz. But of course the EMG signals vary in shape between subjects. I only want to reduce the amount of samples while preserving the vertical and horizontal shape of the signal as much as possible, which is why I came to 'spline'. Do you expect 'resample' to work differently than 'interp1' in my scenario, since they both use 'spline' 'linear' etc. I thought it would have the same results in this case? Thanks for your help Star.
My pleasure!
The resample function is preferable to interp1 for signal processing, since it uses an anti-aliasing filter. I would not resample the signals to have a constant number of samples, since that leads to very difficcult code. Just leave them as they are, and shorten all of them to the shortest record, if the objective is to have all of them the same size. If you want to compare them, the best option might be to do that in the frequency domain, either using fft or spectrogram. It mighty be possible to normalise those to some extent so you can compare them, although you would need to do that experiment. For example, it would be possible to normalise the fft results of all of them by using the same size (length) fft for all of them, since they are all sampled at the same sampling frequency. Specify that with the second argument to fft.
I shall explain my problem in better detail. With 'Sample Entropy' I calculate the variability of EMG signals (for my master research). In that algorithm is shown that the amount of samples to describe the signal affects the entropy (variability) outcomes. So, all participants >must< be normalised to the amount of samples. While doing this, I want to keep the signals as close to the originals as possible. 'pchip' and interp1 didn't do a bad job at all.. but I wanted to check if I used the 'best' method, since, I just concluded that for a sinusoid (attachment) the horizontal output of the signal was slightly altered... overall the curves of the 'pchipped' signals were still quite ok. I'm weighing my options, hence why I came to you!
The method you describe, just trunctating the signals will not work. For every subject I need to describe a fixed amount of full gait phases, and these phases differ in nr. of samples between the subjects. Maybe you can adjust your answer better when you know this!
I have no idea what you are doing, so I am essentially guessing as to what your data represent.
If your subjects have different stride lengths and stride times, there may not be anything you can do with respect to the original signals to normalise them without either adding spurious data or deleting available data. That is the reason I suggest normalising them in the frequency domain. Since they all have the same sampling frequencies, and it would be expected that the gait frequencies would differ, that would be evident on the fft results. The fft results could be normalised to be the same length and so having the same frequency content and resolution, with spectral characteristics specific to each subject. Then analyse the spectral data.
Thanks for the tip, I may look into this when my other methods fail. Thanks for helping star. Maybe I will come back to you when I have more information available.. !
Hey star, I had one follow up question for you.
When I follow the matlab documentation of fft I would convert and plot the time signal of EMG 'y_o' as in %1.
Now, previously I used method %2, but it looks like I end up with different results. I think it has something to do with 'nextpow2' not being used. Is method %2 still valid or would you recommend %1? Just wanted to hear your view on this. This was my last question :) - thank you.
% 1
figure(1)
fs=1000;
T=1/fs;
L=length(y_o);
NFFT= 2^nextpow2(L);
Y=fft(y_o,NFFT)/L;
f=(fs/2)*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
% 2
figure(2)
fs=1000; %samplefreq
L=length(y_o); %length
y_of = fft(y_o); %transform of EMG signal
P2 = abs(y_of/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L; %fs/2 = Nyquist frequency
plot(f,P1)
title('Frequency Spectrum Plot')
xlabel('f (Hz)')
ylabel('|P1(f)|')
This is correct:
P1(2:end-1) = 2*P1(2:end-1);
The reason to multiply it by 2 has to do with the fft function creating a ‘two-sided’ Fourier transform (most easily seen after using fftshift and plotting against an appropriate frequency vector that goes from the negative Nyquist frequency to the positive Nyquist frequency), dividing the energy equally between the two halves (those being the complex conjugates of each other). The actual amplitude as the result in eacch half of the fft result is half the original signal amplitude, so multiplying it by 2 reproduces (approximately) the original signal amplitude in the fft result in the one-sided plot.
I started to worry since you can see a slight difference in signals (see attachment in previous comment), when you compare the one sided plots of %1 and %2. I didn't see where this difference was coming from. Anyway, I'm glad I'm on the right track and thanks for taking the time to reply once more. Greatly appreciated Star :)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!