Angel Record
Angel Record
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sawtooth wave');
%PROGRAM for Triangular wave
t=0:.0001:20;
y=sawtooth(t,.5); % sawtooth with 50% duty cycle(triangular)
subplot(3,3,5);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Triangular waveform');
%PROGRAM for Sinc Pulse
t=-10:.01:10;
y=sinc(t);
axis([-10 10 -2 2]);
subplot(3,3,6)
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time Index');
title('Sinc Pulse');
% PROGRAM for Exponential Growing signal
t=0:.1:8;
a=2;
y=exp(a*t);
subplot(3,3,7);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index'); title('Exponential growing Signal');
clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);
OUTPUT:
clc;
close all;
clear all;
x=input('Enter x: ');
h=input('Enter h: ') ;
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
stem(Y);
disp(Y);
ylabel('Y[n]');
xlabel('----->n') ;
title('Convolutio n of Two Signals without conv function');
INPUT:
Enter x: [1 2 3 4 5]
x=12345
Enter h: [1 2 3 1]
h=1231
Y = 1 4 10 17 24 25 19 5
OUTPUT:
PROGRAM:
clc;
clear all ;
close all;
a = input('Enter the sequence x(n) = ');
b = input('Enter the sequence h(n) = ');
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-1))];
for i = 1:N
k = i;
for j = 1:n2
H(i,j)=x(k)*b(j);
k = k-1;
if(k == 0)
k = N;
end
end
end
y=zeros(1,N);
M=H';
for j = 1:N
for i = 1:n2
y(j)=M(i,j)+y(j);
end
end
disp('The output sequence is y(n)=');
disp(y);
stem(y);
title('Circular Convolution');
xlabel('n');
ylabel('y(n)');
INPUT:
x(n) = 1 2 3 4
h(n) = 1 2 1 1
14 11 12 13
OUTPUT:
PROGRAM : (Spectrum Analysis Using DFT)
clc;
clear all ;
close all;
N=input('type length of DFT= ');
T=input('type sampling period= ');
freq=input('type the sinusoidal freq= ');
k=0:N-1;
f=sin(2*pi*freq*1/T*k);
F=fft(f);
stem(k,abs(F));
grid on;
xlabel('k');
ylabel('X(k)');
Output:
(Spectrum Analysis Using DFT)
Type length of dft=32
Type sampling period=64
Type the sinusoidal freq=11
PROGRAM : (Rectangular Window)
clc;
clear all ;
close all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB ripple fp =');
fs=input('Enter the SB ripple fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=boxcar(n1);
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
xlabel('Normalized frequency------>'); ylabel('Gain in db--------.');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('Gain in db--------.');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
xlabel('Normalized frequency------
>');
ylabel('Gain
in db--------.');
Output:
Output:
PROGRAM : (Chebyshev Type 1 Band pass Filter)
clc;
clear all ;
close all;
alphap=2; %pass band attenuation in dB
alphas=20; %stop band attenuation in dB
wp=[.2*pi,.4*pi];
ws=[.1*pi,.5*pi];
%To find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn); w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
grid;
ylabel('Gain in dB..');
xlabel('Normalised frequency..');
subplot(2,1,2);
plot(ph/pi,an);
grid;
ylabel('Phase in radians..');
xlabel('Normalised frequency..');
Output: (Chebyshev Type 1 Band pass Filter)
PROGRAM : (Chebyshev Type II Band Reject Filter)
clc;
clear all ;
close all;
alphap=2;
alphas=20;
ws=[.2*pi,.4*pi];
wp=[.1*pi,.5*pi];
[n,wn]=cheb2ord(wp/pi,ws/pi,alphap,alphas);
[b,a]=cheby2(n,alphas,wn,'stop');
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
grid;
ylabel('Gain in dB..');
xlabel('Normalised frequency..');
subplot(2,1,2);
plot(ph/pi,an);
grid;
ylabel('Phase in radians..');
xlabel('Normalised frequency..');
Output: (Chebyshev Type II Band Reject Filter)
PROGRAM : (Multirate Filters)
clc;
clear all ;
close all;
N =31; % Filter length
Nord = N-1; % Filter order
L = 3;
ro1 = 0.2; % Roll-off factor
h1 = firnyquist(Nord,L,ro1); % Filter design
ro2 = 0.4; % Roll-off factor
h2 = firnyquist(Nord,L,ro2); % Filter design
ro3 = 0.6; % Roll-off factor
h3 = firnyquist(Nord,L,ro3); % filter design
figure (1)
subplot(3,1,1)
stem(0:N-1,h1,'b')
axis([0,30,-0.2,0.5])
ylabel('h_1[n]')
title('Figure 1')
legend('h1')
subplot(3,1,2)
stem(0:N-1,h2,'k')
axis([0,30,-0.2,0.5])
ylabel('h_2[n]')
legend('h2')
subplot(3,1,3)
stem(0:N-1,h3,'r')
axis([0,30,-0.2,0.5])
xlabel('n')
ylabel('h_3[n]')
legend('h3')
% Computing frequency responses
[H1,f] = freqz(h1,1,256,2);
[H2,f] = freqz(h2,1,256,2);
[H3,f] = freqz(h3,1,256,2); figure (2)
plot(f,abs(H1),'b',f,abs(H2),'k',f,abs(H3),'r'),
grid title ('Figure 2')
axis([0,1,0,1.1])
xlabel('\omega/\pi')
ylabel('Magnitude')
legend('|H_1(e^j^\omega)|','|H_2(e^j^\omega)|','|H_3(e^j^ \omega)|')
Output:
PROGRAM : (Multirate Filters)
clc;
clear all ;
close all;
M=3000;
T=2000;
dB=25;
L=20;
ChL=5;
EqD=round((L+ChL)/2);
Ch=randn(1,ChL+1)+sqrt(-1)*randn(1,ChL+1);
Ch=Ch/norm(Ch);
TxS=round(rand(1,M))*2-1;
TxS=TxS+sqrt(-1)*(round(rand(1,M))*2-1);
x=filter(Ch,1,TxS);
n=randn(1,M);
n=n/norm(n)*10^(-dB/20)*norm(x);
x=x+n; K=M-L;
X=zeros(L+1,K);
for i=1:K
X(:,i)=x(i+L:-1:i).';
end
e=zeros(1,T-10);
c=zeros(L+1,1);
mu=0.001;
for i=1:T-10
e(i)=TxS(i+10+L-EqD)-c'*X(:,i+10);
c=c+mu*conj(e(i))*X(:,i+10);
end
sb=c'*X;
sb1=sb/norm(c);
sb1=sign(real(sb1))+sqrt(-1)*sign(imag(sb1));
start=7;
sb2=sb1-TxS(start+1:start+length(sb1));
SER=length(find(sb2~=0))/length(sb2);
disp(SER);
subplot(2,2,1),
plot(TxS,'*');
grid,title('Input symbols'); xlabel('realpart'),
ylabel('imaginary part')
axis([-2 2 -2 2])
subplot(2,2,2),
plot(x,'o');
grid, title('Received samples'); xlabel('real part'),
ylabel('imaginary part')
subplot(2,2,3),
plot(sb,'o');
grid, title('Equalized symbols'),
xlabel('real part'),
ylabel('imaginary part')
subplot(2,2,4),
plot(abs(e));
grid, title('Convergence'),
xlabel('n'),
ylabel('error signal')
Output:
PROGRAM (Linear Convolution)
#include<stdio.h>
int m=6;
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int y[20];
main()
{
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d \n",y[i]);
}
OUTPUT: (Linear Convolution)
4 10 20 35 56 70 76 73 60 36
PROGRAM :(Circular Convolution)
#include<stdio.h>
int
m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("enter the length of the 1st sequence\n");
scanf("%d",&m);
printf("enter the length of the second sequence\n"); scanf("%d",&n);
printf("enter the 1st sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}