Professional Documents
Culture Documents
t=0:.30:10;
x=sin(t);
y=cos(t);
subplot(2,2,1),plot(t,x)
title('sine continuous')
xlabel('time')
ylabel('amplitude')
grid
subplot (2,2,2),stem(t,x)
title('sine discrete')
xlabel('time')
ylabel('amplitude')
subplot(2,2,3),plot(t,y)
title('cos continuous')
xlabel('time')
ylabel('amplitude')
grid
subplot (2,2,4),stem(t,y)
title('cos discrete')
xlabel('time')
ylabel('amplitude')
Convolution of two Sequences
magnitude response
0
-100
gain in db
-200
-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
phase response
4
phase in radian
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
ChebyShev Type II Band Stop Filter
magnitude response
50
0
gain in db
-50
-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
phase response
4
phase in radian
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
DFT and IDFT of a given sequence
0.5
amplitude
amplitude
0.5 0
-0.5
0 -1
1 1.5 2 2.5 3 1 1.5 2 2.5 3
time index time index
magnitude plot angle plot
3 2
1
2
amplitude
amplitude
0
1
-1
0 -2
0 2 4 6 8 0 2 4 6 8
time index time index
input sequence magnitude input sequence angle
6 1
0.5
amplitude 4
amplitude
0
2
-0.5
0 -1
0 2 4 6 8 0 2 4 6 8
time index time index
magnitude plot angle plot
1 1
0.5
amplitude
amplitude
0.5 0
-0.5
0 -1
0 2 4 6 8 0 2 4 6 8
time index time index
%program for 20 point moving average filter
t=0:.001:1;
f=1; %frequency of sine wave
y=sin(2*pi*f*t);
%generation of random signal
g=0.5*rand(size(t));
z=g+y;
n=20;%order of the filter
b=1/n.*(ones(1,n));
x=filter(b,1, z);%filter noise
subplot(3,1,1);plot(t,y);ylabe l('pure signal');
subplot(3,1,2);plot(t,z);ylabel('noise burried signal');
subplot(3,1,3);plot(t,x);ylabel('filtered signal');
xlabel('time in seconds');
CIRCULAR CONVOLUTION
function f= circonv(a,b)
a=input('enter the first sequence');
b=input('enter the second sequence');
N1=length(a);
N2=length(b);
N=max(N1,N2);
a=[a zeros(1,N-N1)];
b=[b zeros(1,N-N2)];
for n = 0:N-1
f(n+1)=0;
for i=0:N-1
j=mod(n- i,N);
f(n+1)=f(n+1)+a(i+1)*b(j+1);
end;
end;
subplot(2,2,1);stem(a);xlabel('time inde x');ylabel('amplitude');
subplot(2,2,2);stem(b);xlabel('time index');ylabel('amplitude');
subplot(2,1,2 );stem(f);xlabel('time index');ylabel('amplitude');
title('circular convolution');
FREQUENCY MODULATION
fc=inp ut('enter the carrier frequency in hz');
fm=input('enter the mod ulating frequency in hz');
m=inp ut ('enter the mod ulation inde x');
t=0:.0001:1;
C=sin(2*pi*fc*t);
M=sin(2*p i*fm*t);
Y=sin((2*pi*fc*t)-(m*M));
subplot(3,1,1);plot(t,M);axis([0 1 -1.5 1.5]);
title('modulating signal');xlabel('time');ylabel('amplitude');
subplot(3,1,2);plot(t,C);axis([0 1 -1.5 1.5]);
title('carrier signa l');xlabel('time');ylabel('amplitude');
subplot(3,1,3);plot(t,Y);axis([0 1 -1.5 1.5]);
xlabel('time');ylabel('amplitude');title('FM signal');
FIR FILTER USING VARIOUS WINDOWS
f=input('sampling rate in HZ');
fp= inp ut('enter pass ba nd edge frequency in HZ');
fs=input('enter stop ba nd e dge freque ncy in HZ');
rp=input('passband ripple in dB');
rs=input('enter minimum stop ba nd attenuation in dB');
wp=2*fp/f;
ws=2* fs/f;
[N,wn]=cheb1ord(wp,ws,rp,rs);
%HANN WINDOW
Hw=hann(N+1);
B=fir1(N,wn,Hw);
[H, omega]=freqz(B,1,256);
gain=20*log(abs(H));
subplot(2,2,1);plot(omega/pi,gain);grid;
xlabel('normalised frequency');ylabel('gain(dB)');
title('FIR LPF using HANN window');
%HAMMING WINDOW
Hw=hamming(N+1);
B=fir1(N,wn,Hw);
[H, omega]=freqz(B,1,256);
gain=20*log(abs(H));
subplot(2,2,2);plot(omega/pi,gain);grid;
xlabel('normalised frequency');ylabel('gain(dB)');
title('FIR LPF using HAMMING windo w');
%RECTANGULAR WINDOW
Hw=rectwin(N+1);
B=fir1(N,wn,Hw);
[H, omega]=freqz(B,1,256);
gain=20*log(abs(H));
subplot(2,2,3);plot(omega/pi,gain);grid;
xlabel('normalised frequency');ylabel('gain(dB)');
title('FIR LPF using RECTANGULAR window');
%TRIANGULAR WINDOW
Hw=triang(N+1);
B=fir1(N,wn,Hw);
[H, omega]=freqz(B,1,256);
gain=20*log(abs(H));
subplot(2,2,4);plot(omega/pi,gain);grid;
xlabel('normalised frequency');ylabel('gain(dB)');
title('FIR LPF using TRIANGULAR window');
AUTOCORRELATION AND CROSSCORRELATION