0% found this document useful (0 votes)
60 views6 pages

DSP Lab

The document contains Matlab code for analyzing signals and systems. It includes code to: 1) Take the FFT of a signal containing two sinusoids and plot the power spectral density, 2) Implement the FFT on a user-input sequence and plot the magnitude and phase responses, and 3) Calculate and plot the frequency response of linear time-invariant systems using the freqz function.

Uploaded by

jyothimunj1309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views6 pages

DSP Lab

The document contains Matlab code for analyzing signals and systems. It includes code to: 1) Take the FFT of a signal containing two sinusoids and plot the power spectral density, 2) Implement the FFT on a user-input sequence and plot the magnitude and phase responses, and 3) Calculate and plot the frequency response of linear time-invariant systems using the freqz function.

Uploaded by

jyothimunj1309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

%Program-8

%Determination of Power Spectral Density ofa signal


%Matlab Code
%****************************************************************
clc
clear all
close all

t=0:0.001:0.6;
f1=5;
x=sin(2*pi*f1*t)+sin(2*pi*120*t);
subplot(211);
plot(t,x);

%Find theFFT of x
y=fft(x,512);
%Compute the Power Spectral density

f=(0:256);
P=y.*conj(y)/512;
subplot(212);
plot(f,P(1:257));

% PROGRAM-6
% IMPLEMENTATION OF FFT ON A GIVEN SEQUENCE
%Aim : To implement the FFT on a given sequence
%Equipment required : PC withMatlab Software
%Matlab code

%************************************************
%************************************************
clc
clear all
close all

%Enter the No. of samoles


N=8;
m=8;
%Enter the input sequence
a=input('Enter the input Sequence');
n=0:N-1;
%Display the input sequence

subplot(221);
stem(n,a);
xlabel('Time');
ylabel('Amplitude');
title('Input Sequence');

%Compute the FFT of the input sequence


x=fft(a,m)
%Compute the magnitude of the FFT sequence
k=0:1:N-1;
y=abs(x)
%Display the Magnitude response
subplot(222);
stem(k,y);
xlabel('frequency');
ylabel('Amplitude');
title('Magnitude response');

%Compute the phase of the FFT sequence


z=angle(x)
%Display the phase response
subplot(223);
stem(k,z);
xlabel('frequency');
ylabel('Amplitude');
title('Phase response');
clc;

clear all;

close all;

% Difference equation of a second order system

% y[n]-0.25y[n-1]+0.45y[n-2]=1.55x[n]+1.95x[n-1]+ 2.15x[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 frequency response ');

[h,t]=freqz(b,a,N);

subplot(2,2,1);

% figure(1);

plot(t,h);

subplot(2,2,2);

% figure(2);

stem(t,h);

title('plot of frequency response');

ylabel('amplitude');

xlabel('time index----->N');

disp(h);
subplot(2, 2, 3)
plot(N, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid
subplot(2, 2, 4);
plot(N, angle(h));
xlabel('Frequency');
ylabel('Phase - Radians');
grid on;

b = input('Numerator coefficients');
a = input('Denominator coefficients');
w= -2*pi: .5: 2*pi;
h = freqz(b, a, w);
subplot(221);
plot(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on
subplot(222);
plot(w, angle(h));
xlabel('Frequency');
ylabel('Phase');
grid on
subplot(223);
stem(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on
subplot(224);
stem(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on

b = input('Numerator coefficients');
a = input('Denominator coefficients');
w= -2*pi: .5: 2*pi;
h = freqz(b, a, w);
subplot(221);
plot(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on
subplot(222);
plot(w, angle(h));
xlabel('Frequency');
ylabel('Phase');
grid on
subplot(223);
stem(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on
subplot(224);
stem(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
grid on

clc
clear all
close all
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
subplot(221);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Input signal');

z=cos(2*pi*50*t);
A=z+2*randn(size(t));
subplot(222);
plot(t,A);
xlabel('time');
ylabel('Amplitude');
title('Signal Corrupted with Zero-Mean Random Noise')

Y = fft(x,512);
%The power spectral density
Pyy = Y.* conj(Y) / 512;
f = (0:256);
figure
plot(f,Pyy(1:257))
title('Frequency content of y');
xlabel('frequency (Hz)');
grid on

You might also like