skip to Main Content

I have a 1D signal of length 1×48 as follows:

h = [-0.00265429202364732   0.00114381559623147 0.00908984174155875 0.0183092424104111  0.0211504546133937  0.00770487019300306 -0.0267214048940936 -0.0720838840492711 -0.0997128821116885 -0.0725675276244839 0.0291024753407948  0.179241574214812   0.298171242995671   0.284570146378536   0.0817474628244779  -0.259613052052673  -0.574126734090367  -0.656991438427717  -0.392367536944054  0.145508194624853   0.699248579096810   0.960789439152323   0.757486942825664   0.170755448210657   -0.498796897953831  -0.904761150789826  -0.856496441492131  -0.419554007897496  0.143113035135791   0.539681841427904   0.612572904069275   0.398909459502485   0.0701631492551362  -0.189524355981899  -0.282109382620421  -0.220926595018094  -0.0887181885881753 0.0277116422165095  0.0824062595946282  0.0772777428539982  0.0415608034306098  0.00566535573566328 -0.0142417524165823 -0.0174044104259903 -0.0112752491506654 -0.00370981479490947    0.00105712046376533 0.00248943884050455];

I need to somehow squeeze this signal to increase its frequency.
Thanks to “rayryeng”, please see the following plot. The green one (squeezed one) is obviously a kind of downsampled version of the blue one. Let’s say we have the blue signal saved as an image. Open that image in paint or photoshop etc. Now grab the side and squeeze it by mouse (horizontally). You can see that the nature and shape of the squeezed one is as like as the original one. I want to have that kind of squeezed signal. Here in the picture below, amplitude is changed. It shouldn’t. If you squeeze the blue one in paint or photoshop the amplitude never changes.

Thank you.

2

Answers


  1. I’m going to interpret “squeezing” as representing the signal with fewer points, but maintaining the same pitch.

    As such, you could use some sort of interpolation to do so. What you can do is specify values from 1 up to the length of your signal as control points and the values of h as the output values. Next, you can specify a reduced number of points but still maintaining a linearly increasing range from 1 up to 48 but have exactly this many points that span this range. We can use linspace to help us do this. For the interpolation, we can use interp1. Let’s choose 'spline' interpolation to have some smoothing in between each keypoint that is produced in the final result.

    In other words, try something like this:

    num_points_reduced = 20;
    h = [-0.00265429202364732   0.00114381559623147 0.00908984174155875 0.0183092424104111  0.0211504546133937  0.00770487019300306 -0.0267214048940936 -0.0720838840492711 -0.0997128821116885 -0.0725675276244839 0.0291024753407948  0.179241574214812   0.298171242995671   0.284570146378536   0.0817474628244779  -0.259613052052673  -0.574126734090367  -0.656991438427717  -0.392367536944054  0.145508194624853   0.699248579096810   0.960789439152323   0.757486942825664   0.170755448210657   -0.498796897953831  -0.904761150789826  -0.856496441492131  -0.419554007897496  0.143113035135791   0.539681841427904   0.612572904069275   0.398909459502485   0.0701631492551362  -0.189524355981899  -0.282109382620421  -0.220926595018094  -0.0887181885881753 0.0277116422165095  0.0824062595946282  0.0772777428539982  0.0415608034306098  0.00566535573566328 -0.0142417524165823 -0.0174044104259903 -0.0112752491506654 -0.00370981479490947    0.00105712046376533 0.00248943884050455];
    x = 1:numel(h);
    y = linspace(1,numel(h),num_points_reduced);
    h_reduced = interp1(x, h, y, 'spline');
    

    If we plot the original signal as well as the result, this is what it would look like:

    plot(1:numel(x), h, 1:num_points_reduced, h_reduced);
    grid;
    

    enter image description here

    Login or Signup to reply.
  2. If you squeeze the signal maintaining the sample period you lose accuracy. That’s why the amplitude changes. The squeezing works by averaging neighbouring samples. Consider for example the original peak sample. Since it is averaged with some lower-value samples, the squeezed signal has smaller peaks.

    It would be better to do the opposite, i.e “enlarge” the signal horizontally by a factor r, and consider that your new sample period is r times smaller (finer) than before. So the original signal is now sampled more finely, and the squeezed signal has the same accuracy as the original one.

    For that you can use resample:

    h2 = resample(h,5,2); %// resample factor in this example: 5/2
    plot(h, 'b');
    hold on
    plot(h2, 'r');
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search