Info

This question is closed. Reopen it to edit or answer.

Can anyone help plotting a function?

1 view (last 30 days)
Mehran
Mehran on 30 Jul 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello. I'm trying to plot this function:
K=4;N=39; k=0:K; f=0:120; z=exp(2*pi*sqrt(-1)*f); {for i=0 d(i)=0 else d(i)=-1}
I don't get the right answer with my code!
clc
clear all
close all
K=4; N=39;
for k=1
for f=1:120;
z=exp(sqrt(-1)*2*pi*f);
diz=z^0;
for ii =1:2*K
diz=diz-z^(-ii);
end
H=(2*pi/(3*N))^k*...
(1-z^(-2))^(K-k)*...
(1+4/z+z^(-2))/diz;
plot (f,H)
hold on
end
end
what is wrong with my code?!
real answer is:
Thanks for your considerations!
  3 Comments
Michael Haderlein
Michael Haderlein on 31 Jul 2014
I just have some remarks which all unfortunately still don't lead to the graph you showed:
- Better don't use the for loop for f. Use vector calculation instead, is much faster.
- You initialize diz with 1 (z^0). Correct according to your equation would be 0.
- You plot for k=1, but in the graph you plot everything except of k=1.
- Your definition of z looks a bit odd. exp(2i*pi*k) is always 1 if k is an integer.
However, I still don't come to your plot. But maybe these points help you to find the problem.
Best regards, Michael
Patrik Ek
Patrik Ek on 31 Jul 2014
Edited: Patrik Ek on 31 Jul 2014
I think that f should be normalized frequency. The Z-transform is use for discrete frequencies and these are usually normalized with the sampling frequency. Also, are you sure that you are plotting the graph the correct way? I have not got all information, but my impression is that this is a frequency response. This gives some conditions of d_i. My guess is that it symbolizes poles to the system somehow. Something like `d0+d1*z^-1+d2*z^-2+...` or what poles you have. It makes no sense that all poles are 1. You should read the task one more time and think about what you need to do.
Try this for example:
clc; clear all; close all;
K=4; N=39;
k = 1;
for f=1:120;
z=exp(1i*2*pi*f/240);
diz=z^0;
for ii =1:2*K
diz=diz+1/ii*z^(-ii);
end
H(f)=( 2*pi/(3*N) )^k * (1-z^(-2))^(K-k) * ( 1+4/z+z^(-2) )/diz;
end
plot (1:120,abs(H))
It is absolutely not there yet, but it is closer. With the right value of `d_i` It would maybe work.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!