Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
77 views

SSDSP Matlab Scripts

This document contains MATLAB scripts for signal processing functions like addition, multiplication, convolution, Fourier transform, filtering, and more. Each function is documented to show the input and output signals and parameters. The scripts are part of a lab course on signals, systems and digital signal processing taught by Dr. Nikolaos Asimakis.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

SSDSP Matlab Scripts

This document contains MATLAB scripts for signal processing functions like addition, multiplication, convolution, Fourier transform, filtering, and more. Each function is documented to show the input and output signals and parameters. The scripts are part of a lab course on signals, systems and digital signal processing taught by Dr. Nikolaos Asimakis.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

ΤΕΧΝΟΛΟΓΙΚΟ ΕΚΠΑΙΔΕΥΤΙΚΟ ΙΔΡΥΜΑ (Τ.Ε.Ι.

) ΣΤΕΡΕΑΣ ΕΛΛΑΔΑΣ
ΣΧΟΛΗ ΤΕΧΝΟΛΟΓΙΚΩΝ ΕΦΑΡΜΟΓΩΝ
ΤΜΗΜΑ ΗΛΕΚΤΡΟΝΙΚΩΝ ΜΗΧΑΝΙΚΩΝ Τ.Ε.

ΣΗΜΑΤΑ, ΣΥΣΤΗΜΑΤΑ ΚΑΙ ΨΗΦΙΑΚΗ ΕΠΕΞΕΡΓΑΣΙΑ ΣΗΜΑΤΩΝ


ΕΡΓΑΣΤΗΡΙΟ

Δρ. ΑΣΗΜΑΚΗΣ ΝΙΚΟΛΑΟΣ

MATLAB SCRIPTS

function [y,n]=sigadd(x1,n1,x2,n2)
% addition
% y(n)=x1(n)+x2(n)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1+y2;

function [rex,imx,mx,fx,n]=sigcexp(r,w,n1,n2)
% complex exp signal
% r^n*exp(jwn)=(r^n)*{cos(wn)+jsin(wn)} n=n1..n2
n=[n1:n2];
mx=r.^n;
fx=w*n;
rex=mx.*cos(w*n);
imx=mx.*sin(w*n);

function [y]=sigcirconv(x1,x2,N)
% circular convolution
% y(n)=x1(n) N x2(n)
x1=[x1 zeros(1,N-length(x1))];
x2=[x2 zeros(1,N-length(x2))];
m=[0:1:N-1];
x2=x2(mod(-m,N)+1);
H=zeros(N,N);
for n=1:1:N
H(n,:)=sigcirshift(x2,n-1,N);
end;
y=x1*H';

function [y]=sigcirshift(x,m,N)
% circural shift
% x(n) of length N
% y(n) = x((n-m))N
x=[x zeros(1,N-length(x))];
n=[0:1:N-1];
n=mod(n-m,N);
y=x(n+1);

function [y,ny]=sigconv(x,nx,h,nh)
% linear convolution
% y(n)=x(n)*h(n)
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
y=conv(x,h);
Ν. ΑΣΗΜΑΚΗΣ ΣΗΜΑΤΑ, ΣΥΣΤΗΜΑΤΑ ΚΑΙ ΨΕΣ 1
function [Xk]=sigdft(xn,N)
% DFT
% x(n) -- X(k)
% N = length of x(n)
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=xn*WNnk;

function [xe,xo,m]=sigevenodd(x,n)
% even and odd parts signal decomposition
if any (imag(x)~=0)
error('x is not a real sequence')
end
m=-fliplr(n);
m1=min([m,n]);
m2=max([m,n]);
m=m1:m2;
nm=n(1)-m(1);
n1=1:length(n);
x1=zeros(1,length(m));
x1(n1+nm)=x;
x=x1;
xe=0.5*(x+fliplr(x));
xo=0.5*(x-fliplr(x));

function [y,n]=sigfold(x,n)
% fold
% y(n)=x(-n)
y=fliplr(x);
n=-fliplr(n);

function [db,mag,pha,grd,w]=sigfreqzm(b,a)
% freqz version
% frequency response
[H,w]=freqz(b,a,1000,'whole');
H=(H(1:1:501))';
w=(w(1:1:501))';
mag=abs(H);
db=20*log10((mag+eps)/max(mag));
pha=angle(H);
grd=grpdelay(b,a,w);

function [rex,imx,mx,fx,n]=sigiexp(w,n1,n2)
% imaginary exp signal
% exp(jwn)=cos(wn)+jsin(wn) n=n1..n2
n=[n1:n2];
rex=cos(w*n);
imx=sin(w*n);
mx=1.^n;
fx=w*n;

Ν. ΑΣΗΜΑΚΗΣ ΣΗΜΑΤΑ, ΣΥΣΤΗΜΑΤΑ ΚΑΙ ΨΕΣ 2


function hi=sigilp(w,N)
% Ideal Low Pass Filter
% w = cutoff frequency
% N = Ideal Low Pass Filter length
% hi = Ideal Impulse Responce in time [0..N-1]
a=(N-1)/2;
n=[0:N-1];
m=n-a+eps;
hi=sin(w*m)./(pi*m);

function [x,n]=sigimp(n0,n1,n2)
% impulse signal
% d(n-n0) n=n1..n2
n=[n1:n2];
x=[(n-n0)==0];

function [y,n]=sigmult(x1,n1,x2,n2)
% multiplication
% y(n)=x1(n)x2(n)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;

function [x,n]=sigrexp(r,n1,n2)
% real exp signal
% r^n n=n1..n2
n=[n1:n2];
x=r.^n;
function [y]=sigscaldiv(c,x)
% frequency division
% x(n) n=1:l
% y(n)=x(cn)
% c>1
nl=length(x);
m=floor(nl/c);
for i=1:m
y(i)=x(i*c);
end;

function [y]=sigscalmul(c,x)
% frequency multiplication
% x(n) n=1:l
% y(n)=x(n/c)
% c>1
nl=length(x);
m=nl*c;
for i=1:m
y(i)=0;
if mod(i,c)==0
y(i)=x(i/c);
end;
end;

function [y,n]=sigshift(x,m,n0)
Ν. ΑΣΗΜΑΚΗΣ ΣΗΜΑΤΑ, ΣΥΣΤΗΜΑΤΑ ΚΑΙ ΨΕΣ 3
% shift
% y(n)=x(n-n0)
n=m+n0;
y=x;

function [x,n]=sigsin(w,f,n1,n2)
% sinusoidal signal
% x(n)=sin(w*n+f) n=n1..n2
n=[n1:n2];
x=sin(w.*n+f);

function [x,n]=sigstep(n0,n1,n2)
% step signal
% u(n-n0) n=n1..n2
n=[n1:n2];
x=[(n-n0)>=0];

Ν. ΑΣΗΜΑΚΗΣ ΣΗΜΑΤΑ, ΣΥΣΤΗΜΑΤΑ ΚΑΙ ΨΕΣ 4

You might also like