MATLAB Answers

## making different signals equal in length

Asked by Lisa Justin

### Lisa Justin (view profile)

on 3 Dec 2012
Latest activity Commented on by chaitanya

### chaitanya (view profile)

on 27 Feb 2016
Accepted Answer by Jan Simon

### Jan Simon (view profile)

Hi, I am working with a set of data and i need all of them to be the same length. how can i do this?

## Products

No products are associated with this question.

## 3 Answers

### Jan Simon (view profile)

Answer by Jan Simon

### Jan Simon (view profile)

on 3 Dec 2012
Accepted answer

It depends. As said already you can crop the longer ones, pad the shorter ones or apply an interpolation. For the latter there are linear, cubic, spline, bsline, trigonometric and more complicated interpolation methods.

aliya

### aliya (view profile)

on 1 Jun 2015

What if we have multiple signals from a database of different sizes. how to make their length equal?

Walter Roberson

### Walter Roberson (view profile)

on 1 Jun 2015

Find the maximum of their lengths, say maxlen. Then for each,

```ifft(fft(TheSignal),maxlen)
```

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 3 Dec 2012

```S1 = size(FirstMatrix);
S2 = size(SecondMatrix);
MaxS = max(S1, S2);
```
```if MaxS(1) > S1(1); FirstMatrix(end+1:MaxS(1), :) = 0; end
if MaxS(2) > S1(2); FirstMatrix(:, end+1:MaxS(2)) = 0; end
```
```if MaxS(1) > S2(1); SecondMatrix(end+1:MaxS(1), :) = 0; end
if MaxS(2) > S2(2); SecondMatrix(:, end+1:MaxS(2)) = 0; end
```

You can simplify this a bit if you are using vectors and you know the orientation of the vectors.

Walter Roberson

### Walter Roberson (view profile)

on 3 Dec 2012

Ah... did you want to do this by clipping the longer ones to the length of the shorter?

Lisa Justin

### Lisa Justin (view profile)

on 3 Dec 2012

yes exactly. But then i lose some relevant part of the signal which is not good either. I am a bit unsure how best to make all the length equal. they are about 600 files

chaitanya

### chaitanya (view profile)

on 27 Feb 2016

thanks..it is useful

### Muruganandham Subramanian (view profile)

Answer by Muruganandham Subramanian

### Muruganandham Subramanian (view profile)

on 3 Dec 2012

Can you provide the data? you can do it by adding zeros, ones, any desirable data to the data having minimum sizes from data having maximum sizes by initializing max. data length caustiously..

#### Join the 15-year community celebration.

Play games and win prizes!

Learn more

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!