DSP Lab
DSP Lab
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
subplot(221);
stem(n,a);
xlabel('Time');
ylabel('Amplitude');
title('Input Sequence');
clear all;
close all;
% y[n]-0.25y[n-1]+0.45y[n-2]=1.55x[n]+1.95x[n-1]+ 2.15x[n-2]
[h,t]=freqz(b,a,N);
subplot(2,2,1);
% figure(1);
plot(t,h);
subplot(2,2,2);
% figure(2);
stem(t,h);
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