how to zero pad a vector to have the same amount of data as a vector with more data?

17 次查看(过去 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))];

回答(3 个)

Stephen23
Stephen23 2023-11-13
Simpler:
in(end+1:numel(verb)) = 0;

Paul
Paul 2023-11-13
As of R2023b: paddata
in_padded = paddata(in,numel(verb));

Les Beckham
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 CenterFile Exchange 中查找有关 Modulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by