how to zero pad a vector to have the same amount of data as a vector with more data?
29 次查看(过去 30 天)
显示 更早的评论
I have read multiple other threads with questions similar to this, however none of these were able to work in my case.
quick description: i have two audio signals. the "verb" signal is longer than the "in" signal. I want to change the "in" signal to have the same amount of data (i.e, the length of verb = length of in), using zero padding.
Can someone please walk me through how to achieve this? I have tried many things. Here is the code that reads the inputs as well as my best attempt to zero pad the "in" signal.
thank you for your help
%%% goal: to have the length of 'in' equal the length of 'verb'
%%% define inputs
[in, fs] = audioread('smash_hit.wav'); % input signal defined
in = in(:,1); % converts signal to mono, if needed
[verb, ~] = audioread('warehouse.wav'); % reverb response signal defined
verb = verb(:,1); % converts signal to mono, if needed
in_padded = [in, zeros(1, length(verb))];
0 个评论
回答(3 个)
Les Beckham
2023-11-13
Try this:
%%% goal: to have the length of 'in' equal the length of 'verb'
%%% define inputs
[in, fs] = audioread('smash_hit.wav'); % input signal defined
in = in(:,1); % converts signal to mono, if needed
[verb, ~] = audioread('warehouse.wav'); % reverb response signal defined
verb = verb(:,1); % converts signal to mono, if needed
% in_padded = [in, zeros(1, length(verb))];
in_padded = [in, zeros(1, length(verb) - length(in))]; % <<< corrected this line
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!