Gisu
Gisu

Reputation: 27

Undefined function 'symsum' for input arguments of type 'double'

I am trying to generates the variable Fourier series for a square wave signal and a uniformly distributed noise signal.

This is my code and I have this error

Undefined function 'symsum' for input arguments of type 'double'.

fs = 1000;       %Sampling  frequency Hz [1 1000]
l = 1 ;         %Signal length sec [1 10]

% Fourier Series Parameter
h = 1;    %Amplitude [0 10]; default 1
k =1 ;  %Fourier Series lenght(k);[1 21]

% Noise Signal specific parameters

h1 = 1;  %Amplitude (h); [0 10]; default: 1

%calculate signal
%x = 0:1/fs:L-1/fs; 

x = 0:1/fs:l-1; 

n = [1; Inf];
f(x) = 4*h/pi * symsum( (1./k) * sin((2*pi*k*x)),k,2*n-1,n); %Fourier series for a square wave signal

%uniformly distributed noise signaL
%Noise signal specific parameters
%Amplitude (h); [0 10]; default: 1
h2 = 1 ; % Noise Amplitude

sig_Noise = h2*(f(x) + sigma*randn(1,length(x))); %  signal with phase  & amplitude noise 

plot(x,f(x)) 

my summation is here Summation how can I fix it?

Upvotes: 1

Views: 2374

Answers (1)

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23675

This should do the trick:

fs = 1000; %Sampling Frequency Hz [1 1000]
l = 10; % Signal Length sec [1 10]
h = 1; % Amplitude [0 10] - Default 1
h2 = 1; % Noise Amplitude
sigma = 1;
x = 0:(1/fs):(l-1);

syms k;
syms f(x);
f(x) = 4*h/pi() * symsum((1/k)*sin(2*pi()*k*x),k,1,Inf); % Fourier series for a square wave signal

fplot(x,f(x));

Actually, if you want to work with symbolic maths... you have to work with symbolic variables that can be declared using the syms keyword. For plotting, the fplot function must be used instead of plot.

Upvotes: 1

Related Questions