can't solve matrix dimensions error with noise signal

1 Ansicht (letzte 30 Tage)
rivaldo rivaldo
rivaldo rivaldo am 6 Jun. 2017
Kommentiert: Star Strider am 6 Jun. 2017
I'm trying to add uniformal distributed noise to a speech signal and just dont know how to solve this error
Error using +
Matrix dimensions must agree.
x-the speech signal
nos-the noise signal
clear all;close all;clc
[x,Fs,Nbits] = wavread('jennifer.wav');
t = 0:0.001:512;
f = 45:55;
nos = sum(sin(2*pi*f'*t));
figure(1)
plot(t, nos)
grid
axis([0 2 -4 4]);
y=x+nos;

Antworten (1)

Walter Roberson
Walter Roberson am 6 Jun. 2017
Your t is size 512001 -- remember that when you have 0:N that the length of that is N+1
Your f is size 11, but you sum along the dimension implied by f, so your nos comes out 1 x 512001 -- a row vector.
Your x is going to be a column vector.
In R2016a and earlier, if you attempt to add a column vector and a row vector, that would be an error. In R2016b and later, the effect would be the same as
bsxfun(@plus, x, nos)
which would return a length(x) by 512001 array; it seems unlikely that is what you want.
I would suggest
t = (0 : length(x)-1) / Fs;
f = 45:55;
nos = sum(sin(2*pi*f'*t));
y = x + nos(:);

Kategorien

Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by