Finding frequency, amplitude and duration and direction of the sound
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everybody, I have a problem with this following code:
In this code, I generated 45 sounds (with especific frequency, Amplitud, duration) and after that I represent them to left and right ear randomly.
but at the end, I want to know what is the frequency, amplitude and duration and direction of the sound (memory{1,r2(ci)}) that is sent randomly in the ear (in the fifth loop)
(find value of its own amplitud and duration and frequency and direction for each sound and put them in a cell.(my cell should have 45*4 (amplitud and duration and frequency and direction= total 4) )
but I can not make it in my cell (my cell is OUT in line 44 )
PLEASE IF YOU KNOW IT, HELP ME (thanks in advance)
clc;
clear;
close all;
SamplingRate_Hz=48000;
F=[250 500 1000 2000 4000];
A=[5 10 15]/15;
T=[1 2 3];
ind = 0;
memory{1,1}{1,1}{1,1}={0};
Memory{1,1}{1,1}{1,1}={0};
for i=1:length(F)
for j=1:length(T)
for k=1:length(A)
ind = ind + 1;
Frequency_Hz = F(i);
time_p = T(j);
Amplitude = A(k);
t=0:(1/SamplingRate_Hz):(time_p-1/Frequency_Hz);
y=Amplitude*sin(2*pi*Frequency_Hz*t);
xt_ramped = toneburst(SamplingRate_Hz,y);
Memory{1,i}{1,j}{1,k} = xt_ramped';
memory{1,ind} = xt_ramped';
end
end
end
L = numel(memory);
thisdir{1,1}={0};
for h=1: L
direction = {'L', 'R'};
r1 = randi([1, 2], 1); % Get a 1 or 2 randomly.
thisdir{1,h} = direction(r1);
end
r2= randperm(L); % create 45 random values
out_all=[];
ind=0;
OUT=[];
for ci = 1:L
ind = ind + 1;
y=zeros(length(memory{1,r2(ci)}),2);
if strcmpi(thisdir{1,ind},'L')
y(1:length(memory{1,r2(ci)}),1)=memory{1,r2(ci)};
else
y(1:length(memory{1,r2(ci)}),2)=memory{1,r2(ci)};
end
%%% Here I have a Problem and I want to know and find what is the frequency, amplitude and duration and direction of the sound (memory{1,r2(ci)}) that is sent randomly in the ear
% and put them in OUT (my cell is OUT and it should have 45*4 )
X=find(strcmpi(memory{1,r2(ci)}, Memory{1,i}{1,j}{1,k}));
OUT= {F(i),T(j),A(k),thisdir{1,ind}}; %% put frequency, amplitude and duration and direction in OUT
% if strcmpi(memory{1,r2(ci)},Memory)
% OUT= {F(i),T(j),A(k),thisdir{1,ind}};
% else
% disp('Error')
% end
% sound(y,SamplingRate_Hz) ;
% pause(5)
out_all = [out_all; y];
end
audiowrite('test.wav',out_all,SamplingRate_Hz);
%% here is my function(toneburst)
function xt_ramped = toneburst(SamplingRate_Hz,y)
xt =y;
fs=SamplingRate_Hz;
ramp_dur=0.0025; %ramp duration in seconds
%setup ramp
rampSamps = floor(fs*ramp_dur);
window=hanning(2*rampSamps)'; %hanning window is cosine^2 this will change depending on the kind of ramp you want
w1=window(1:ceil((length(window))/2)); %use the first half of hanning function for onramp
w2=window(ceil((length(window))/2)+1:end); %use second half of hanning function of off ramp
w_on_xt = [w1 ones(1,length(xt)-length(w1))];
w_off_xt = [ones(1,length(xt)-length(w2)) w2];
xt_ramped = xt.*w_on_xt.*w_off_xt;
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulation, Tuning, and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!