필터 지우기
필터 지우기

edit .mat values to match

조회 수: 1 (최근 30일)
Tatiana
Tatiana 2023년 11월 21일
답변: Image Analyst 2023년 11월 22일
I currently have this code below:
clc
clear
clear all
[data,fs]=audioread('pracsound.mp3');
save new_file data fs
new_file = new_file';
% Load sample sound
load new_file.mat;
% Play sample sound
sound(data, fs);
% Wait 5 seconds
pause(5)
% Call the function to add echo
y_echo = echo_gen(data, fs, 0.5, 0.75);
% Play echo sound
sound(y_echo, fs);
function output=echo_gen(input, fs, delay, amp)
% Preallocate new vector
output=zeros((numel(input)+delay*fs),1);
% Add zeros to input to get both vectors same length
input = [input; zeros(delay*fs,1)];
% No change during the delay time
output(1:delay*fs) = input(1:delay*fs);
% Add Echo to the remaining part
output(delay*fs+1:end)= input(1:end-delay*fs)*amp + input(delay*fs+1:end);
% Normalize between -1 and 1
output = rescale(output,-1,1);
end
It is supposed to load an .mat audio file play the original, add an echo using a function then play it again.
My problem is the .mat file I want to use appears like this once loaded in:
And I need it to look like this .mat file (A sample that works with my given code found online).
How do I get the data value for new_file to be 246000x1 double like the TestSoundEcho.mat file instead of 246000x2?

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2023년 11월 21일
According to "doc audioread",
Audio data in the file, returned as an m-by-n matrix, where m is the number of audio samples read and n is the number of audio channels in the file.
So it was dependent on the contents of the .mp3 file.
You could to this after audioread() to select only one channel
[data,fs]=audioread('pracsound.mp3');
data=data(:,1);
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 11월 21일
Some people prefer
data = mean(data,2);
to merge all of the channels into a single channel.
For example especially in the 1960's, it was very common in pop and rock music to have one channel (ear) be the vocals, and the other channel (ear) be the music; if you were to just extract one channel from such a recording you would get only the music or only the vocals.

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


Image Analyst
Image Analyst 2023년 11월 22일
You could try interp1 or imresize to resize the stereo audio signal to be as if it had the number of samples it would have had if it were sampled at 44100 Hz. Attach your audio signal in a .mat file or your mp3 file in a .zip file if you need more help.

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by