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[0]’); 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[0]*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[1]’); set(h, ‘horiz’, ‘center’, ‘vertical’, ‘bottom’); subplot(4,2,6);…

Continue reading

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.

Continue reading

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…

Continue reading

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…

Continue reading

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…

Continue reading