[go: up one dir, main page]

0% found this document useful (0 votes)
58 views4 pages

DSP Programs

This document contains 5 MATLAB scripts that demonstrate various signal processing concepts: 1. Verifies the sampling theorem by plotting a continuous signal and its samples at rates greater than, equal to, and less than the Nyquist rate. 2. Calculates the impulse response of a discrete-time system based on its difference equation. 3. Computes the auto-correlation of a discrete signal and verifies that it is even and that its center value equals the signal energy. 4. Calculates the DFT of a discrete sequence and plots the magnitude and phase spectra. 5. Performs circular convolution of two sequences using the DFT and IDFT.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views4 pages

DSP Programs

This document contains 5 MATLAB scripts that demonstrate various signal processing concepts: 1. Verifies the sampling theorem by plotting a continuous signal and its samples at rates greater than, equal to, and less than the Nyquist rate. 2. Calculates the impulse response of a discrete-time system based on its difference equation. 3. Computes the auto-correlation of a discrete signal and verifies that it is even and that its center value equals the signal energy. 4. Calculates the DFT of a discrete sequence and plots the magnitude and phase spectra. 5. Performs circular convolution of two sequences using the DFT and IDFT.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Sampling theorem verification

clc;
T=0.04; % Time period of 50 Hz signal
t=0:0.0005:0.02;
f = 1/T;
n1=0:40;
size(n1)

xa_t=sin(2*pi*2*t/T);

subplot(2,2,1);
plot(200*t,xa_t);
title('Verification of sampling theorem');
title('Continuous signal');
xlabel('t');
ylabel('x(t)');

ts1=0.002;%>niq rate
ts2=0.01;%=niq rate
ts3=0.1;%<niq rate

n=0:20;
x_ts1=2*sin(2*pi*n*ts1/T);
subplot(2,2,2);
stem(n,x_ts1);
title('greater than Nq');
xlabel('n');
ylabel('x(n)');

n=0:4;
x_ts2=2*sin(2*pi*n*ts2/T);
subplot(2,2,3);
stem(n,x_ts2);
title('Equal to Nq');
xlabel('n');
ylabel('x(n)');

n=0:10;
x_ts3=2*sin(2*pi*n*ts3/T);
subplot(2,2,4);
stem(n,x_ts3);
title('less than Nq');
xlabel('n');
ylabel('x(n)');

2.impulse response
clc;
clear all;
close all;
% Difference equation of a second order system
% y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
b=input('enter the coefficients of x(n),x(n-1)-----');
a=input('enter the coefficients of y(n),y(n-1)----');
N=input('enter the number of samples of imp response ');

[h,t]=impz(b,a,N);
plot(t,h);
title('plot of impulse response');
ylabel('amplitude');

xlabel('time index----->N');
disp(h);
grid on;

3. Auto correlation

x=[1,2,3,6,5,4]
% define the axis
n=0:1:length(x)-1
% plot the signal
stem(n,x);
xlabel('n');
% auto correlate the signal
Rxx=xcorr(x,x);
% the axis for auto correlation results
nRxx=-length(x)+1:length(x)-1
% display the result
stem(nRxx,Rxx)

% properties of Rxx(0) gives the energy of the signal


% find energy of the signal
energy=sum(x.^2)

%set index of the centre value


centre_index=ceil(length(Rxx)/2)

% Acces the centre value Rxx(0)


Rxx_0==Rxx(centre_index)
Rxx_0==Rxx(centre_index)

% Check if the Rxx(0)=energy


if Rxx_0==energy
disp('Rxx(0) gives energy proved');
else
disp('Rxx(0) gives energy not proved');
end
Rxx_right=Rxx(centre_index:1:length(Rxx))
Rxx_left=Rxx(centre_index:-1:1)
if Rxx_right==Rxx_left
disp('Rxx is even');
else
disp('Rxx is not even');
end

4. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.

N = input('Enter the the value of N(Value of N in N-Point DFT)');


x = input('Enter the sequence for which DFT is to be calculated');
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-1j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk;
MagX=abs(Xk) % Magnitude of calculated DFT
PhaseX=angle(Xk)*180/pi % Phase of the calculated DFT
figure(1);
subplot(2,1,1);
plot(k,MagX);
subplot(2,1,2);
plot(k,PhaseX);

5.Circular convolution of two given sequences using DFT and IDFT

clc; % Program for circular convolution


clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n=input('enter the no of points of the dft');

subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');

subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');

y1=fft(x1,n);
y2=fft(x2,n);
y3=y1.*y2;
y=ifft(y3,n);

disp('the circular convolution result is ......');


disp(y);

subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');

You might also like