Posts: 21
Threads: 9
Joined: Nov 2017
Nov-20-2018, 12:26 PM
(This post was last modified: Nov-20-2018, 12:26 PM by royer14.)
hello, I'm trying to use the matplotlib library and since I'm new my code has been written wrong, can you tell me what I failed ?, more than anything I would like to be corrected
x = np.arange(1,41)
b = 0.7
a =(1 - b) / (1-b**5)
i = np.arange(1,5)
w = a*(b**(5-i))
for n in range[5:40]:
y = [w*x[n-4:n].conj().T]
n = range[5:40]
plt.plot(x,y)
plt.show() my question from the book is the following:
- Generate a MATLAB graph of the output response and y[n], for 5 <= n <= 40 of the filter
PMPE in point 5, with b = 0.7, when the input x[n] is:
a) x[n] = 1, 0 <= n <=40
graphic that I want to obtain
[Image: fu4du3k5scs6je27g.jpg]
I would appreciate any help from you
Posts: 4,790
Threads: 76
Joined: Jan 2018
There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y?
Posts: 21
Threads: 9
Joined: Nov 2017
(Nov-20-2018, 01:20 PM)Gribouillis Wrote: There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y? ok,sorry for the delay
[Image: dy6u5128enq07ay7g.jpg]
Posts: 4,790
Threads: 76
Joined: Jan 2018
Nov-20-2018, 05:16 PM
(This post was last modified: Nov-20-2018, 05:17 PM by Gribouillis.)
It is still unclear, what are the possible values of n ? When i varies from 0 to N-1, the index n-i decreases from n to n-N+1, which may be negative. Can you explain this point?
It looks like a convolution, some special functions such as numpy.convolve may be useful later once we understand what you are doing.
Posts: 21
Threads: 9
Joined: Nov 2017
Nov-20-2018, 06:13 PM
(This post was last modified: Nov-20-2018, 06:13 PM by royer14.)
(Nov-20-2018, 05:16 PM)Gribouillis Wrote: It is still unclear, what are the possible values of n ? When i varies from 0 to N-1, the index n-i decreases from n to n-N+1, which may be negative. Can you explain this point?
It looks like a convolution, some special functions such as numpy.convolve may be useful later once we understand what you are doing.
Well the code had found it in Matlab and I have guided him, now I show you the code made in Matlab.
vew image
Posts: 4,790
Threads: 76
Joined: Jan 2018
I could run your code in Scilab. Here is a first python equivalent
import numpy as np
from matplotlib import pyplot as plt
N = 40
x = np.ones(N+1)
b = 0.7
S = 5
a =(1 - b) / (1-b**S)
i = np.arange(1,S+1)
w = a * (b**(S-i))
# print(w)
y = np.zeros(N)
y[S-1:] = [ np.dot(w, x[n-S+1:n+1].T) for n in range(S-1, N)]
print(y)
print(len(y))
plt.plot(range(S, N+1),y[S-1:], marker='o')
plt.plot(range(S, N+1),y[S-1:], linestyle='-')
plt.show()
Posts: 21
Threads: 9
Joined: Nov 2017
(Nov-20-2018, 07:07 PM)Gribouillis Wrote: I could run your code in Scilab. Here is a first python equivalent
import numpy as np
from matplotlib import pyplot as plt
N = 40
x = np.ones(N+1)
b = 0.7
S = 5
a =(1 - b) / (1-b**S)
i = np.arange(1,S+1)
w = a * (b**(S-i))
# print(w)
y = np.zeros(N)
y[S-1:] = [ np.dot(w, x[n-S+1:n+1].T) for n in range(S-1, N)]
print(y)
print(len(y))
plt.plot(range(S, N+1),y[S-1:], marker='o')
plt.plot(range(S, N+1),y[S-1:], linestyle='-')
plt.show()
fantastic, thank you very much for doing it saved me from a headache, thank you very much
Posts: 21
Threads: 9
Joined: Nov 2017
but I want to know how you did the graph, see if I have the following, how would you do it?
Posts: 4,790
Threads: 76
Joined: Jan 2018
I think one only needs to replace line 4 with
x = list(range(N+1)) If you want to go further, you need to analyse the python code to understand how it works.
|