# Demo entry 3548855

**CodeA**

Submitted by **anonymous**
on Jan 19, 2016 at 14:04

Language: Matlab. Code size: 741 Bytes.

vect = linspace(0,100, 101); %Vector vect for graph representation signal = linspace(0,0, 100); %Vector signal initialization(100 elements vector) N0 = 50; % Period M = 5; %Value of signal s[n] is calculated for n = 1:101 % Because of a MatLab precision error in the representation of pi, % sin(pi)often does not return 0 as expected, so I check that (n-1) % modulo N0 is different from 0. If, instead the value is 0 % the signal assumes as its value the function limit if(mod(n-1, N0) ~= 0) num = sin((2*M + 1) * (pi * (n-1) / N0)); % Numerator den = sin(pi * (n-1) / N0); % Denominator signal(n) = num / den; % Signal value is calculated else signal(n) = 2*M + 1; end end %I draw the graph figure, plot(vect, signal);

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.