can't solve matrix dimensions error with noise signal
1 view (last 30 days)
Show older comments
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;
Answers (1)
Walter Roberson
on 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(:);
See Also
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!