필터 지우기
필터 지우기

how to add 2 or more different length signals?

조회 수: 4 (최근 30일)
Áron Laczkovits
Áron Laczkovits 2013년 8월 26일
I want to add 2 or more signals to play them at the same time, like a sampler. If i know well i need to convert them to the same sampling rate. How can i do that if i have a big sample library? If sample A is longer than sample B, after B finishes playing, the rest from A should continue playing till end. So it's only need a simple addition from the beginning of each other until the longest sample finishes?
Thx in advance
I tried with this source code:
clear;
clc;
myFolder = 'C:\Users\Aron\Samples\proba';
if exist(myFolder, 'dir') ~= 7
Message = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(Message));
return;
end
filePattern = fullfile(myFolder, '*.wav');
wavFiles = dir(filePattern);
sampleArray = cell(length(wavFiles),1);
Fs = zeros(size(sampleArray));
for k = 1:length(wavFiles)
baseFileName = wavFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
[sampleArray{k}, Fs(k)] = wavread(fullFileName);
end
s=1;
data_1=(sampleArray{s});
%sound(data_1);
%%
L = length(data_1);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(data_1,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure(1);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
%%
g=9;
data_2=(sampleArray{g});
L = length(data_2);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
X = fft(data_2,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
data_sum=Y+X;
data_sum_in_time = ifft(data_sum,NFFT)*L;
sound (data_sum_in_time);

답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by