This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
PROGRAM1To compute & plot the convolution of the sequences x(n) & y(n) using DFT & IDFT where x(n)=[3 4 2 11 0 7 -1 10 3] & h(n)=[1.2 3.7 4.8]
x=[3 4 2 11 0 7 -1 10 3];h=[1.2 3.7 4.8];
xlen=length(x); %find the length of sequencehlen=length(h);ylen=xlen+hlen-1; % compute the resulting length of output sequenceN=ylen;xk=fft(x,N); % compute the DFTs of x[n] & y[n]hk=fft(h,N);yk=xk.*hk; % Note the use of '.*' -> Vector multiplicationy=ifft(yk); % convolution o/pstem(y);figure(1);
To compute & plot the sequence x(n) & y(n) using 9 point DFT & IDFT where x(n)=[3 4 2 11 0 7 -1 10 3] & h(n)=[1.2 3.7 4.8] (example of circular convolution which is linear convolution with aliasing)
To plot the magnitude & phase response of IIR filter described by transfer equation y(n)=0.8y(n-1) + 0.2x(n)
b=[0.2];a=[1 -0.8];%finding the frequency response[h,w]=freqz(b,a,128);%plotting the mag responsefigure(1)plot(w,abs(h));%plotting the phase responsefigure(2)plot(w,angle(h));
PROGRAM 6 – WAVEFORM 1
PROGRAM 6 – WAVEFORM 2
PROGRAM 7
Design of a second order butterworth filter with cutoff frequency
[a,b]=butter(2,0.2)%finding the frequency response[h,w]=freqz(a,b,512);%plotting the mag responsefigure(1)plot(w,abs(h))%plotting the phase responsefigure(2)plot(w,angle(h))
PROGRAM 7 – WAVEFORM 1-magnitude response
PROGRAM 7 – WAVEFORM 2-phase response
Design and implementation of IIR filter to meet given specifications
• [N, Wn] = BUTTORD(Wp, Ws, Rp, Rs)returns the order N of the lowest order digital
• [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator).
MATLAB PROGRAM FOR IIR FILTERGeneration of input sequencesc=3; % eg of 3 frequenciesf(1)=20; f(2)=8;f(3)=35;fs=100; % sampling frequenciesn=1:20; % 20 sampless=[ ];s1=[ ];for i=1:c % sine waves1=sin(2*3.14*n*f(i)/fs); % appending the 3 frequenciess=[s s1]; end% figure of input sequencesfigure(1)stem(s) title(input)
YulewalkAlgorithm Yulewalk performs a least-squares fit in the time domain. It computes
the denominator coefficients using modified Yule-Walker equations, with correlation coefficients computed by inverse Fourier transformation of the specified frequency response.
To compute the numerator, yulewalk takes the following steps:• Computes a numerator polynomial corresponding to an additive
decomposition of the power frequency response.• Evaluates the complete frequency response corresponding to the
numerator and denominator polynomials.• Uses a spectral factorization technique to obtain the impulse
response of the filter.• Obtains the numerator polynomial by a least-squares fit to this
impulse response.
Design an 8th-order lowpass filter and overplot the desired frequencyresponse with the actual frequency response:
f = [0 0.6 0.6 1];m = [1 1 0 0];[b,a] = yulewalk(8,f,m);[h,w] = freqz(b,a,128);plot(f,m,w/pi,abs(h),'--')legend('Ideal','yulewalk Designed')title('Comparison of Frequency Response Magnitudes')
Design and implementation of FIR filter to meet given
specifications• B = FIR1(N,Wn) designs an N'th order
lowpass FIR digital filter and returns the filter coefficients in length N+1 vector B.
• [H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter whose numerator and denominator coefficients are in vectors B and A.
MATLAB PROGRAM FOR FIR FILTER%Generation of input sequencesc=3; % eg of 3 frequenciesf(1)=20; f(2)=8;f(3)=35;% sampling frequencyfs=100; n=1:20; % 20 sampless=[ ];s1=[ ];for i=1:c% sine waves1=sin(2*3.14*n*f(i)/fs);% appending the 3 frequenciess=[s s1]; endfigure(1)%stem(s)
% figure of input sequencen1=1:60;plot(n1,s)title('input')
%d=fir1(n,Wc,type) % generate filter co-effs n=order ,Wc=cut off ,type=filter type
Parks-McClellan algorithm• The Remez FIR Filter Design block implements
the Parks-McClellan algorithm to design and apply a linear-phase filter with an arbitrary multiband magnitude response.
• The filter design, which uses the firpm function in Signal Processing Toolbox, minimizes the maximum error between the desired frequency response and the actual frequency response.
• Such filters are called equiripple due to the equiripple behavior of their approximation error.
• The block applies the filter to a discrete-time input using the Direct-Form II Transpose Filter block.
Decimation• Decreases the sampling rate-fs/D • where D-decimation factor• Involves dropping the samples (D-1) without violating the
sampling theorem
Digital Low passfilter (π/D)
DownSampler
X[n]
fs fs Fs/D
Y[n]
MATLAB program to implement Decimation
clear%Generation of input sequencesfs=1000; %Sampling frequencyi=1:60;s=sin(2*pi*i*100/fs); % sine wavefigure(1)n2=1:length(s);plot(n2,s)%stem(s) % figure of input sequencestitle('input')
%d=fir1(n,Wc,type) % generate filter co-effs n=order,%Wc=cut-off,type=filter type%Eg. d=fir1(16, 0.15,blackman(17))%Wc=cut-off=fs/decimation factor %Normalized wc=Wc/fmax where fmax=fs/2df=3; %decimation factorfc=1000/(df*500) %cut off freq of deci filterd=fir1(5,fc);figure(2)stem(d) % filter coeffs graphtitle('filtergraph')
op=conv(d,s); % convolutionfigure(3)stem(op) % filter o/pdecop=[];for i=1:df:65decop=[decop op(i)];endfigure(4)%stem(decop)n=1:length(decop)plot(n,decop) title('decimated output by a factor 3')figure(5);stem(abs(fft(op,256)))
figure(6);stem(abs(fft(decop,256)))title('fft of decimated output')figure(7);stem(abs(fft(s,256)))title('fft of input')
Figures with a decimation filter of order 5 and 15
MATLAB program to implement Decimation
tfinal=0.05;t=0:0.00005:tfinal;fd=input('Enter analog frequency');%define analog signal for comparison xt=cos(2*pi*fd*t);
%simulate condition for undersamplingi.e., fs1<2*fdfs1=1.3*fd; %define the time vectorn1=0:1/fs1:tfinal;%Generate the undersampled signal
xn=cos(2*pi*n1*fd);
%plot the analog & sampled signalssubplot(3,1,1);plot(t,xt,'b',n1,xn,'r*-');title('undersampling plot');
%condition for Nyquist plotfs2=2*fd;n2=0:1/fs2:tfinal;xn=cos(2*pi*fd*n2);subplot(3,1,2);plot(t,xt,'b',n2,xn,'r*-');title('Nyquist plot');
%condition for oversamplingfs3=5*fd; n3=0:1/fs3:tfinal;xn=cos(2*pi*fd*n3);subplot(3,1,3);plot(t,xt,'b',n3,xn,'r*-');title('Oversampling plot');xlabel('time');ylabel('amplitude');legend('analog','discrete');