Professional Documents
Culture Documents
Generate a bidimensional plot of the elements of this vector versus their indexes and activate the grid lines:
>>plot(b, grid on
Generate a matrix:
>>A=[1 2 0; 2 5 -1; 4 10 -1]
Verify that the product between a matrix and its inverse is the identity matrix:
>>I=inv(A)*A
Generate a vector with increasing equally-spaced elements (the lower limit is 0, the upper limit is 5, and the step
size is 0.05):
>>x=0:0.05:5; y=sin(x);
>>plot(x,y)
>>figure,bar(x,y)
>>figure,stairs(x,y)
>>figure,stem(x,y)
C. Spectral Analysis: the Fourier transform and the power spectral density
Generate a sine waveform in time domain with a 50 Hz frequency, sampled with a frequency of 1 kHz:
>>t=0:0.001:0.25; x=sin(2*pi*50*t);
Calculate and plot the power spectral density of the signal, based on the Fourier transform:
>>Pxx=X.*(conj(X))/256; f=1000/256*(0:127);
>>plot(f,Pxx(1:128))
>>title('DSP'), xlabel('Frequency (Hz)')
Plot the power spectral density of the signal in the [0, 100] Hz band:
>>plot(f(1:25),Pxx(1:25))
>>title ('PSD'), xlabel('Frequency (Hz)')
Build a function to calculate the average and the standard deviation of the elements of a vector.
function [med,devst]=stat(x)
%[med,devst]=stat(x)
%med is the mean, devst is the standard deviation
%of the elements of the x vector
n=length(x);
med=sum(x)/n;
devst=sqrt(sum((x-med).^2)/n);
The file must be saved using the same name as the function ( stat.m) .
Example:
>>cd d:\sc
>>help stat
>>x=[1 2 3 4 5 6 7];
>>[med,devst]=stat(x)
Note: see if, for, while commands which are very useful in the implementation of an algorithm.
The SIMULINK module allows the modeling, the simulation and the time domain analysis of a block diagram.
The file must be saved as model_name.mdl.