How to plot these equations ?
1 次查看(过去 30 天)
显示 更早的评论
Hello
I'm trying to plot these polynomials shown in the image, but I keep receiving errors and I'm not if my code is correct of not. Could you please help ?
regards![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/870800/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/870800/image.png)
clear all
close all
clc
%%
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1024; % Length of signal
t = 2*(0:L-1)*T; % Time vector
x = 0;
c = 1+i;
P(1) = 1;
Q(1) = 1;
P(2) = P(1) + exp(i*(2^(0))*t)*Q(1);
Q(2) = P(1) - exp(i*(2^(0))*t)*Q(1);
P(3) = P(2) + exp(i*(2^(1))*t)*Q(2);
Q(3) = P(2) - exp(i*(2^(1))*t)*Q(2);
P(4) = P(3) + exp(i*(2^(2))*t)*Q(3);
Q(4) = P(3) - exp(i*(2^(2))*t)*Q(3);
for m=1:16
x = x +c*exp(i*2*pi*m*t).*P(m);
end
figure
subplot(2,2,1)
plot(t,x)
title('signal')
6 个评论
采纳的回答
Matt J
2022-1-23
编辑:Matt J
2022-1-23
Change P(m) to P{m} and Q(m) to Q{m} everwhere.
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1024; % Length of signal
t = 2*(0:L-1)*T; % Time vector
x = 0;
c = 1+i;
P{1} = 1;
Q{1} = 1;
for m=2:16
P{m} = P{m-1} + exp(1i*(2^(m-2))*t).*Q{m-1};
Q{m} = P{m-1} - exp(1i*(2^(m-2))*t).*Q{m-1};
end
for m=1:16
x = x +c*exp(1i*2*pi*m*t).*P{m};
end
whos x
4 个评论
Matt J
2022-1-23
I'm glad it worked, but please Accept click the answet to indicat so.
Whether it's to be considered flat is probably subjective...
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!