plot based on if and else condition

조회 수: 1 (최근 30일)
Malar Vizhi
Malar Vizhi 2022년 8월 14일
댓글: Malar Vizhi 2022년 8월 16일
GoodEvening Sir/Mam,
I'm working in intesity of speech .I have classified it based om maximum to minimum energy but i dont know how to plot them.Please help me as possible
[x,fs] = audioread("sa.wav");
%end
si = 0.020;Fsi=si*fs;t=(0:1/Fsi);
frames=framing(x,fs,Fsi);
[r,c] = size(frames);
signal = zeros(size(0));
for i = 1:r
signal(i) = sum(frames(i,:).^2);
end
A=zeros(1,length(signal));
B=zeros(1,length(signal));
C=zeros(1,length(signal));
D=zeros(1,length(signal));
sig = max(signal);
for j=1:length(signal)
I(j)=(signal(j)/sig);
if(0.9<=I(j)<=1)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.6<=I(j)<=0.8)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.4<I(j)<=0.6)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.2<=I(j)<=0.5)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0<=I(j)<=0.1)
A(j)=I(j);
plot(A,'b-');hold on
end
end

답변 (4개)

Torsten
Torsten 2022년 8월 14일
MATLAB does not accept "double inequalities".
Thus instead of
if a < b < c
you will have to use
if a < b && b < c
Further, you should plot A completely after the if-clause, not after every value of j.
Further, you missed to classify the cases 0.8 < l(j) < 0.9, 0.4 < l(j) < 0.5 and 0.1 < l(j) < 0.2. Or should A remain 0 in these cases ?
  댓글 수: 3
Malar Vizhi
Malar Vizhi 2022년 8월 14일
Sir i have change my code but the plot is not changed
Torsten
Torsten 2022년 8월 14일
I can't answer anything useful without the modified code ...

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


Malar Vizhi
Malar Vizhi 2022년 8월 14일
[x,fs] = audioread("sa.wav");
%end
si = 0.020;Fsi=si*fs;t=(0:1/Fsi);
frames=framing(x,fs,Fsi);
[r,c] = size(frames);
signal = zeros(size(0));
for i = 1:r
signal(i) = sum(frames(i,:).^2);
end
%
% plot(signal,'bo');
A=zeros(1,length(signal));
B=zeros(1,length(signal));
C=zeros(1,length(signal));
D=zeros(1,length(signal));
sig = max(signal);
for j=1:length(signal)
I(j)=(signal(j)/sig);
if(0.9<=I(j)) && (I(j)<=1)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.6<=I(j)) && (I(j)<=0.9)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.4<I(j)) && (I(j)<=0.6)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0.2<=I(j)) && (I(j)<=0.4)
A(j)=I(j);
plot(A,'b-');hold on
elseif(0<=I(j))&& (I(j)<=0.2)
A(j)=I(j);
plot(A,'b-');
end
end

Malar Vizhi
Malar Vizhi 2022년 8월 14일
If i give plot outside i got the output as same as signal
[x,fs] = audioread("sa.wav");
%end
si = 0.020;Fsi=si*fs;t=(0:1/Fsi);
frames=framing(x,fs,Fsi);
[r,c] = size(frames);
signal = zeros(size(0));
for i = 1:r
signal(i) = sum(frames(i,:).^2);
end
%
% plot(signal,'bo');
A=zeros(1,length(signal));
B=zeros(1,length(signal));
C=zeros(1,length(signal));
D=zeros(1,length(signal));
sig = max(signal);
for j=1:length(signal)
I(j)=(signal(j)/sig);
if(0.9<=I(j)) && (I(j)<=1)
A(j)=I(j);
% plot(A,'b-');hold on
elseif(0.6<=I(j)) && (I(j)<=0.9)
A(j)=I(j);
%plot(A,'b-');hold on
elseif(0.4<I(j)) && (I(j)<=0.6)
A(j)=I(j);
% plot(A,'b-');hold on
elseif(0.2<=I(j)) && (I(j)<=0.4)
A(j)=I(j);
% plot(A,'b-');hold on
elseif(0<=I(j))&& (I(j)<=0.2)
A(j)=I(j);
end
plot(A,'b-');
end
  댓글 수: 1
Torsten
Torsten 2022년 8월 14일
Yes, A is the signal, normalized to 1.
What else do you expect for the plot if you set
A = signal/max(signal)
(because this is what you do) ?

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


Malar Vizhi
Malar Vizhi 2022년 8월 16일
Actually this is like energy detector.I want compare highest amplitude with each amplitude of signal and seperate it into region of highest and lowest. Now the plot should differentiate these regions.
  댓글 수: 2
Torsten
Torsten 2022년 8월 16일
편집: Torsten 2022년 8월 16일
Then you must plot something different from signal/max(signal) as you do.
Maybe a frequency distribution - I don't know:
A = signal/max(signal);
I = zeros(1,10);
for i = 1:10
I(i) = sum(A>=(i-1)/10 & A<i/10);
end
plot(1:10,I/numel(A))
Malar Vizhi
Malar Vizhi 2022년 8월 16일

Thanks a lot.I will try it

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

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by