필터 지우기
필터 지우기

I want to add random impulse noise to an audio signal, But the dimensions of input audio and noise audio both are different and that's why they are not getting added.

조회 수: 8 (최근 30일)
I am doing a project to remove impulse noise from audio sample using median filter. For this first I have to add the impulse noise to the signal and to do that I am using rand() to genrate random impulses of random amplitude and then trying to add them to the orignal signal but while adding I am getting error that
"
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in class_03 (line 25)
noise_y2 = [y, y_2];
"
clc;
clear;
close all;
[y, Fs] = audioread("teste_01.wav");
t = y(500:200000); % taking smalle sample from 'y' to add noise
N = round(length(t));
%%
y_2 = 0.25.*randn(1, N); % creating random noise
% trying to make array 'y_2' of same dimension as of y
y_dim = size(N);
scaled_data_dim = size(y_2);
if y_dim(1) < scaled_data_dim(1)
y_2 = repmat(y_2, y_dim(1), 1);
end
if y_dim(1) > scaled_data_dim(1)
noisy_padding = [y, zeros(1, scaled_data_dim(1) - y_dim(1) )];
y_2 = [y_2 ; noisy_padding];
end
%%
% adding both orignal and impulse noise array
noise_y2 = [y, y_2];
figure
subplot(2, 1, 1)
plot(y)
title('Orignal audio signal')
subplot(2, 1, 2)
plot(noise_y2)
title('audio with impulse noise')

채택된 답변

Walter Roberson
Walter Roberson 2023년 11월 23일
[y, Fs] = audioread("teste_01.wav");
That will return a 2D array, with the columns being channels (one channel would still be a column array.)
t = y(500:200000); % taking smalle sample from 'y' to add noise
N = round(length(t));
If y was a column array (one channel) then t will end up being a column array, but if y had multiple columns (multiple channels) then t will end up being a row vector. (Using one index parameter on a vector gives a result that is a vector the same orientation as the original vector, but using one index parameter on something that is not a vector gives a result that is the same shape as the index.)
Note that if the file has multiple channels but fewer than 200000 rows then you are using linear indexing on it and would in that case be extracting information from multiple columns. If you want to extract 200000 samples per channel, use two indexing parameters, y(500:200000,:) .
N is going to be 200000 - 500 + 1 = 199501
y_2 = 0.25.*randn(1, N); % creating random noise
That is a row vector. Remember that t will be a column vector if y has one channel but a row vector if y has multiple channels.
y_dim = size(N);
N was calculated using length(t) which is always going to return a scalar integer. round() of the scalar integer leaves it as a scalar integer. size() of the scalar integer is going to be 1 x 1
The rest of the code is suspect because it is based upon the size of the scalar, rather than the size of y or t.
  댓글 수: 1
khan hanzala
khan hanzala 2023년 11월 24일
I used randi() to creat a random 2D vecoter. Now trying to reduce to density of the noise.
Thanks a lot for yout advice.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Transmitters and Receivers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by