how i implement code for y=audiorec​ord(Fs,nbi​ts,1)

조회 수: 3 (최근 30일)
gadhamg
gadhamg 2018년 3월 21일
댓글: govindaraj sangam 2021년 1월 5일
close all;
clear all;
%%Variables
low_stop = 300;
high_stop = 1000;
WindowEnvelope = 0.1; % Length of envelope averaging filter window
MaximaWindow = 2.4; % Length of window to find local maxima
DownSamp = 200; % Frequency to downsampe envelope to (Hz)
Threshold = 0.2; % Percentage of mean maxima value that a
Fs = 8000; % Sampling Frequency
nbits = 8; % Bits of Precision When Sampling
WindowTime = 5; % Length of recorded time processed in each
%%Initialize
BreathCountTotal = 0;
Y = audiorecord(Fs,nbits,1);
meanbreath = 0;
%%Create Bandpass Filter
F=[(low_stop-100) low_stop high_stop (high_stop+100)]; % band limits
A=[0 1 0]; % band type: 0='stop', 1='pass'
dev=[0.0001 10^(0.1/20)-1 0.0001]; % ripple/attenuation spec
[M,Wn,beta,typ]= kaiserord(F,A,dev,Fs); % window parameters
b = fir1(M,Wn,typ,kaiser(M+1,beta),'noscale'); % filter design
%%Initialize
loopcount = 0;
EXIT = 1;
BreathTotal = [];
%%Initial Recoding
signal = zeros(1,Fs*WindowTime);
record(y)
while EXIT == 1
%%Counter
loopcount = loopcount + 1;
%%Filter Signal
signal_f = fftfilt(b,signal);
%%Find Envelope
signal_h = hilbert(signal_f); % Hilbert Transform
envelope = sqrt(signal_h.*conj(signal_h));
envelope_f = filter(ones(1,round(Fs*WindowEnvelope))/round(Fs*.1),1,envelope);
envelope_fDS = downsample(envelope_f,round(Fs*(1/DownSamp)));
%%Find Local Maxima
windowsize = DownSamp * MaximaWindow / 4;
BreathCount = 0;
Breath = [];
for ix = 1:length(envelope_fDS) - windowsize
maxima = max(envelope_fDS(ix:ix+windowsize));
if loopcount < 2 % Ignore first 2 loops
elseif loopcount < 100 % Use next 100 loops to get breath
threshold
if maxima == envelope_fDS(ix+windowsize/2)
BreathCount = BreathCount + 1;
Breath(BreathCount) = ix + windowsize/2;
end
else % Begin using and updating threshold
if (maxima == envelope_fDS(ix+windowsize/2)) && maxima >(Threshold * meanbreath)
BreathCount = BreathCount + 1;
Breath(BreathCount) = ix + windowsize/2;
end
end
end
BreathTotal = cat(2,BreathTotal,envelope_fDS(Breath));
meanbreath = mean(BreathTotal);
if isempty(Breath) && loopcount > 100 == 1
for i = 1:10
beep
pause(.1)
end
EXIT = 0;
end
%%Keep Recording
stop(y)
signal_new = getaudiodata(y,'double');
record(y)
signal(1:end-length(signal_new)) =signal(1+length(signal_new):end);
signal(end-length(signal_new)+1:end) = signal_new;
clear signal_new
%%Plot
figure(1)
subplot(2,1,1)
signalplot = signal;
time1 = (0:length(signalplot)-1) / (Fs/4);
refresh
plot(time1,signalplot)
title('Raw Signal')
xlabel('Time (seconds)')
ylabel('Intensity')
subplot(2,1,2)
envelopeplot = envelope_fDS;
time = (0:length(envelopeplot)-1) / (DownSamp/4);
plot(time,envelopeplot)
hold on
plot(Breath/(DownSamp/4),envelope_fDS(Breath),'rx','MarkerSize',16,'linewidth',4)
title('Envelope of Breath Signal w/ Breath Markers')
xlabel('time (sec)')
ylabel('Arbitrary Units')
hold off
end
  댓글 수: 3
gadhamg
gadhamg 2018년 3월 22일
Y = audiorecord(Fs,nbits,1); error occuring in this line when I run the program. so please give correct code for sleep apnea detection
govindaraj sangam
govindaraj sangam 2021년 1월 5일
I need explanation for this program

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

채택된 답변

Abhishek Ballaney
Abhishek Ballaney 2018년 3월 22일
https://in.mathworks.com/help/matlab/ref/audiorecorder.html

추가 답변 (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