## Variables in embedded C programming language What are variables in C language. Variables are simple keywords which are defined by the values. Values can be changed. Variables are like a boxes with some size where values like apples can be put in. So variables can be various forms and sizes so called variable types. Variable type is defined by a reserved word which indicates the type and size of variable identifier: unsigned char my_char; long int all_my_numbers; int number; Why do we need variables? The basic answer is that memory is limited and compiler needs to know much space to reserve for each variable. The coder needs to specify the variable type and its size by using one of reserved words from the table:

## Gauss-Zeidel optimization routines This is simplest optimization routines. Using this algorithm optimization parameters are changed separately in each step. Only one parameter can be changed in one step while other are helt as constants. Xk+1=Xk+ΔXk , k=0,1,2,… ΔXk step of parameter Xk. Parameter is changed until function growth is noticed, and then next parameter follows and so on. After cycle with all parameters is completed, then step is changed to half of its value and repeat cycle again. Optimal point searching ends when there is no function increase and last point is held as optimal point. Lets see how it works with following function: Its plot: Using MATLAB script we get results bellow. In each picture start coordinates are different. Start coordinates. x=150; y=200; Start coordinates x=50; y=150; Other example Start coordinates x=10; y=10; Start coordinates x=100; y=200; Third example Start coordinates x=10; y=10; Start coordinates x=50; y=200; Matlab script: close all; clear all; clc; [X,Y] = meshgrid(-100:1:100, -100:1:100); Z =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5000)); xx=100; yy=100; contour3(Z,20); hold on; % figure(2); mesh(Z); % figure % plot3(X,Y,Z) X=70; Y=100; X1=0;Y1=0; X0=X; Y0=Y; z=160; figure(1); plot(X,Y,’r*’), hold on; X=X-xx; Y=Y-yy; TT1 =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5053)); for i=1:50 z=z/2; X=X-z; Z2 =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5053)); if Z2>=TT1 TT=Z2; X1=X;…

## Impulse Response of discrete system Impulse signal can be represented as: d[n] = 1, if n=0 d[n] = 0, otherwise it can also be written like d=[1,0,0,0,â€¦] Impulse Response The impulse response h(n) is the response of filter L() at time n to unit impulse occurring at time 0. h(n)=L(d(n)) Lets see how discrete system can be described when impulse response is known We know that: In the linear system this can be written as follows: Because h(n-k)=L(d(n-k)) Then: What do we get? There is obvious, that linear system can be described by its impulse response. The last expression is called convolution. This is the heart of DSP Filtering. To write this sum in more convenient matter is assumed that: Matlab example Matlab example: % Plot an unit impulse signal n = -7:7; x = [0 0 0 0 0 0 0 1 2 3 0 0 0 0 0]; subplot(4,2,1); stem(n, x); limit=[min(n), max(n), 0, 5]; axis(limit); title(‘Input x[n]’); subplot(4,2,3); x0=0*x; x0(8)=x(8); stem(n, x0); axis(limit); h=text(0, x0(8), ‘x’); set(h, ‘horiz’, ‘center’, ‘vertical’, ‘bottom’); subplot(4,2,4); y0=0*x; index=find(x0); for i=index:length(n) y0(i)=x0(index)*exp(-(i-index)/2); end stem(n, y0); axis(limit); h=text(0, x0(8), ‘x*h[n-0]’); set(h, ‘vertical’, ‘bottom’); subplot(4,2,5); x1=0*x; x1(9)=x(9); stem(n, x1); axis(limit); h=text(1, x1(9), ‘x’); set(h, ‘horiz’, ‘center’, ‘vertical’, ‘bottom’); subplot(4,2,6);…

## Pointers to structures in embedded C Sometimes you might like to manipulate the members of C structures in more generalized way. This can be done by using pointer reference to structure. Normally it is easier to pass pointer to structure than passing entire structure to function. Structure pointer can be declared very easily: struct structure_tag_name *variable; For instance: struct position{ int x; int y; }pos1, *pos2; we can assign first structure address to structure pointer like this: pos2=&pos1; now we can access first structure members by using structure pointer: pos2->x=10; or we can write (*pos2).x=10; Structures can contain member pointers to other structures or to structures of same type. This way we can create lists – dynamic structure: struct list{ int listNo; struct list *next; //pointer to another structure }item1, item2; This way you can assign the pointer with address to another structure: item1.next=&item2; Read more about dynamic structures in C tutorials on internet.

## C language Operators and expressions

The main thing what microcontrollers does is operates with data. There are four main operations that microcontrollers does: adds, abstracts, multiplies and divides (+,-,*,/). division can be split in division “/” and modulus operation “%”. For instance i1/i2 is integer division. Other part of operators is Relation operators. They are used for boolean conditions and expressions. Expressions with these operators return true or false values. Zero is taken as false and non zero value as true. Operators may be as follows: <, <=, > >=, ==, !=. The priority of the first four operators is higher than that of the later two operators. These operators are used in relational expressions such as: 7 > 12 // false 20.1 < 20.2 // true ‘b’ < ‘c’ // true “abb” < “abc” // true Note that the equality operator is == and not =. ‘=’ is an assignment operator. If you want to compare a and b for equality then you should write a == b, not a = b because a = b means you are assigning the value of b to a, as shown in. Next part of operators are logical operators. With logical operators results may be combined to…

## Constants in C language

Constant value is understandable as non changeable value like PI=3.141592… value in math. Usually you use constants in your programs, but don’t realize that they are constants. For instance: x=x+3; The number 3 is a constant which will be compiled directly in addition operation. Constants can be character or string. Like in function printf(“Hello World\n”); “Hello World” is a string constant which is placed in program memory and will never changes. It is usually recommended to declare constants by using identifier with reserved word const: const int No=44; By identifying the variable as constant will cause compiler to store this variable in program memory rather than in RAM, thus saving space in RAM. If special functions used, then constants can be also stored in EEPROM memory. Few words for the numeric constants. Numeric constants can be declared in many ways indicating their base. Decimal integer constants (base 10) consist of one or more digits, 0 through 9, where 0 cannot be used as the first digit. Binary constants (base 2) begin with a 0b or 0B prefix, followed by one or more binary digits (0, 1). Octal constants (base 8) consist of one or more digits 0 through 7, where…

## The very basics of C

C language is function based programming language. C program itself is a function. Usually parameters to C function are passed as arguments. Function consists of a name followed by the parentheses enclosing arguments or an empty pair of parentheses if there are not arguments required. If there are several arguments, they are separated by commas. The mandatory part in C program is main function. This function must be included in every program because this is a first function which is run after execution of program. Lets take an example: #include <stdio.h> int main(void) { printf(“Hello world!\n”); return 0; } This is a very basic C program, but it contains all necessary elements of it. Lets examine a little bit what we have written here…