To find Group delay : Error using diff Difference order N must be a positive integer scalar.

To find Group delay : Error using diff Difference order N must be a positive integer scalar.
I am trying to find the group delay of a modulated signal , which is derivative of phase delay , but while using diff iam getting this error "Error using diff Difference order N must be a positive integer scalar" , can anyone sugget method to do this
this is the code i tried to do
close all;
dt=.0001;
fs=1/dt; %sampling frequency
fn=fs/2;
n=100;
t=dt*(-n/2:n/2); %time base
f0 = 200; %to modulate GP multifly by cos(2ft*pi)
xt = cos(2*pi*t*f0) .* cos(2*pi*fn*t);
y = hilbert(xt);
m = abs(y);
g = angle(y);
ph = -g/(2*pi*f0);
gd = diff (ph,(2*pi*f0));
figure
subplot(3,1,1);
plot(t,xt,'b');
title('signal');
xlabel('Time(s)'); ylabel('Amplitude');
subplot(3,1,2);
plot(t,ph,'b');
title('phase delay');
xlabel('Time(s)'); ylabel('phase');
subplot(3,1,3);
plot(t,gd,'b');
title('group delay');
xlabel('Time(s)'); ylabel('phase');

댓글 수: 2

ph = -g/(2*pi*f0);
gd = diff (ph,(2*pi*f0));
What was your hope that this would accomplish?
group delay is taken as the derivative of phase delay
so i thought taking differential would give me the group delay of the signal envelope.

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

 채택된 답변

Replace the line:
gd = diff (ph,(2*pi*f0));
with
gd = diff([ph (2*pi*f0)]);

댓글 수: 2

thank you , the code was completed well and stoped getting the error message.
I don't think this is right for the circumstances

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

추가 답변 (1개)

MATLAB has two diff() functions. The one that your equation is for, the calculus derivative, is only used for symbolic expressions and symbolic functions.
The other one applies for all numeric types, and is the successive difference operator, x(2:end) - x(1:end-1) . In the case of equidistant points each 1 unit apart it acts as an approximation of numeric derivative.
As you have numeric data, I recommend that you use gradient(), which does more accurate approximation of numeric derivative.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 11월 29일

답변:

2021년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by