Vous êtes sur la page 1sur 9

Problem# 1.1 Soln.: % Generate the following sequence d(n-3) + d(n+4) % Candidate No.

: 41910 % Date Created : 30th October 2008 % Date Last Modified : 13th November 2008 Code:
clc; close all; clear all; n1 = input ('Enter the lowest range= '); n2 = input ('Enter the highest range= '); x1 = input ('Enter the 1st place of delta ='); x2 = input ('Enter the 2st place of delta ='); % defining range for x-axis n = n1:n2; d1=[(n+x1)>=0]-[(n+(x1-1))>=0]; d2=[(n+x2)>=0]-[(n+(x2-1))>=0]; d = d1+d2; stem(n,d);

Result : Runtime input values: Enter the lowest range= -10 Enter the highest range= 10 Enter the 1st place of delta = -3 Enter the 2st place of delta = 4 Output: Figure1 shows the required output for the sequence d(n+4) + d(n-3) . Here the response will exist for n is equal to -4 and 3 . For other values of n it will remain zero. Discussions: In the above code delta function is generated by using the defination of unit step funtion to generate the result. Where : d(n) = 1 for n = 0 ; d(n) = 0 otherwise. Thus for creating d(n+4) + d(n-3): n+4=0; n=(-4); and n-3=0; n=3 . Thus we have the sequence which is at -4 and 3 . Our objective is to create signal which is switched ON at a specified sample time. Figure:

Modification: Here d is subscripted for delta function. Problem# 1.2 Soln.: % Generate the following sequence : sawtooth waveform % Candidate No. : 41910 % Date Created 30th October 2008 % Date Last Modified : 30th October 2008 Code:
clc; close all; clear all; f = input(' Enter the frequency in Hz = '); fs = input('Enter the sample rate in kHz ='); d = input('Enter the duty cycle = '); t = 0:1/fs:10; squa = Square(t*2*pi*f,d)+1; saw = sawtooth(2*pi*f*t)+1; ans = (squa.*saw) + 1 ; %figure(1) subplot(2,2,1); plot(t,ans); title('sawtooth with duty cycle'); xlabel('samples'); ylabel('amplitude'); %figure(2) subplot(2,2,2); plot(t,squa); title('square'); xlabel('samples'); ylabel('amplitude'); %figure(3) subplot(2,2,3); plot(t,saw);

title('sawtooth'); xlabel('samples'); ylabel('amplitude');

Result (1) : Enter the frequency in Hz = 1 Enter the sample rate in kHz =1000 Enter the duty cycle =30 Output: The figure below shows the sawtooth waveform with 30 % duty cycle Discussions: In the above code sawtooth waveform with spesified duty cycle is generated by simply generating sawtooth waveform and multipling with sqaure waveform of specified duty cycle.

Result (2): Enter the frequency in Hz = 1 Enter the sample rate in kHz =1000 Enter the duty cycle = 80

Figure:

Problem# 2 Soln.: % Write a routine to convolve two discrete-time sequences in the time domain [without using conv() function] % Candidate No. : 41910 % Date Created 13th November 2008 % Date Last Modified : 13th November 2008 Code:
clc; close all; clear all; a1 = input ('enter the first sequence='); a2 = input ('enter the second sequence='); % For taking lenght of resultant sequence d1= size(a1,2); d2= size(a2,2); X=fft([a1 zeros(1,d2-1)]); Y=fft([a2 zeros(1,d1-1)]); con = ifft(X.*Y); % for verifying the above function taking direct convolve function Z = conv(a1,a2); display(con); display (Z); %figure(1) subplot(1,2,1) stem(con); title('Result without using conv() function'); xlabel('samples'); ylabel('amplitude'); %figure(2) subplot(1,2,2) stem(Z); title('Result by using conv() function');

xlabel('samples'); ylabel('amplitude');

Result: enter the first sequence=[1 2 1 3] enter the second sequence=[1 2 0 2] Output: con = 1.0000 4.0000 5.0000 7.0000 10.0000 2.0000 6.0000 Z= 1 4 5 7 10 2 6

Discussion: FFT convolution uses the principle that multiplication in the frequency domain corresponds to convolution in the time domain. It is the easiest way as it has to performless computational intensities. Convolution is best define for the sequence of the length ( N=2^n where n= 1,2,3.)Here the function FFT performs zeropadding if incase the sequence is not of the order ^n.The most common fast convolution algorithms use fast fourier transform(FFT) algorithms via the Circular Convolution theorem. Here the function FFT performs zeropadding if incase the sequence is not of the order ^n Here Circular Convolution of two finite-length sequences is found by taking an FFT of each sequence, multiplying point wise, and then performing an inverse FFT. Then the result is also compare with the convolution of same sequences by using conv( ) function. Figure:

