Академический Документы
Профессиональный Документы
Культура Документы
Ex. No: Date: AIM: To perform digital modulation using MATLAB. (a) ASK (b) FSK (c) PSK (d)AM (e)FM ALGORITHM: 1. Start the program. 2. Get the input bit sequence to be modulated as input 3. Calculate the length of the sequence. 4. Generate the carrier waveform for different values of amplitude, frequency and phase. 5. Generate the carrier waveform for the corresponding binary value. 6. Plot the input and output waveform. 7. Stop
Result Thus the programs for digital modulation techniques(ASK,FSK, PSK,AM & FM) are written and executed using MatLab.
PROGRAM
% Amplitude Shift Keying clc clear all close all x=input('Enter the input bit sequence: '); t=0:length(x) - 1; subplot(2,1,1); stairs(t,x); axis([0 length(x) -2 2]); title('Input'); grid on; t1=0:0.01:1; s1=sin(2*pi*6*t1); L=length(t1)*length(x); i=1; for j=1:length(x) if(x(j)==1) for k=1:length(t1) y(i)=s1(k); i=i+1; end else for k=1:length(t1) y(i)=0; i=i+1; end end end t2=0:(length(x)/(L-1)):length(x); subplot(2,1,2); plot(t2,y); title('ASK output');
PROGRAM
%Frequency Shift Keying clc; clear all; close all; x=input('Enter the bits within square brackets:'); t=0:length(x)-1; subplot(2,1,1),stairs(t,x); axis([0 length(x) -2 2]); grid on; title('input sequence'); t1=0:0.001:1; s1=sin((2*pi*6*t1)); s2=sin((2*pi*3*t1)); L=length(t1)*length(x); i=1; for j=1:length(x) if (x(j)==0) for k=1:length(s1) y(i)=s1(k); i=i+1; end else for k=1:length(s2) y(i)=s2(k); i=i+1; end end end t2=0:(length(x)/(L-1)):length(x); subplot(2,1,2),plot(t2,y); axis([0 length(x) -2 2]); grid on; title('FSK output');
OUTPUT
PROGRAM
%Phase Shift Keying clc; clear all; close all; x=input('Enter the bits within square brackets:'); t=0:length(x)-1; subplot(2,1,1),stairs(t,x); axis([0 length(x) -2 2]); grid on; title('Input sequence'); t1=0:0.001:1; s1=sin(2*pi*6*t1); s2=sin((2*pi*6*t1)+pi); L=length(t1)*length(x); i=1; for j=1:length(x) if(x(j)==0) for k=1:length(s1) y(i)=s1(k); i=i+1; end else for k=1:length(s2) y(i)=s2(k); i=i+1; end end end t2=0:(length(x)/(L-1)):length(x); subplot(2,1,2),plot(t2,y); axis([0 length(x) -2 2]); grid on; title('PSK Output');
OUTPUT
%amplitute modulation close all; clear all; em = input('enter signal amplitute:'); ec = input('enter carrier amplitute:'); fm = input('enter signal frequency in khz:'); fc = input('enter carrier frequency in khz:'); ma = em/ec; disp(ma); w0=(2*pi*fm); w1=(2*pi*fc); wu=w0+w1; wl=w1-w0; t = 0:0.001:2; E=em*cos(w0*t); C=ec*cos(w1*t); U=(ma*ec*cos(wu*t))/2; L=(ma*ec*cos(wl*t))/2; AM=C+L+U; title('message signal'); subplot(3,1,1); plot(t,E); grid on; title('carrier signal'); subplot(3,1,2); plot(t,C); grid on; title('am signal'); subplot(3,1,3); plot(t,AM); grid on;
%Frequency modulation clc close all; clear all; fm = input('Enter signal frequency in khz:'); fc = input('Enter carrier frequency in khz:'); b=input('Enter the frequency deviation: '); t=0:0.001:10; c=cos(2*pi*fc*t); m=cos(2*pi*fm*t); %b=fc-fm; fsig=cos((2*pi*fc*t)+(b/fm)*cos(2*pi*fm*t)); subplot(3,1,1) plot(t,m); title('Message Signal'); xlabel('time'); ylabel('amplitude'); subplot(3,1,2) plot(t,c); title('Carrier Signal'); xlabel('time'); ylabel('amplitude'); subplot(3,1,3) plot(t,fsig); title('Frequency Modulated Signal'); xlabel('time'); ylabel('amplitude');
OUTPUT Enter signal frequency in khz:1 Enter carrier frequency in khz:5 Enter the frequency deviation: 2
ALGORITHM: Welch 1. Start the program. 2. Get the input signal x, whose spectrum is to be estimated 3. Estimate the spectrum for the input x using pwelch[] function 4. If the function parameter noverlap is made as zero, it is equivalent to Barlett method of spectrum estimation. 5. Plot the graph.
Bartlett 1. Start the program. 2. Get f1, f2 and the sampling frequency fs. 3. Compute f1 + f2 + random signal. 4. Sample the result of step 3 and perform FFT. 5. Calculate the magnitude and plot the graph.
Blackmann - Turkey 1. Start the program. 2. Get f1, f2 and the sampling frequency fs. 3. Compute f1 + f2 + random signal. 4. Sample the result of step 3, perform autocorrelation of the signal and perform FFT. 5. Calculate the magnitude and plot the graph.
Result Thus spectrum estimation is done using Welch, Bartlett and Blackmann-Turkey method in MatLab.
%Spectral analysis using periodogram clc; clear all; close all; f=input('Enter the input frequency: '); fs=input('Enter the sampling frequency: '); t = 0:1/fs:.3; x = sin(2*pi*t*f)+0.1*randn(size(t)); periodogram(x,[],'onesided',length(x),fs)
SAMPLE I/P: enter the input frequency:10 enter the sampling frequency:100
PROGRAM
%Power spectrum using welch method% Fs=1000; t=0:1/Fs:0.296; %A cosine of 200 Hz plus noise x=cos(2*pi*pi*t*200)+randn(size(t)); %Uses default window,overlap & NFFT pwelch(x,[],[],[],Fs,'twosided'); title('Powe spectrum using welch');
PROGRAM
%power spectrum estimation using Barlett method clc; close all; clear all; n=0:1000; c=sin(2*3.14*0.24*n)+sin(2*3.14*0.36*n)+ randn(size(n)); subplot(2,1,1); plot(n,c); title('Signal with noise'); nfft=512; noverlap=0; window=hamming(256); [pxx,f]= psd(c,nfft,2,window,noverlap); subplot(2,1,2); plot(f/2,10*log10(pxx)); title('Power Spectral Density');
OUTPUT
PROGRAM
%Power spectrum estimation Blackmann and Turkey Method clc; clear all; clf; f1=input('Enter the first freq: '); f2=input('Enter the second freq: '); fs=input('Enter the sampling freq: '); t=0:1/fs:1; a=sin(2*3.14*f1*t)+sin(2*3.14*f2*t)+randn(size(t)); subplot(2,1,1); plot(t,a); axis([0 1 -4 4]); title('Power spectrum input: '); rxx=xcorr(a); n=length(rxx); w=hanning(n); s=rxx.*w'; pxx=fft(s); pxx=fftshift(pxx); mag=10*log10(abs(pxx)); subplot(2,1,2); stem((-(n-1)/2:(n-1)/2)/(n/fs),mag); axis([-fs/2 fs/2 45 80]); title('Power spectrum estimation using blackmann turkey method: ');
OUTPUT Enter the first freq: 500 Enter the second freq: 1000 Enter the sampling freq: 3000
Result Thus Hamming-code is generated and error correction in the transmitted sequence is done using MatLab.
PROGRAM
%hamming code clc; clear all; m=input('Enter the 4 bits to be transmitted: '); g=[1 1 0 1 0 0 0;0 1 1 0 1 0 0;1 1 1 0 0 1 0;1 0 1 0 0 0 1]; h=[1 0 0 1 0 1 1;0 1 0 1 1 1 0;0 0 1 0 1 1 1]; disp('Generator matrix: '); disp(g); disp('H matrix: '); disp(h); x=m*g; y=mod(x,2); disp('y:'); disp(y); ht=h.'; cr=input('Enter the corrupted code: '); s=cr*ht; sm=mod(s,2); disp('Syndrome: '); disp(sm); q=[0 0 0;0 0 1; 0 1 0;0 1 1;1 0 0;1 0 1; 1 1 0; 1 1 1]; e=[0 0 0 0 0 0 0;1 0 0 0 0 0 0;0 1 0 0 0 0 0;0 0 1 0 0 0 0;0 0 0 1 0 0 0;0 0 0 0 1 0 0;0 0 0 0 0 1 0;0 0 0 0 0 0 1]; disp('q:'); disp(q); disp('e:'); disp(e); for i=1 :7 l=0; for j=1 :3 if sm(1,j)== q(i,j) l=l+1; end end if l==3 p=i-1; break; end end fprintf('Error in the %d position',p ); cr(p)=not(cr(p)); disp('Corrected Code'); disp(cr);
0 0 1
1 1 0
0 1 1
1 1 1
1 0 1
Discrete Cosine Transform (DCT) and Inverse Discrete Cosine Transform (IDCT).
Ex. No: Date: AIM: To perform DCT and IDCT using MATLAB ALGORITHM: 1. Start 2. Read an image and display the same 3. Find the cosine transform of the image 4. Find the inverse discrete cosine transform 5. Show the resultant Image and reconstructed image 6. Stop.
PROGRAM
%Discrete and inverse Discrete Cosine transforms of an image a=imread('baboon.jpg'); subplot(3,1,1); imshow(a,[]); title('Original Image'); b=dct2(a); subplot(3,1,2); imshow(b); title('DCT'); c=idct2(b); subplot(3,1,3) imshow(c,[]); title('Inverse DCT');
OUTPUT
Histogram equalization
Ex. No: Date: AIM: To perform histogram equalization using MATLAB ALGORITHM: 1. Start 2. Read an image and display the same 3. Find the histogram of the image 4. Find the histogram equalization of the input image 5. Show the resultant Image and reconstructed image 6. Stop.
Result Thus Histogram equalization of the given image is done using MatLab.
PROGRAM
clc; clear all; close all; subplot(4,1,1); a=imread('baboon.jpg'); imshow(a); title('original image'); subplot(4,1,2); imhist(a); title('histogram of original image'); subplot(4,1,3); b=histeq(a); imshow(b); title('equalization iamge'); subplot(4,1,4); imhist(b); title('histogram of equalized image');
OUTPUT
BUTTERWORTH FILTER
Ex. No: Date: AIM: To design an IIR filter using BUTTERWORTH filter co-efficients. ALGORITHM: 1. Start. 2. Get the sampling frequency. 3. Get the signal frequency. 4. Using the in built function butterworth function, like buttod 5. Design the filter by calculating co-efficients and plot the values.
RESULT: Thus program was successfully written and the code was executed using MatLab.
PROGRAM
%BILEAR TRANSFORM wp=0.355*pi; ws=0.7*pi; ap=-20*log10(0.6); as=-20*log10(0.1); T=0.1; awp=(2/T)*tan(wp/2); aws=(2/T)*tan(ws/2); [n,wc]=buttord(awp,aws,ap,as,'s'); disp(n); disp(wc); [b,a]=butter(n,1,'s'); display('normalized s domain tf'); hs=tf(b,a); [b,a]=butter(n,'w','s'); display('unnormalized tf'); [num,den]=bilinear(b,a,1/T); display('tf in z domain'); hz=tf(num,den); fvtool(num,den);
IMPULSE INVARIANCE
Ex. No: Date: AIM: To design an IIR filter using Impulse Invariance and to find filter co-efficients. ALGORITHM: 1. Start. 2. Get the required parameter like amplitude and frequency etc. 3. Convert the required signal parameter into decibel. 4. Using the Butterworth function in MatLab, calculate the co-effecients. 5. Plot the frequency spectrum.
RESULT: Thus the filter is successfully designed and executed using MatLab.
PROGRAM:
%impulse invariance wp=0.355*pi; ws=0.7*pi; ap=-20*log10(0.6); as=-20*log10(0.1); f=1; T=0.1; awp=(2/T)*tan(wp/2); aws=(2/T)*tan(ws/2); [n,wc]=buttord(awp,aws,ap,as,'s'); disp(n); disp(wc); [b,a]=butter(n,1,'s'); display('normalized s domain tf'); hs=tf(b,a); [b,a]=butter(n,wc,'s'); display('unnormailzed tf'); hs=tf(b,a); [bz,az]=impinvar(b,a,f); display('tf in z domain'); hz=tf(bz,az); fvtool(bz,az);
RESULT: Thus the filter is designed for the windowing using rectangular method and executed using MAtLab.
RESULT: Thus the noises were added and removed to the image and successfully executed using MatLab.
Result Thus programs using direct, indirect and immediate addressing modes are done using TMS320C50 processor.
IMMEDIATE ADDRESSING MODE PROGRAM: .mmregs .ds 1000h .ps 0a00h .entry .lacc #07h .add #05h .end sample input & output: acc <- o7h o/p: acc<- 07+05=och DIRECT ADDRESSINGG MODE PROGRAM: .mmregs .ds 1000h .ps 0a00h .entry ldp #32 lacc 02h add 04h sacl 20h .end sample input & output: 1002 ->acc -> 02h 1004 <- 04h acc <- 06h o/p: 1020 <- 06h INDIRECT ADDRESSING MODE PROGRAM: .mmregs .ds 1000h .ps 0a00h .entry lar ar2, #1003h lar ar0, #1001h lar ar1, #1002h mar * lacc * mar *, ar1 add * mar *,ar2 add * sacl * .end sample input & output: ar0 ->1001h -> 02h ar1 ->1002h -> 03h ar2 ->1003h -> 01h o/p: 1003h -> 06h
MULTIPLICATION
Ex. No: Date: AIM: To perform multiplication using TMS320C50 instruction kit. ALOGRITHM: (i)USING MPY INSTRUCTION: 1. Start. 2. Load AR's and temprorary registers which contain the 1 st operand. 3. Using mpy instruction perform multiplication. 4. store the result. 5. Stop.
(ii)USING MAC INSTRUCTION: 1. Start. 2. Load the data in required AR's. 3. Using mac instrution to multiply the data in 0a00h & in AR. 4. Store the result. 5. Stop. (iii) USING REPEATED ADDITION: 1. Start 2. Load AR's with one operand & address of another another. 3. Perfrom repeated addition using one AR as counter. 4. Stop.
(i) USING MAC INSTRUCTION PROGRAM: .mmregs .ds 1000h .ps 0a00h .entry lar ar0,#1000h lacc #05h samm treg0 mpy #06h pac mar *,ar0 sacl * .end sample input & output acc-< 05h * 06h preg <- 12h acc <- 12h ar0 -> 1000h -> 12h (ii) USING MAC INSTRUCTION PROGRAM: .mmregs .ds 1000h .ps 0a00h .word 06h .entry lar ar0,#1001h lar ar1,#1010h mar *,ar0 mac 0a00h pac mar *,ar1 sacl * .end sample input & output ar0 ->1001h -> 06h 0a00h -> 06h preg ->24h ->acc 1010h -> 24h (iii) USING REPEATED ADDITION PROGRAM: .mmregs .ds 1000h .ps 0a00h
.entry lar ar0, #1000h lar ar1, #05h lar ar2,#1002h L: mar *,ar0 zap add * mar *,ar1 mar *banz L mar *,ar2 sacl * .end sample input & output 100h <- 05h 1002h <- 19h
Linear Convolution Ex. No: Date: AIM: To perform linear convolution using TMS320C50 instruction set ALGORITHM:
1. Start 2. Store the input sequence of length n1 in program memory 3. Store the impulse sequence of length n2 in data memory 4. Appended (n1-1) zeros on either side of impulse sequence 5. Point to the last element of n1 sequence and multiply using MAC instruction 6. Next point to the last but one element and perform the same 7. Do this in a loop counter, count=(n1+n2-1) 8. If counter 0 repeat else go to 9. Stop the loop 10. Stop
LINEAR CONVOLUTION x(n) ={1,2,3}; h(n)= {0,0,3,1,0,0}; PROGRAM: .mmregs .ds 1000h .word 00h,00h,03h, 10h,00h,00h .ps 0a00h .word 10h,02h,03h .entry lar ar0,#1002h lar ar1,#04h lar ar2,#1020h L1: zap mar *, ar0 rpt #03h mac 0a00h, *adrk #05h mar *,ar2 sacl *+ mar *,ar1 mar *banz L1 .end sample output: 00h,00h,03h,07h,03h,03h,00h,00h
Circular Convolution Ex. No: Date: AIM: To perform circular convolution using TMS320C50 instruction set ALGORITHM:
1. Start 2. Load CBSR1, CBER1 and CBCR. 3. Load the required ARs. 4. Multiply using MAC instruction by decrementing AR. 5. Store the result in suitable location. 6. Stop.
x(n)= {5,7,9,2,3} h(n)={1,2,3,4,5} 53297 1 57329 2 97532 3 29753 4 32975 5 PROGRAM: .mmregs .ds 1000h .ps 0a00h .word 05h,07h,09h,02h,03h .entry splk #1004h,cbsr1 splk #1000h,cber1 splk #ofh,cbcr lar ar7, #1000h lar ar1, #1030h lar ar2, #05h L: zap mar *, ar7 rpt #05h mac 0a00h,*mar *mar *mar *mar *, ar1 sacl *+ mar *, ar2 mar *banz L .end sample input & output 1000h- 05h 1001h- 07h 1002h- 09h 1003h- 02h 1004h- 03h o/p: 1030h- 58h 1031h- 4Fh 1032h- 3Ch 1033h- 4Ch 1034h- 57h 0a00h- 01h 0a001h- 02h 0a002h- 03h 0a003h- 04h 0a004h- 05h
Waveform Generation Ex. No: Date: AIM: To generate waveforms using TMS320C50 instruction set ALGORITHM: 1. Initialize memory mapped registers 2. Initialize the data and program memory segment 3. (a) For Square wave Generation i) Set the Amplitude and ii) Time Period Positive: 7FFFh Negative: 9FFFh Ton: 1000h T off: 1000h 4. Set the Tone and Toff of the square wave form using Auxiliary Register 5. Load the positive value in Accumulator 6. AND the accumulator value with 0FFCh for primary communication between DSP and AIC 7. Transfer the data from ACC to DXR Using SAMM instruction 8. Repeat step 7 for Ton times 9. Load the negative value in Accumulator 10. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC 11. Repeat step 10 for Toff times 12. Repeat step 5 to step 11 unconditionally.
b) For Ramp wave Generation 1. i) Set the Amplitude and ii) Step Value Amplitude: 7FFFh Step: 00008h 2. Set the interrupt and load PDWSR and CWSR with appropriate value 3. Load Accumulator with amplitude 4. Load ARCR with ACC value using SAMM instruction 5. Load Accumulator and ARn with #0000h 6. Add step value with ACC and ARn content 7. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC 8. Transfer the data from ACC to DXR using SAMM instruction 9. Compare ARCR with ARn and Branch conditionally (CM=00)to corresponding step 6 10. Repeat step 5 to step 9 unconditionally (c) For Triangular wave Generation 1. i) Set the Amplitude and ii) Step Value Amplitude: 7FFFh Step: 00008h 2. Load Accumulator with amplitude value 3. Load ARCR with ACC value using SAMM instruction 4. Load Accumulator and ARn with #0000h 5. Add step value with ACC and ARn content 6. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC 7. Transfer the data from ACC to DXR using SAMM instruction 8. Compare ARCR with ARn and Branch conditionally (CM=00) to corresponding step 7 9. Load Accumulator with #0000h 10. Load ARCR with ACC value using SAMM instruction 11. Load Accumulator and ARn with amplitude value 12. Subtract step value from ACC and ARn content 13. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC 14. Transfer the data from ACC to DXR using SAMM instruction
15. Compare ARCR with ARn and Branch conditionally (CM=00) to corresponding step 12 16. Branch to step 4 unconditionally
Result: Thus square, ramp and triangular waveforms are generated using TMS320C50 processor.
SQUARE WAVEFORM PROGRAM: .mmregs .ds 1000h .ps 0a00h ampp .set 7FFFh ampn .set 9FFFh ton .set 7888h toff .set 7888h .entry L1: lacc #ampp and #0FFCh rpt #ton samm dxr lacc #ampn and #0FFCh rpt #toff samm dxr bL1 .end TRIANGULAR WAVEFORM PROGRAM: .mmregs .ds 1000h .ps 0a00h amp .set 7FFFh step .set 0010h .entry L3: lacc #amp samm arcr lacc #0000h lar ar0, #0000h L1: add #step and #offfch samm dxr adrk #step cmpr1 bcnd L1,tc splk #0000h,arcr L2: sub #step and #offfch samm dxr sbrk #step cmpr 2 bcnd L2,tc bL3 .end
RAMP WAVEFORM PROGRAM: .mmregs .ds 1000h .ps 0a00h amp .set 7fffh step .set 0008h .entry lacc #amp samm arcr L2: lacc #0000h samm arcr L1: and offfch samm dxr add #step adrk #step cmpr 1 bcnd L1,tc bL2 .end
Result: Thus lowpass and highpass FIR filters are designed using TMS320C6713
Design of IIR Filters (i) LPF (ii) HPF Ex. No: Date: AIM: To design a Low Pass Filter and High Pass Filter using IIR filter design method using TMS320C6713 Code Composer Studio ALGORITHM: 1. Get the passband cut off frequency, stopband cut-off frequency, passband ripple and stopband ripple as input for desired filter response 2. Calculate the order using Butterworth method/Chebyshev method as specified, N 3. Find the transfer function of the analog filter according to N 4. Convert the analog filter to digital filter using Bilinear transformation method
Result: Thus low pass and high pass FIR filter are designed using TMS320C6713.
LOW PASS FILTER #include<stdio.h> #include<math.h> main() { float wc,hd[9],h[9],w[9]; int n,x,I; printf(enter the order); scanf(%d: ,& n); printf(enter cutoff); scanf( %f , &wc); x = (n-1)/2; for(i=0;i<n-1;i++) { w[i]= 0.54 + (0.46 * cos(2*pi*i)/(n-x)); if(i==x) hd[i]=wc/3.14; else hd[i]=sin(wc * (i-x) )/ (3.14 * (i-x)); h[i]= hd[i] * w[i]; } for(i=0;i<n-1;i++) { printf(%f,h[i]); } }
HIGH PASS FILTER #include<stdio.h> #include<math.h> main() { float wc,hd[9],w[9]; int n,x,I; printf(enter the order); scanf(%d: ,& n); printf(enter cutoff); scanf( %f , &wc); x = (n-1)/2; for(i=0;i<n-1;i++) { w[i]= 0.54 + (0.46 * cos(2*pi*i)/(n-x)); if(i==x) hd[i]=1-(wc/3.14) else hd[i]=-sin(wc * (i-x) / (3.14 * (i-x)); h[i]=hd[i] * w[i]; } for(i=0;i<n-1;i++) printf(%f, h[i]); }
SAMPLE INPUT AND OUTPUT a=[0.107503, -0.046953, -0.079272, 0.229496, 0.381976, 0.229496, -0.008522, 0.002205, -0.0085] b=[0.167503, -0.04693, -0.079272, 0.256706, 0.381972, 0.256706, -0.008522, 0.002205, -0.008522]
ALGORITHM: 1. 2. 3. 4. 5. 6. 7. 8. 9. Start. Get the two sequences x and h. Perform padding of zeros. Run a for loop for j=0 to m+n-1. Assign y[i]=0. Run another for loop from i=0 to j. y[j] = y[j] + (x[i] * h[j-1]); display y. stop.
PROGRAM: /* prg to implement linear convolution */ #include<stdio.h> #include<math.h> int y[20]; main() { 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}; 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]); }
/*Lenght of i/p samples sequence*/ /*Lenght of impulse response Co-efficients */ /*Input Signal Samples*/ /*Impulse Response Co-efficients*/
ALGORITHM: 1. 2. 3. 4. 5. 6. Start. Get the two sequences m and n. Get the two sequences x and h. If length of both sequence are not equal pad the smaller sequence with zeros Fold h[n] to h[-n]. Perform circular convolution. y[0] = x[i]*a[i]. 7. Perform circular shift. 8. Display the result.
RESULT: Thus circular convolution was performed using C6713 code composer studio
PROGRAM:
#include<stdio.h> #include<math.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 first sequence\n"); scanf("%d",&m); printf(" enter the length of the second sequence\n"); scanf("%d",&n); printf(" enter the first 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 length of both sequences are not equal*/ { if(m>n) /* Pad the smaller sequence with zero*/ { 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++) /*folding h(n) to h(-n)*/ a[j]=h[n-j]; /*Circular convolution*/ for(i=0;i<n;i++) y[0]+=x[i]*a[i]; for(k=1;k<n;k++) { y[k]=0; /*circular shift*/ 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]; } } /*displaying the result*/ printf(" the circular convolution is\n"); for(i=0;i<n;i++) printf("%d \t",y[i]); }
Ex. No: Date: AIM: To implement FIR bandpass filter using hamming window in C6713 code composer studio.
ALGORITHM: 1. Start. 2. Get the filter specifications wc1,wc2,N. 3. Calculate the window coeffecients w(n). 4. Calculate the filter coeffecients hd(n). 5. Convolve th e two sequence to get the FIR filter coeffecients. h(n)=w(n)*hd(n). 6. Stop.
RESULT: Thus the FIR band pass filter using hamming window has been implemented successfully in code composer studio
PROGRAM: #include<stdio.h> #include<conio.h> int N=11;a=1000; float w[7],hd[7],h[7],pi=3.14,x(1000); wc1=0.4*pi; wc2=0.65*pi; void main() { float t1=0.4*pi,t2=0.65*pi; int n=0; for(n=0;n<N;n++) { w(n)=0.5-(0.5*cos(2*pi*n/N-1)); hd(n)=(sin(t2*(n-3)))-(sin(t1*(n-3)))/(pi*(n-3))); h(n)=w(n)*hd(n); printf(%f,h(n))); for(i=0;i<a;i++) { x(i)=0.25-((0.0296)*cos(i*pi/6))-((0.112)*cos(2*i*pi/6)); printf(%f,x(i))); } }
OUTPUT
( )
( ( )
( )
RESULT: Hence the discrete fourier transform(DFT) was implemented successfully in code composer studio.
PROGRAM:
#include<stdio.h> #include<math.h> int N,k,n,I; float pi=3.1416,sumre=0;sumin=0; float out_real(8)=0.03, out_imag[8]={0.03}; int x[32]; void main() { printf(Enter the length of sequence \n); scanf(%d,&N); printf(Enter the sequence \n); for(i=0;i<n;i++) scanf(%d,&x[i]); for(k=0;k<n;k++) { sumre=0;sum in>0; } for(n=0;n<N;n++) { sumre=sumre+x(n)*cos(2*pi*k*n/w); sumim=sumim-x(n)*sin(2*pi*k*n/w); } out_real(k)=sumre; out_imag[k]=sumim; printf(%d= \t %f \t%f,k,out_real(k),out_imag(k)); } }