Abhinav Aggarwal
Abhinav Aggarwal

Reputation: 1363

High error due to resample function in MATLAB

I am working on training the output of the wavelet transform of a signal using a neural network in MATLAB. So I decided to use 3 layer db4 wave filter for its wavelet transform. I have used an array of 240 elements and after wavelet transform, I get an array l

l = [36;36;65;123;240]

Now, since I have to train my neural network, I have to resample the wavelet transforms of length 36, 36, 65, 123 to an array of 240 elements.

So what I did was, I did wavelet transform of the signal. I resampled each wavelet transform to 240 points, and then resampled the wavelet to 36, 36, 65, 123 points respectively. I got an error of 20.2668. What can be done to reduce error?

I used the following command to resample using MATLAB:

[c1, l] = wavedec(signal, 3, 'db4');

c1a = c1(1:l(1));
c1a = resample(c1a, length(signal), length(c1a));

c1b = c1(1+l(1):l(1)+l(2));
c1b = resample(c1b, length(signal), length(c1b));

c1c = c1(1+l(1)+l(2):l(1)+l(2)+l(3));
c1c = resample(c1c, length(signal), length(c1c));

c1d = c1(1+l(1)+l(2)+l(3):l(1)+l(2)+l(3)+l(4));
c1d = resample(c1d, length(signal), length(c1d));

c2a = resample(c1a, l(1), length(c1a));
c2b = resample(c1b, l(2), length(c1b));
c2c = resample(c1c, l(3), length(c1c));
c2d = resample(c1d, l(4), length(c1d));

X = waverec([c2a; c2b; c2c; c2d], l, 'db4');
err = norm(X-signal)

Now, the error err is reported as

err = 20.26688

What can I do to reduce this error? Please help :)

The data plot for wavelet transform after both resampling and original is: Image showing both the original and resampled signals

Upvotes: 2

Views: 487

Answers (1)

Rash
Rash

Reputation: 4336

If you want to resample all wavelet coefficients to your signal length, 240, and then use them as features for a classification, as far as I know, that is wrong because wavelet coefficients are like frequency components and you can't assign them to time domain samples.

What I suggest is to reconstruct your signal with different combinations of wavelet coefficients, so you would have a signal in time domain, then you could use it as feature.

I provided an example,

X = sin(rand(1,240)).*sin(5*linspace(0,2*pi,240));
subplot(5,1,1)
plot (X); title ('Original Signal');
[C, L] = wavedec(X, 3, 'db4');
C1 = C; C2 = C; C3 = C; C4 = C;
C1(L(1)+1:end) = 0;
X1 = waverec(C1, L, 'db4');
subplot(5,1,2)
plot(X1);title ('A3');
C2(1:L(1)) = 0;
C2(L(1)+L(2)+1:end) = 0;
X2 = waverec(C2, L, 'db4');
subplot(5,1,3)
plot(X2); title ('D3');
C3(1:L(1)+L(2)) = 0;
C3(L(1)+L(2)+L(3)+1:end) = 0;
X3 = waverec(C3, L, 'db4');
subplot(5,1,4)
plot(X3); title ('D2');
C4(1:L(1)+L(2)+L(3)) = 0;
C4(L(1)+L(2)+L(3)+L(4)+1:end) = 0;
X4 = waverec(C4, L, 'db4');
subplot(5,1,5)
plot(X4); title ('D1');

Gives 4 signals all with length 240 which can be used as features.

enter image description here

Upvotes: 2

Related Questions