Inverse Z Transform recursion code not working?
6 次查看(过去 30 天)
显示 更早的评论
So I was working on this code that basically uses the power series to use recursion to do an inverse Z transform from a given function. ~
syms a b i n x z % Create symbolic variables
prompt = 'What is the value of n? ';
x_n = input(prompt)
x_n = (a*n - symsum(x*(n-i))*b*i/b);
x_n=simplify(x_n)
g=iztrans(x_n,z,n); %Inverse Z-transform for xn[z]
g=simplify(g)
Fs = 100; % Sampling frequency
T = (1 / Fs)*pi; % Sampling period (time interval between samples)
L = 10*pi; % Length of signal duration in seconds
t= (0:T:(L-T)); % Time interval set
g=subs(g,n,t); %Substitute the values of t into the double value h
figure(1); % Open a new figure
stem(t,g) % Plot the transfer function
hold on
h2=sin(pi.*t/3);
stem(t,(h2))
hold off
xlabel('t / s');
ylabel('h(t)');
However, when running the code, it outputted this:
0 个评论
回答(1 个)
Shadaab Siddiqie
2021-4-15
From my understanding you are getting an error for the above code. This is because you are substituting the n with t, in line
g=subs(g,n,t); %Substitute the values of t into the double value h
but still g here has another variable x which is not assigned to any value before your plot it in line
stem(t,g) % Plot the transfer function
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!