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

29 vues (au cours des 30 derniers jours)
Will Banks
Will Banks le 13 Nov 2023
Commenté : Will Banks le 14 Nov 2023
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))];

Réponses (3)

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

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

Les Beckham
Les Beckham le 13 Nov 2023
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

Catégories

En savoir plus sur Measurements and Spatial Audio dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by