Matrix dimensions error for adding noise vectors

1 view (last 30 days)
I've got some code for my adding my noise vectors to my pwelch command, but my matrix dimensions ar not agreeing in my new_sound_array variable. I cannot change the frequencies or amplitudes of x1 and x2, as those need to stay the same. Can someone help me with this?
clc;
close all;
clear all;
[y,Fs]=audioread('doorbell.wav');%reading audio file
y=y';
y_spectrum=pwelch(y);
sound(y_spectrum);%playing the spectrum using sound function
%% creating noise vectors
t=0:1/Fs:1;
t1=t(1,1:5189);
f1=4000;
a1=0.2;
x1=a1*sin(2*pi*f1*t1);
f2=5000;
a2=0.25;
x2=a2*sin(2*pi*f2*t1);
%% adding noise vectors to sound array
new_sound_array=y+x1+x1;
sound(new_sound_array,Fs);
new_sound_array_spectrum=pwelch(new_sound_array);
sound(new_sound_array_spectrum);
%%convolution of H array with new_sound_array
H=[0.0065 0.0103 0.0210 0.0382 0.0599 0.089 0.1032 0.1171 0.1221 0.1171 0.1032 0.0829 0.0599 0.0382 0.0210 0.0103 0.0065];
Final_new_array=conv(new_sound_array,H);
Final_new_array_spectrum=pwelch(Final_new_array);
sound(Final_new_array_spectrum);

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 29 Sep 2019
Edited: KALYAN ACHARJYA on 29 Sep 2019
The issue is here, you are trying to add different sizes matrices in the following line-
new_sound_array=y+x1+x1;
Where
>> whos x1
Name Size Bytes Class Attributes
x1 1x5189 41512 double
>> whos y
Name Size Bytes Class Attributes
y 1x33292 266336 double
Please ensure that the matrices sizes must be same before adding to each other, whether it may be noise or signal, it doesnot matter. We have to followed basic Maths.
One way out: To avoid Matrix dimensions error
[y,Fs]=audioread('doorbell.wav');%reading audio file
y=y';
%% creating noise vectors
t=0:1/Fs:1;
data=length(y);
Choose the t in such a way that it length and y length (data) must be same.
Good Luck!

More Answers (0)

Categories

Find more on Get Started with Signal Processing Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!