count=0;
for j = 1:frame_number
for i=1:15
if (A(i,j)*A(i+1,j))<0
count=count+1;
end
b(j)=count;
end
count=0;
end

3 件のコメント

Dyuman Joshi
Dyuman Joshi 2022 年 7 月 31 日
What are you trying to reshape?
Onur Batin Genc
Onur Batin Genc 2022 年 7 月 31 日
clc;
clear;
close all;
[x,fs]=audioread('susanhates8khz8bit.wav');
N = length(x);
frame_length=16;
time = 0:1/fs:N/fs-1/fs;
%nth frame ==>time
n=input("enter a number: ");
nth_frame_start=frame_length*(n-1)*(1/fs);
nth_frame_finish=frame_length*n*(1/fs);
A = [nth_frame_start,nth_frame_finish];
disp(A)
figure
subplot(2,1,1), stem(x), grid on, xlabel('sample'),axis tight;
subplot(2,1,2), plot(time,x),grid on, xlabel('time'),axis tight;
%ADD NOISE
figure
Noise_Data = x + 0.01*randn(size(x));
title('Audio with noise'),plot(time,Noise_Data), grid on, xlabel('time'),axis tight;
%framing with for loop
frame_number=floor(N/frame_length); %frame_number = Length of the signal/frame_length
k=1;
for i=1:frame_number
for j=1:frame_length
A(j,i)=x(k);
k = k+1;
end
end
%or without for loop A=reshape(x(1:frame_length*frame_number),frame_lengthe,frame_number);
count=0;
for j = 1:frame_number
for i=1:15
if (A(i,j)*A(i+1,j))<0
count=count+1;
end
b(j)=count;
end
count=0;
end
Onur Batin Genc
Onur Batin Genc 2022 年 7 月 31 日
Thats the main code of my approach. I was trying to use reshape instead of for loop to get zero crossing points.

サインインしてコメントする。

 採用された回答

Jan
Jan 2022 年 7 月 31 日

0 投票

Your loop method overwrites b(j) repeatedly. Setting count to 0 in two lines is confusing. Simpler:
for j = 1:frame_number
count=0;
for i = 1:15
if (A(i,j) * A(i+1,j)) < 0
count = count + 1;
end
end
b(j) = count;
end
In a next step of simplification you can omit the if branch and add the result of the condition directly:
for j = 1:frame_number
count=0;
for i = 1:15
count = count + ((A(i,j) * A(i+1,j)) < 0);
end
b(j) = count;
end
If the condition is true, its value is converted to 1. false is converted to 0.
But you can omit the loop completely:
AA = A(1:15, :) .* A(2:16, :);
b = sum(AA < 0, 1);
There is no need for a reshape command.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 7 月 31 日

回答済み:

Jan
2022 年 7 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by