이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How could I generate a biphasic pulse train?
조회 수: 4 (최근 30일)
이전 댓글 표시
Abir Ouji
2020년 11월 9일
hi :)
i m trying to generate a biphasic pulse train to modulate with speech signal. but all i found is pulse train with positive amplitude only.
how could I generate a biphasic pulse train ? any help ?
채택된 답변
Mathieu NOE
2020년 11월 9일
hello
maybe this can help you
freq = 10 ;
Ts=1e-04;
t=0:Ts:1;
angl = 2*pi*(mod(freq*t,1));
% % example 1 : positive square wave / mono phasic pulse train
% square_wav = 0.5*(sign(sin(angl))+1);
% plot(t,square_wav);
% example 2 : bi phasic pulse train
interphase_gap = 10e-3; % gap (in second)
gap_angl = 2*pi*freq*interphase_gap;
angl(angl<=gap_angl/2) = 0;
angl(abs(2*pi-angl)<=gap_angl/2) = 0;
angl(abs(pi-angl)<=gap_angl/2) = 0;
biphasic_pulse_train = sign(sin(angl));
% plot(t,angl);
plot(t,biphasic_pulse_train);
댓글 수: 19
Abir Ouji
2020년 11월 10일
thnx a lot ^^
could u please help me apply this pulse train on other signals to get finally pulses that take the shape each signal like this..

Mathieu NOE
2020년 11월 12일
hello
sorry, I'm not sure to understand what you need ? you want to simulate the same type of signals like above ?
a mix of mon and bi phasic pulses ?
Mathieu NOE
2020년 11월 20일
hello
so you have to create a bi phasic pulse train signal that has ame length as your audio signal
at th time index of when the pulse signal gets from positive to negative, you pick the amplitude of the audio signal and multiply the bi phasic pulse train signal with that amplitude info
Abir Ouji
2020년 11월 20일
i got it but how is that with matlab ? I m a beginner and still learning matlab. could u please help me ? :)
Mathieu NOE
2020년 11월 20일
hello
ok, can yu share your audio file ?
second, can yu define when the pulses are defined on the time axis ?
Abir Ouji
2020년 11월 20일
hiii, i couldn't share the audio file but u can use any audio file.wav u want, coz i need to try everytime an audio with the commande [y,fs]=audioread('filename.wav');
second, the pulses should be like these ones:

with a rate=833 pulse/sec and d=33 msec/phase and it start's after 1/rate duration
Mathieu NOE
2020년 11월 20일
hello I think I have a code that works but I have a problem with the values you gave above
if d is 33 msec (confirm) , so 33e-3 s , you cannot have 833 pulses per seconde because each pulse duration would be 66 msec, so max 15 pulses per second is doable, and it woul look like there is no time space between two consecutive pulses
so, this is the code, but the demo is made with rate = 1;
NB this is made with Fs = 11 kHz wav file

