MATLAB CODE TO DESIGN A CHEBYSHEV I LOWPASS FILTER

CODE:


clear all
alphap=1;  %passband attenuation in dB
alphas=15; %stopband attenuation in dB
wp=.2*pi; % passband freq. in radians
ws=.3*pi; % stopband freq. in radians
%to find cutoff freq. and order of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas); %syatem function of the filter
[b,a]=cheby1(n,alphap,wn);

MATLAB CODE TO DESIGN A ELLIPTICAL LOW PASS FILTER

CODE:



clc;
clear all;
N = input('Order = ');
Fp = input('Passband edge frequency in Hz = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation in dB = ');
% Determine the coefficients of the transfer function
[num,den] = ellip(N,Rp,Rs,2*pi*Fp,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');


MATLAB CODE TO DESIGN A BUTTERWORTH BAND REJECT FILTER

CODE:

clear all
alphap=2;  %passband attenuation in dB
alphas=20; %stopband attenuation in dB
wp=[.2*pi,.4*pi]; % passband freq. in radians
ws=[.1*pi,.5*pi]; % stopband freq. in radians
%to find cutoff freq. and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas) %syatem function of the filter
[b,a]=butter(n,wn,'STOP')
w=0:.01:pi;

MATLAB CODE TO DESIGN A BUTTERWORTH HIGHPASS FILTER

CODE:
clear all
alphap=.4;  %passband attenuation in dB
alphas=30; %stopband attenuation in dB
fp=400; %passband freq. in hz
fs=800; %stopband freq. in hz
F=2000; %sampling freq. in hz
omp=2*fp/F;oms=2*fs/F; % To find cutoff freq. and order of the filter

MATLAB CODE TO DESIGN A BUTTERWORTH BANDPASS FILTER

CODE:
clear all
alphap=2;  %passband attenuation in dB
alphas=20; %stopband attenuation in dB
wp=[.2*pi,.4*pi]; % passband freq. in radians
ws=[.1*pi,.5*pi]; % stopband freq. in radians
%to find cutoff freq. and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas) %syatem function of the filter

MATLAB CODE TO DESIGN A BUTTERWORTH LOWPASS FILTER

CODE:


clear all
alpha=.4;  %passband attenuation in dB
alphas=30; %stopband attenuation in dB
fp=400; %passband freq. in hz
fs=800; %stopband freq. in hz
F=2000; %sampling freq. in hz
omp=2*fp/F;oms=2*fs/F; % To find cutoff freq. and order of the filter
[n,wn]=buttord(omp,oms,alpha,alphas) %syatem function of the filter
[b,a]=butter(n,wn)
w=0:.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=abs(h);
an=angle(h);
subplot(2,1,1);plot(om/pi,20*log(m));grid;
ylabel('gain in dB');
Xlabel('NORMALISED FREQUENCY')
subplot(2,1,2);plot(om/pi,an);grid
ylabel('phase in radians')
xlabel('noramlised frequency')


OUTPUT:



n =4
wn =0.5821
b =  0.1518    0.6073    0.9109    0.6073    0.1518
a =1.0000    0.6418    0.6165    0.1449    0.0259
 


Matlab code for Computation of Linear convolution with DFT

Code:


clc;
clear all;
g=input('Type in the first sequence:');
h=input('Type in the second sequence:');
ga=[g zeros(1,length(h)-1)];
ha=[h zeros(1,length(g)-1)];
G=fft(ga);
H=fft(ha);
Y=G.*H;

MATLAB CODE TO FIND OUT THE DFT & IDFT THEN PLOT MANITUDE AND PHASE RESPONSE OF IT

CODE:
clc;
clear all;
close all;
x=input('enter the data sequence');
N=input('enter the N point DFT');
fs=input('enter the sample freq.');
Y=fft(x,N)                       %this will give DFT
f=fs/N;
G=ifft(Y,N)                      %this will give IDFT
z=0:f:((length(Y)-1)*f);          %freq vextor for the x axis

MATLAB CODE TO FIND OUT THE FREQUENCY AND PHASE RESPONSE

CODE:

clc;
clear all;
a=input('Enter the values for numerator : ');
b=input('Enter the values for denomator : ');
t = tf(a,b,0.1) %give transfer function in Z domain

freqz(a,b); % give freq as well as phase response

OUTPUT:

Enter the values for numerator : [1 2 3]
Enter the values for denomator : [4 5 6]
 Transfer function:
 z^2 + 2 z + 3
---------------
4 z^2 + 5 z + 6
 Sampling time: 0.1



Matlab code for Addition of the signals frequnecy and amplitude value will be enter by user

Code:


clc;
clear all;
close all;
n=input('enter the no. of freq components :');
a=input('enter the amplitude matrix :');
f=input('enter the freq matrix :');
fs=input('enter the sampling frequency :');
disp(a); % display the amplitude componenets
disp(f); % display the frequency componenets
for i=1:1:n
    if (i+1)>n
        break;
    end
       if f(1,i)>f(1,i+1)
           f(1,i+1)=f(1,i); %find outthe maxium freq components
       end  
end
if fs<(2*f(1,n)) %check out the sampling theroem (fs>=2fm)
    fs=input('The fs entered was unadequate. Plz enter the required sampling frequency :');
end
z=0:(.1*fs):fs;
for i=1:1:n  %display the each cosine signal
    x=a(1,i)*cos(2*pi*(z/fs)*f(1,i));
    subplot(n+1,1,i);
    stem(z,x);
    grid on;
    hold on;
end
x=0;
for i=1:1:n  %addition of all signals
    x=(a(1,i)*cos(2*pi*(z/fs)*f(1,i)))+x;
    subplot(n+1,1,n+1);
    stem(z,x);
    grid on;
end


Output:


enter the no. of freq components :4
enter the amplitude matrix :[1 2 1 2]
enter the freq matrix :[5 6 7 5]
enter the sampling frequency :12
     1     2     1     2     5     6     7     5
The fs entered was unadequate. Plz enter the required sampling frequency :16