필터 지우기
필터 지우기

how can i summarize 2 different signals?

조회 수: 3 (최근 30일)
Áron Laczkovits
Áron Laczkovits 2013년 8월 14일
Hi all!
I just want to play 2 or more different signals at the same time. If i know well for this, i need to summarize the signals, and the just play back it, but the matrix dimensions musn't agree. Can anyone help me to solve the problem?
Thanks in advance
I tried it 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);
  댓글 수: 7
Walter Roberson
Walter Roberson 2013년 8월 21일
If sample A is longer than sample B, then after B finishes playing, should the rest of A play by itself, or should one go back to the beginning of B and keep going from there until the end of A ?
Are the samples always taken at the same sampling rate, or does there need to be conversion ?
Áron Laczkovits
Áron Laczkovits 2013년 8월 21일
편집: Walter Roberson 2013년 8월 21일
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? (not sure that all sample has the same sample rate, it's a bit complicate the task)
Maybe I need a conversation that convert all sample to the same sample rate. i don't know what should i do if i have a sound library with different length sound signals and doesn't known the sampling rate between the signals and i would like to play them even if more than two.

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

답변 (2개)

Iain
Iain 2013년 8월 21일
Signal A: 10,000 samples, sampled at 20KHz Signal B: 5,000 samples, sampled at 20KHz
A(samples_offset+(1:5000)) = A(samples_offset+(1:5000)) + B; %set the offset to play signal B starting at the same time, ending at the same time, or somethign in the middle.
Signal A: 10,000 samples, sampled at 20KHz Signal B: 5,000 samples, sampled at 10KHz
Here you need to resample B. You can do it via interpolation. - Something like:
C(1:2:9999) = B;
C(2:2:9998) = B(1:end-1) + B(2:end) ./ 2
C(10000) = B(end);
  댓글 수: 2
Áron Laczkovits
Áron Laczkovits 2013년 8월 26일
And what if i have a sample library with different samples (and i dont know the sampling rate) and i want to add them, because i would like to play for example 2 or 3 samples at the same time, like a sampler. I need a conversation for all? or what?
Thx in advance
dpb
dpb 2013년 8월 26일
How can you do anything w/ them if the sampling rate isn't known (or at least embedded in the storage format)?
The answer to the question is as given earlier; you have to resample one or both to a common time base in some fashion of your choosing. If you don't want to use the Signal Processing Toolbox resample function, then roll your own...

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


Walter Roberson
Walter Roberson 2013년 8월 26일
Respampled = ifft( fft(SampleWithLowerFrequency), ceil(length(SampleWithLowerFrequency) * HigherFrequency / LowerFrequency ) )
now play SampleWithHigherFrequency and Resampled together, both at HigherFrequency
  댓글 수: 11
Áron Laczkovits
Áron Laczkovits 2013년 9월 2일
@dpl
Why minLeng=min(length(sampleArray{k})) doesn't return the shortest sample?
It's not the shortest one as i see and hear...
The two sample's length values are: l1: 176400 and L2: 17656
And minLeng value is: 19962
Walter Roberson
Walter Roberson 2013년 9월 2일
min( cellfun(@length, SampleArray) )

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by