Keep getting error using sound command

조회 수: 12 (최근 30일)
Joseph Guzzo
Joseph Guzzo 2022년 4월 30일
답변: Walter Roberson 2022년 4월 30일
Error message: Error using sound (line 76) Only one- and two-channel audio supported.
Code:
clear; clc; close all;
fs = 44100;
% [h, n] = bpw(lower_cutoff, upper_cutoff, 501, 'type');
% Num 2
[h1, n1] = bpw(0, .627, 501, 'hamm');
[h2, n2] = bpw(.627, 1.25, 501, 'hann');
[h31, n31] = bpw(1.25, 1.88, 501, 'blac');
[h32, n32] = bpw(1.25, 1.88, 501, 'rect');
[h4, n4] = bpw(1.88, 2.51, 501, 'bart');
[h5, n5] = bpw(2.51, pi, 501, 'hann');
Av1 = 1;
Av2 = 1;
Av3 = 1;
Av4 = 1;
Av5 = 1;
im1 = h1 * Av1;
im2 = h2 * Av2;
im31 = h31 * Av3;
im32 = h32 * Av3;
im4 = h4 * Av4;
im5 = h5 * Av5;
TIR = im1 + im2 + im31 + im4 + im5;
% Num 3
audio = audioread("Undone_Clip.wav");
finalSound = conv2(audio, TIR);
sound(finalSound, fs);
  댓글 수: 4
Star Strider
Star Strider 2022년 4월 30일
What’s ‘bpw’?
It’s not in the online documentation (R2022a).
.
Joseph Guzzo
Joseph Guzzo 2022년 4월 30일
편집: Walter Roberson 2022년 4월 30일
It's a separate windowing function:
function [h,n] = bpw(wl, wu, len, win);
if mod(len,2) == 0
len = len + 1;
end
M = len-1;
n = [-M/2:M/2];
n2 = n+M/2;
h = (wu/pi)*sinc((wu*n)/pi) - (wl/pi)*sinc((wl*n)/pi);
if win == 'bart'
wn = 0.54 - 0.46*cos((2*pi*n2)/M);
elseif win == 'blac'
wn = 0.42 - 0.5*cos(2*pi*n2/M) + 0.08*cos(4*pi*n2/M);
elseif win == 'hamm'
wn = 0.54 - 0.46*cos((2*pi*n2)/M);
elseif win == 'hann'
wn = 0.5 - 0.5*cos((2*pi*n2)/M);
elseif win == 'rect'
wn = 0*n2+1;
else
disp('Not a valid window type! ==> Rect Window Used.');
wn = 0*n2+1;
end
h = h.*wn;
n = n2;

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

답변 (2개)

Image Analyst
Image Analyst 2022년 4월 30일
You sound doesn't have any signal in it. Here's an example:
[y, fs] = audioread('guitartune.wav');
size(y)
ans = 1×2
661500 1
You say your y "finalsound" "is a 1x2 that has values [537146, 502]"
That means you have 537,146 samples but 502 channels. the soundsc can only take 1 or 2 channels. Can you just play 2 of the channels?
stereoSound = finalSound(:, 1:2); % Extract first two channels and ignore remaining 499 channels.
soundsc(stereoSound);

Walter Roberson
Walter Roberson 2022년 4월 30일
audioread() returns something that has one row per sample, and as many columns as there are channels.
n = [-M/2:M/2];
That is a row vector, so your bpw() function returns a row vector.
finalSound = conv2(audio, TIR);
You are conv2() your N x channels with a row vector and you are not using any parameters to clip the size of the output of conv2() . When you do not use options such as 'same' or 'valid', conv2 is going to return a large output. conv2() is symmetric mathematically, so do not just think about convolving the audio with the TIR: you are also convolving the TIR with the audio, so you should expect something about the same width as the TIR as the output width.
You should probably be using conv() of the audio and a column vector TIR and should probably be using the 'same' option

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by