Clear Filters
Clear Filters

matlab fourier series..

5 views (last 30 days)
jongguk Choi
jongguk Choi on 20 Sep 2020
Answered: Angelo Yeo on 23 Jun 2024 at 0:15
syms n(t)
a1 = exp(30j);
a2 = exp(-30j);
a3 = (-1/(800*pi-200*n*pi));
a4 = (1/(800*pi-200*n*pi));
a5 = (j*(4*pi-n*pi));
a6 = (j*(4*pi+n*pi));
A = 1/2*(a1*(a3*exp(a5))+a3*(exp(a6))+a2*(a4*exp(a6))-a4*exp(a5));
b1 = exp(60j);
b2 = exp(-60j);
b3 = (-1/(1800*pi-200*n*pi));
b4 = (1/(1800*pi-200*n*pi));
b5 = (j*(9*pi-n*pi));
b6 = (j*(9*pi+n*pi));
B = (b1*(b3*exp(b5))+b3*(exp(b6))+b2*(b4*exp(b6))-b4*exp(b5));
c1 = exp(45j);
c2 = exp(-45j);
c3 = (-1/(2400*pi-200*n*pi));
c4 = (1/(2400*pi-200*n*pi));
c5 = (j*(12*pi-n*pi));
c6 = (j*(12*pi+n*pi));
C = 3/2*(c1*(c3*exp(c5))+c3*(exp(c6))+c2*(c4*exp(c6))-c4*exp(c5));
C_n = 1/0.01*(A+B+C);
f_sample = 10e3; %Sampling Frequency
T_sample = 1/f_sample; %Sampling Time
t = [0:T_sample:0.05]; %time for display fs = 1kHz
N=length(t);
for n=1.0000:N
f_t(n)=0;
f_t(n)= C_n*exp(j*n*2*pi*t/0.01);
end
Unable to perform assignment because value of type 'symfun' is not convertible to 'double'.

Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
f_t(n)에서 double형 배열로 변환할 수 없다는데.. 무엇이 문제일까요 ㅠ

Answers (1)

Angelo Yeo
Angelo Yeo on 23 Jun 2024 at 0:15
MATLAB에서 'symfun' 타입을 'double' 타입으로 변환할 수 없다는 에러는 주로 심볼릭 변수를 포함한 표현식을 숫자로 변환하려 할 때 발생합니다. 이 문제를 해결하려면, 심볼릭 변수를 실제 값으로 대체한 후 변환해야 합니다. 아래와 같이 subs 함수를 사용하여 심볼릭 변수를 실제 값으로 대체한 다음 변환할 수 있습니다.
syms n(t)
a1 = exp(30j);
a2 = exp(-30j);
a3 = (-1/(800*pi-200*n*pi));
a4 = (1/(800*pi-200*n*pi));
a5 = (j*(4*pi-n*pi));
a6 = (j*(4*pi+n*pi));
A = 1/2*(a1*(a3*exp(a5))+a3*(exp(a6))+a2*(a4*exp(a6))-a4*exp(a5));
b1 = exp(60j);
b2 = exp(-60j);
b3 = (-1/(1800*pi-200*n*pi));
b4 = (1/(1800*pi-200*n*pi));
b5 = (j*(9*pi-n*pi));
b6 = (j*(9*pi+n*pi));
B = (b1*(b3*exp(b5))+b3*(exp(b6))+b2*(b4*exp(b6))-b4*exp(b5));
c1 = exp(45j);
c2 = exp(-45j);
c3 = (-1/(2400*pi-200*n*pi));
c4 = (1/(2400*pi-200*n*pi));
c5 = (j*(12*pi-n*pi));
c6 = (j*(12*pi+n*pi));
C = 3/2*(c1*(c3*exp(c5))+c3*(exp(c6))+c2*(c4*exp(c6))-c4*exp(c5));
C_n = 1/0.01*(A+B+C);
% 심볼릭 변수를 숫자로 대체
n_value = 1; % 적절한 숫자 값으로 n을 대체
C_n_numeric = subs(C_n, n, n_value);
f_sample = 10e3; % Sampling Frequency
T_sample = 1/f_sample; % Sampling Time
t = 0:T_sample:0.05; % time for display fs = 1kHz
N = length(t);
f_t = zeros(1, N);
for n = 1:N
f_t(n) = C_n_numeric * exp(j * n * 2 * pi * t(n) / 0.01);
end
figure;
tiledlayout(2,1)
nexttile;
plot(real(f_t));
nexttile;
plot(imag(f_t))

Categories

Find more on Biotech and Pharmaceutical in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!