Problem# 3 Soln.: % Write a routine to compute IDFT % Candidate No. : 41910 % Date Created 13th November 2008 % Date Last Modified : 13th November 2008 Code:
clc close all; clear all; X =input('Enter the sequence in the frequency domain='); N = size(X); N = N(2); display('The time domain sequence by the computed formula is' ) % generation of function to comoute idft for n=1:N K=0; forj=1:N K = K +(X(1,j)*exp((2*pi*i/N)*(j-1)*(n-1))); end R=K/N; display(R) end % for verification taking the idft by using direct function display('Time domain sequence by direct ifft function for verification') Z = ifft(X); display(Z);

Result :
Enter the sequence in the frequency domain=[6 -2+2i -2 -2-2i]

Output: The time domain sequence by the computed formula is R=

0 R= 1.0000 + 0.0000i R= 2.0000 - 0.0000i R= 3.0000 - 0.0000i Time domain sequence by direct ifft function for verification Z= 0 1 2 3

Discussion: IDFT ( inverse discrete fourier transform ) is performed to transfer the sequence from frequency domain into time domain. Here the result is compared with the result of inbuilt IFFT function for verification.

Problem# 4 Soln.: % Design a IIR lowpass Butterworth filter, and plot its frequency domain characteristics % Candidate No. : 41910 % Date Created 4th December 2008 % Date Last Modified : 4th December 2008 Code:
clc; close all; clear all; wp=input('Enter the Digital Passband Frequency: '); ws=input('Enter the Digital Stopband Frequency: '); d1=input('Enter in db, the Passband Attenuation: '); d2=input('Enter in db, the Stopband Attenuation: '); fs=input('Enter the Sampling frequency: '); % sampling period ts=(1/fs); % Angular passband and Stopband frequencies

Wp=2*pi*wp; Ws=2*pi*ws; % Denormalize frequencis ohm_p=((2/ts)*tan(Wp*ts/2)); ohm_s=((2/ts)*tan(Ws*ts/2)); ohm= (ohm_s/ohm_p); % Finding order of filter order= log10(((10.^(0.1*d2)-1)./(10.^(0.1*d1)-1)))./(2*log10(ohm)); N=ceil(order); ohm_c=ohm_p; disp('The Order of the Filter is: '); disp(N); disp('The Analog Cutoff Frequency of the Filter is: ') disp(ohm_c); % To generate tranfer function for low pass butterworth filter. a=1; f=.1:5; w=2*pi*f; s=j*w; for k=1:N sk= ohm_p.*exp(j*(((2*k)+N-1)*pi)./2*N); a=a.*(s-sk); end H=((ohm_p).^N)./a; s=s./ohm_c; for k=1:N sk= ohm_p.*exp(j*(((2*k)+N-1)*pi)./2*N); a=a.*(s-sk); end H1=((ohm_p).^N)./a; % Applying bilear transformation z=exp(-1*j*w*ts); s=((2/ts)*((z-1)./(z+1)))./ohm_c; for k=1:N sk= ohm_p.*exp(j*(((2*k)+N-1)*pi)./2*N); a=a.*(s-sk); end H2=((ohm_p).^N)./a; % figure to plot frequency response of the filter plot(f,abs(H2));

Result: Enter the Digital Passband Frequency: 700 Enter the Digital Stopband Frequency: 1000 Enter in db, the Passband Attenuation: 4 Enter in db, the Stopband Attenuation: 15 Enter the Sampling frequency: 4000 Output: The Order of the Filter is: 4 The Analog Cutoff Frequency of the Filter is: 4.9024e+003

Discussion: Butterworth filter has the flat frequency response in the passband , and rolls off towards zero in the stopband . The response rolls off at -20 dB per decade, and goes on decreasing as the order increases. Only Butterworth filter has the same shape for higher orders. First Analog filter is design as it is more stable than digital . Then by applying transformation technique it is converted to digital filter. Here bilinear tranfornmation technique is used to transfer the analog filter into digital. The filter is design as lowpass butterworth filter by applying transformation [s to (s/cutoff frequency) ]. And then mangnitude is ploted against frequency.

Vous aimerez peut-être aussi