infile='DirectGuitar.wav';
% current sample is 11kHz so 0-3 ms is 0 - 33 samples
% read the sample waveform
[x,Fs] = audioread(infile);
samples = length(x);
time =(0:samples-1)/Fs;
% normalize x to +/- 1 amplitude
x = x ./ (max(abs(x)));
% square pulse wave
% rate=833 pulse/sec and d=33 msec/phase and it start's after 1/rate duration
rate = 1; % Fs/833;
start_time = 1; %rate/Fs; % in seconds
gap_seconds = 33e-3; % please double check
[BP_train, signal_pulsed] = bptrain(Fs,samples,rate,start_time,gap_seconds,x);
% plot
figure(1);
subplot(3,1,1),plot(time,x,'b');grid
title('input waveform');
subplot(3,1,2),plot(time,BP_train,'b');grid
title('pulse train');
subplot(3,1,3),plot(time,signal_pulsed,'b');grid
title('pulsed waveform');
function [biphasic_pulse_train, signal_pulsed] = bptrain(Fs,samples,rate,start_time,gap_seconds,signal)
start_sample = floor(start_time*Fs);
gap_angl = 2*pi*rate*gap_seconds;
sin_gap_angl = sin(gap_angl);
time =(0:samples-start_sample)/Fs;
angl = 2*pi*(mod(rate*time,1));
time = (0:samples-1)/Fs;
out = zeros(samples,1);
angl = [zeros(1,start_sample-1) angl];
ind_pos = find(angl>0 & angl<=gap_angl);
out(ind_pos) = 1;
ind_neg = find(angl>gap_angl & angl<=2*gap_angl);
out(ind_neg) = -1;
% create a enveloppe of the signal before applying the product with the
% pulse train
N = 1000;
envelop = myslidingavg(abs(signal), N);
biphasic_pulse_train = out;
signal_pulsed = biphasic_pulse_train.*envelop;
end
function out = myslidingavg(in, N)
% OUTPUT_ARRAY = MYSLIDINGAVG(INPUT_ARRAY, N)
%
% The function 'slidingavg' implements a one-dimensional filtering, applying a sliding window to a sequence. Such filtering replaces the center value in
% the window with the average value of all the points within the window. When the sliding window is exceeding the lower or upper boundaries of the input
% vector INPUT_ARRAY, the average is computed among the available points. Indicating with nx the length of the the input sequence, we note that for values
% of N larger or equal to 2*(nx - 1), each value of the output data array are identical and equal to mean(in).
%
% * The input argument INPUT_ARRAY is the numerical data array to be processed.
% * The input argument N is the number of neighboring data points to average over for each point of IN.
%
% * The output argument OUTPUT_ARRAY is the output data array.
if (isempty(in)) | (N<=0) % If the input array is empty or N is non-positive,
disp(sprintf('SlidingAvg: (Error) empty input data or N null.')); % an error is reported to the standard output and the
return; % execution of the routine is stopped.
end % if
if (N==1) % If the number of neighbouring points over which the sliding
out = in; % average will be performed is '1', then no average actually occur and
return; % OUTPUT_ARRAY will be the copy of INPUT_ARRAY and the execution of the routine
end % if % is stopped.
nx = length(in); % The length of the input data structure is acquired to later evaluate the 'mean' over the appropriate boundaries.
if (N>=(2*(nx-1))) % If the number of neighbouring points over which the sliding
out = mean(in)*ones(size(in)); % average will be performed is large enough, then the average actually covers all the points
return; % of INPUT_ARRAY, for each index of OUTPUT_ARRAY and some CPU time can be gained by such an approach.
end % if % The execution of the routine is stopped.
out = zeros(size(in)); % In all the other situations, the initialization of the output data structure is performed.
if rem(N,2)~=1 % When N is even, then we proceed in taking the half of it:
m = N/2; % m = N / 2.
else % Otherwise (N >= 3, N odd), N-1 is even ( N-1 >= 2) and we proceed taking the half of it:
m = (N-1)/2; % m = (N-1) / 2.
end % if
for i=1:nx, % For each element (i-th) contained in the input numerical array, a check must be performed:
dist2start = i-1; % index distance from current index to start index (1)
dist2end = nx-i; % index distance from current index to end index (nx)
if dist2start<m || dist2end<m % if we are close to start / end of data, reduce the mean calculation on centered data vector reduced to available samples
dd = min(dist2start,dist2end); % min of the two distance (start or end)
else
dd = m;
end % if
out(i) = mean(in(i-dd:i+dd)); % mean of centered data , reduced to available samples at both ends of the data vector
end % for i
Abir Ouji
2020년 11월 20일
hello,
it shows an error for me and says "Function definitions are not permitted in this context" :/
Abir Ouji
2020년 11월 20일
i got it ! i think this version of matlab (R2014b) does not count "bptrain" syntax :/
Mathieu NOE
2020년 11월 21일
you can of course create or download new functions (from the File Exchange for example)
there are no limits to expand matlab functionnalities
for your code the main code for you would be only this part
infile='DirectGuitar.wav';
% current sample is 11kHz so 0-3 ms is 0 - 33 samples
% read the sample waveform
[x,Fs] = audioread(infile);
samples = length(x);
time =(0:samples-1)/Fs;
% normalize x to +/- 1 amplitude
x = x ./ (max(abs(x)));
% square pulse wave
% rate=833 pulse/sec and d=33 msec/phase and it start's after 1/rate duration
rate = 1; % Fs/833;
start_time = 1; %rate/Fs; % in seconds
gap_seconds = 33e-3; % please double check
[BP_train, signal_pulsed] = bptrain(Fs,samples,rate,start_time,gap_seconds,x);
% plot
figure(1);
subplot(3,1,1),plot(time,x,'b');grid
title('input waveform');
subplot(3,1,2),plot(time,BP_train,'b');grid
title('pulse train');
subplot(3,1,3),plot(time,signal_pulsed,'b');grid
title('pulsed waveform');
the rest , that is the 2 subfunctions are stores are separate m functions , either in the same directory as the main code or as your own toolbox (create a folder and add it to the matlab path)
Mathieu NOE
2020년 11월 22일
hello again
in case you need more info on functions , see the help
https://fr.mathworks.com/help/matlab/ref/function.html
Abir Ouji
2020년 11월 22일
편집: Abir Ouji
2020년 11월 22일
hello
I did store two separate m functions. first i doesn t work coz the variables in in the function instruction are not define. for example for the function myslidingavg i needed to define the two variable N and in ! so I did and it works.
but could u please tell me what are the signification of every variable of the function bptrain and its role? so i could solve the rate and duration problem.
I only have less than a week to finish this but still doesn t work and I started to get nervous and stressed :(
Mathieu NOE
2020년 11월 22일
hello
I have cleaned my code and aded more comments everywhere to help you
also there is the main code and separate subfunctions
hope it helps
Abir Ouji
2020년 11월 22일
hiii :)
it does wooooooooooork :D
thank you a lot Mathieu NOE you are so kind, helpful and gentle. thank you :)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 AI for Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)