Академический Документы
Профессиональный Документы
Культура Документы
[y,t]=impsignal(-1,12,0);
%it is necessary to save impulseseq function as "impulseseq.m" in
your
%directory where you installed a MATLAB. Otherwise it will give
you
%error......
stem(t,y,'^')
title('impulse signal infinity at 0[13-EE-33');
Figure:
Program:
function [y,n]=stepseq(n1,n2,n0)
% n1 &n2 is length of n in x-axis
% n0 is delay
n=n1:n2;
y=[(n-n0)>=0];
end
Now plot of sequence
[y,n]=stepseq(-3,4,2);
stem(n,y)
xlabel('n');
ylabel('amplitude');
title('unit step sequence[12-EE-33]');
FIGURE:
[x,t]=singeneration(5,60);
%f=60Hz & amplitude=10V
%it is necessary to save singeneration function as
"singeneration.m" in your
%directory where you installed a MATLAB. Otherwise it
will give you
%error......
plot(t,x)
xlabel('time(second)');
ylabel('amplitude(V)');
title('sine wave[13-EE-33]');
zoom xon;
Figure
sine wave[13-EE-33]
5
4
3
amplitude(V)
2
1
0
-1
-2
-3
-4
-5
0.005
0.01
0.015
time(second)
0.02
0.025
Program:
function [y,time]=cosgeneration(A,f)
% A is amplitude ...
%f is frequency of sin wave...
fs=8000;
%frequency per sample
dt=1/fs;
%time per sample
st=0.025 ;
%stop time
time=0:dt:st-dt;
F=f;
y=A*cos(2*pi*F*time);
end
Now we plot a wave given below:
[y,t]=cosgeneration(3,60);
%f=60Hz & amplitude=5V
%it is necessary to save singeneration function as
"singeneration.m" in your
%directory where you installed a MATLAB. Otherwise it
will give you
%error......
plot(t,y)
xlabel('time(second(s))');
ylabel('amplitude(Volt)');
title('cos wave[13-EE-33]');
zoom xon;
Figure:
%dutycycle=40%
& Amplitude
Figure
function [x,n]=rampseq(n1,n2,n0)
% n1 &n2 is length of n in x-axis
% n0 is delay
n=n1:n2;
k=n2-n1+1;
m=n1;
if(n0>1)
for i=n0+1:k
if(m<=0)
x(i)=0;
else
x(i)=m;
end
m=m+1;
end
end
if(n0<=1)
for j=1:k
if(m<=0)
x(j)=0;
else
x(j)=m;
end
m=m+1;
end
end
end
Now we will plot ramp sequence AS given:
[x,n]=rampseq(-5,45,0);
% n1=-1 & n2= 6 is length of n in x-axis
% n0= 0 is delay
%it is necessary to save rampseq function as
"rampseq.m" in your
%directory where you installed a MATLAB.
Otherwise it will give you
%error......
stem(n,x,'filled,r')
xlabel('n');
ylabel('Amplitude');
title('ramp sequence[13-EE-33]');
Figure:
LAB
0.25 sec
B)
0.5 sec
C)
1.0 sec
t=0:0.25:10;
ta=0:0.5:10;
tb=0:1:10;
y=sin(t);y1=sin(ta);y2=sin(tb);
subplot(2,2,1);
plot(t,y,'m');
xlabel('time');
ylabel('sine function ');
title('original signal[13-EE-33]');
subplot(2,2,2);
stem(t,y,'b');
xlabel('time');
ylabel('sine function');
title('sampling at t=0.25[13-EE-33]');
subplot(2,2,3);
stem(ta,y1,'m');
xlabel('time');
ylabel('sine function');
title('sampling at t=0.5[13-EE-33]');
subplot(2,2,4);
stem(tb,y2,'filled');
title('sampling at t=1[13-EE-33]');
xlabel('time');
ylabel('sine function ');
Figure:
LAB No.8:
Program:
n=20:100;
char('OK');
f = input('select frequency: (f=0,1/6,1/8,1/4,1/2,1/sqrt(5):');
%after running program pleas open commond window to select frequency:
%after this window will ask you to here sound press 'OK' insted of just OK.
if(f==0 || f==1/6 || f==1/8 || f==1/4 || f==1/2 || f==1/sqrt(5))
if(f==0)
x2= cos(2*pi*0*n);
stem(n,x2);
xlabel('n');
ylabel('cose function');
title('sampling signal');
C=input('To plot OR to here sound of original signal enter OK:');
s1 = strcmp(C,tf);
if(s1==1)
close ;
x1=cos(2*pi*f*t);
subplot(1,2,1);
plot(t,x1,'g');
xlabel('t');
ylabel('cos function');
title('original signal');
[autocor,lags] = xcorr((cos(2*pi*f*t)),'coeff');
subplot(1,2,2);
plot(lags,autocor)
xlabel('Lag ')
ylabel('Autocorrelation')
title('signal to check predocity');
axis([-21 21 -0.4 1.1])
sound(x1);
end
end
if(f==1/6)
x2= cos(2*pi*1/6*n);
stem(n,x2);
xlabel('n');
ylabel('cose function');
title('samlipling signal at f=1/6');
C=input('To plot OR to here sound of original signal enter OK:');
s1 = strcmp(C,tf);
if(s1==1)
close ;
x1=cos(2*pi*f*t);
subplot(1,2,1);
plot(t,x1,'g');
xlabel('t');
ylabel('cos function');
title('original signal');
[autocor,lags] = xcorr((cos(2*pi*f*t)),'coeff');
subplot(1,2,2);
plot(lags,autocor)
xlabel('Lag ')
ylabel('Autocorrelation')
title('signal to check predocity[13-EE-33]');
axis([-21 21 -0.4 1.1])
sound(x1);
end
end
if(f==1/8)
x2= cos(2*pi*1/8*n);
stem(n,x2);
xlabel('n');
ylabel('cose function');
title('samlipling signal f=1/8');
C=input('To plot OR to here sound of original signal enter OK:');
s1 = strcmp(C,tf);
if(s1==1)
close ;
x1=cos(2*pi*f*t);
subplot(1,2,1);
plot(t,x1,'g');
xlabel('t');
ylabel('cos function');
title('original signal');
[autocor,lags] = xcorr((cos(2*pi*f*t)),'coeff');
subplot(1,2,2);
plot(lags,autocor)
xlabel('Lag ')
ylabel('Autocorrelation')
title('signal to check predocity');
axis([-21 21 -0.4 1.1])
sound(x1);
end
end
if(f==1/4)
x2= cos(2*pi*1/4*n);
stem(n,x2);
xlabel('n');
ylabel('cose function');
title('samlipling signal f=1/4');
C=input('To plot OR to here sound of original signal enter OK:');
s1 = strcmp(C,tf);
if(s1==1)
close ;
x1=cos(2*pi*f*t);
subplot(1,2,1);
plot(t,x1,'g');
xlabel('t');
ylabel('cos function');
title('original signal');
[autocor,lags] = xcorr((cos(2*pi*f*t)),'coeff');
subplot(1,2,2);
plot(lags,autocor)
xlabel('Lag ')
ylabel('Autocorrelation')
title('signal to check predocity[13-ee-33]');
axis([-21 21 -0.4 1.1])
sound(x1);
end
end
if(f==1/2)
x2= cos(2*pi*1/2*n);
stem(n,x2);
xlabel('n');
ylabel('cose function');
RESULTS:
By entering f=1/4 we have output of sampled signal and continuous time signal.
And we also determine the periodicity of signal using correlation method.
By entering OK
Clearly signal is periodic at right hand side of plotted figure. For each frequency
sound is heard.
LAB No.9: Continue by adding the signals
x1(n)= cos(2f1n) and x2(n)=Cos (2f2n) in a vector of length 8192 with the
adjacent frequencies f1 =1/81/8192 and f2 =1/8+1/8192. Listen and plot and
rewrite your program using the results from Lab 02. Then, listen only to x1(n).
Change the frequency f1 =1/2 1/8192 and listen again. Can you explain the
beating effect although there is only one cosine???
Program:
n1n=0:8192;
f=1/8-1/8192;
f2=1/8+1/8192;
x1=cos(2*pi*f*n1n);
x2=cos(2*pi*f2*n1n);
subplot(2,2,1);
plot(n1n,x1,'k');
xlabel('time(t)');
ylabel('cose signal');
title('signal with frequency 2*(1/8-1/8192)[13-EE-33]');
subplot(2,2,2);
plot(n1n,x2,'g');
xlabel('time(t)');
ylabel('cos signal');
title('signal with frequency 2*(1/8-1/8192)');
subplot(2,2,3);
y=x1+x2;
% sum of signal by 'k'
plot(n1n,y,'b');
xlabel('time(t)');
ylabel('cos signal');
title('signal with addation of x1,x2)[13-EE-33]');
x3=cos(2*pi*(1/2-1/8192)*n1n);
subplot(2,2,4);
plot(x3);
xlabel('time(t)');
ylabel('cos signal');
title('signal with frequency (1/2-1/81``)');
% play(recObj);
% tic;
% while toc < 3
% end
sound(x1);
% tic;
% while toc < 2
% end
%play(recObj1);
tic;
while toc < 5
end
sound(y);
% while toc < 7
% end
% play(recObj2);
tic;
while toc <3
end
sound(x3);
Output figure:
LAB No.10: Generate a sequence x (n) = 1+cos (2f0n) of 8192 samples with f0
=0.0625. Let a filter calculate the 1st deference, i.e. Y (n) = x (n) x (n 1). Use
loops for. end or use subtraction with two vectors. Study the signal and explain the
result. What is the impulse response of the system calculating the 1st deference? Is
it causal?? Stable??
Program:
fo=0.0625;
n=1:8192;
x_n=1+cos(2*pi*fo*n);
x=[1 0 0 0 0 0 0 0 0 0 ];
for n=2:10
h(n)=x(n)-x(n-1);
end
subplot(2,1,1)
stem(x_n(1:10),'filled');
title('SEQUENCE OF SAMPLES[13-EE-33]')
subplot(2,1,2)
stem(h(2:10),'b');
FIGURE:
x=[1 2 3 4 5];
h=[1 3 2];
convy= conv(h,x);
corrk= xcorr(h,x);
subplot(2,2,1)
plot(convy,'k');
subplot(2,2,3)
plot(corrk,'m');
subplot(2,2,2)
stem(corrk,'c');
subplot(2,2,4)
stem(corrk,'c');
Figure