Vous êtes sur la page 1sur 7

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI

Pilani Campus

EEE C434/EEE F434: Digital Signal Processing


Lab 5: DFT

Note: Please write your MATLAB codes in this .doc file and save it. Capture
and paste the snapshots of your plots, wherever required. Make sure you
get it signed before leaving the lab.

Please make sure you add a title, axis labels, x-axis limit and y-axis limit, grid on,
and legend (if required) to each of your figures.

PART A: DFT of speech signal

Q1) Use the following link below to access the speech signal x[n]:
.
a) Plot the signal x[n] and its magnitude and phase spectrum using N-point DFT,
where N=length(x). You can use the MATLAB inbuilt function to compute DFT.
Make sure to use the subplot command such that these three plots are shown in
one column and three rows. Additionally, the x-axis for the DFT plots should be in
frequency (Hz). Make sure the phase spectrum has absolute values.

>> [y,fs]=audioread('C:\Users\user\Downloads\si1188.wav');
>> ymag=abs(fft(y));
>> yphase=abs(unwrap(angle(fft(y))));
>> N=length(y);
>> freq=0:fs/N:fs*(N-1)/N;
>> length(freq)

ans =

22938

>> subplot(3,1,1);
>> plot(freq,y)
>> xlabel('freq(in Hz)')
>> ylabel('Amplitude')
>> subplot(3,1,2);
>> plot(freq,ymag)
>> xlabel('freq(in Hz)')
ylabel('Amplitude')
>> subplot(3,1,3);
>> plot(freq,yphase)
>> xlabel('freq(in Hz)')
ylabel('Amplitude')
>> ylabel('Phase')
b) Now, compute the same with 2*N DFT and repeat a). Record your observations.

>> ydft=fft(y,2*length(y));
>> ymag=abs(ydft);
>> yphase=abs(unwrap(angle(ydft)));
>> freq=(0:fs/N:fs*(N-1)/N);
>> plot(freq,y)
Error using plot
Vectors must be the same length.

>> length(freq)

ans =

45876

>> subplot(3,1,1);
>> plot(y)
>> subplot(3,1,2);
>> plot(freq,ymag)
>> subplot(3,1,3);
>> plot(fre,yphase)
Undefined function or variable 'fre'.

>> plot(freq,yphase)
To access the sound file (si1188.wav):
https://drive.google.com/file/d/0B7-qexRAlXuTUldYOUdPTXFYSW8/view?usp=sharing

PART B: Spectral sampling

Q2) Consider a discrete time sequence given below:

x[n] = cos(2** (f1/fs)*n) + cos(2* (f2/fs)* n); 0 n N-1. Assume that rectangular
window of length N is used. Here, f1 = 170 Hz and f2 = 390 Hz, fs = 6630 Hz.

a) Compute the N-point DFT of the sequence for the following values of N:
i) N = 170 ii) N = 390 iii) N = 663 iv) N = 200

Plot the sequence x[n] and its magnitude spectrum for different values of N. Use
the subplot command with two columns and four rows such that all 8 plots are
shown in one figure. Column 1 should have the time domain sequence with the
corresponding DFT magnitude spectrum in column 2. Additionally, the x-axis for
the DFT plots should be in frequency (Hz).

Observe clearly the spectral peak values in each of the four values of N (use stem
command instead of plot). Note down your observations.

>> N1=0:1:169;
>> N2=0:1:389;
>> N3=0:1:662;
>> N4=0:1:199;
>> x1=cos(2*pi*(f1/fs)*N1)+ cos(2*pi*(f2/fs)*N1);
>> x2=cos(2*pi*(f1/fs)*N2)+ cos(2*pi*(f2/fs)*N2);
>> x3=cos(2*pi*(f1/fs)*N3)+ cos(2*pi*(f2/fs)*N3);
>> x4=cos(2*pi*(f1/fs)*N4)+ cos(2*pi*(f2/fs)*N4);
>> freq1=(0:fs/N1:fs*(N1-1)/N1);

>> freq1=(0:fs/170:fs*(170-1)/170);
>> freq2=(0:fs/390:fs*(390-1)/390);
>> freq3=(0:fs/663:fs*(663-1)/663);
>> freq4=(0:fs/200:fs*(200-1)/200);

>> subplot(4,2,1);
>> stem(N1,x1)
>> subplot(4,2,2);
>> stem(freq1,abs(fft(x1)))
>> subplot(4,2,3);
>> stem(N2,x2)
>> subplot(4,2,4);
>> stem(freq2,abs(fft(x2)))
>> subplot(4,2,5);
>> stem(N3,x3)
>> subplot(4,2,6);
>> stem(freq3,abs(fft(x3)))
>> subplot(4,2,7);
>> stem(N4,x4)
>> subplot(4,2,8);
>> stem(freq4,abs(fft(x4)))
b) Based on the observations from part a), mark if frequency is present in the
magnitude spectrum.

N f1 = 170Hz f2 = 390Hz
170 No No
390 Yes no
663 yes Yes
200 No No
Use the fftshift command to change the frequency range to [fs/2, fs/2]. Plot the
sequence x[n], original magnitude spectrum and shifted spectrum for N = 170. Make
sure to use the subplot command such that these three plots are shown in [y,fs] =
wavread('foo.wav');
ydft = fft(y);
% I'll assume y has even length
ydft = ydft(1:length(y)/2+1);
% create a frequency vector
freq = 0:fs/length(y):fs/2;
% plot magnitude
subplot(211);
plot(freq,abs(ydft));
% plot phase
subplot(212);
plot(freq,unwrap(angle(ydft)));
xlabel('Hz');

c) one column and three rows. Note down your observations.


f='name.wav';
[x,sr]=wavread(f) ;
Ts=1/sr;
N=2^15;
x=x(1:N)';
time=Ts*(0:length(x)-1);
figure(1)
magx=abs(fft(x));
ssf=(0:N/2-1)/(Ts*N);
plot(ssf,magx(1:N/2))
wave_file = 'name.wav';

[wave_data_time, sample_rate] = wavread(wave_file);

N_temp = length(wave_data);

N = 2^nextpow2(N_temp);

buff = floor((N-N_temp)/2)+1;

Nyq = sample_rate/2;

df = sample_rate/N;

f = -Nyq:df:Nyq-df;

wave_data_time_pad = zeros(size(f));

wave_data_time_pad(buff:buff-1+N_temp) = wave_data_time;

wave_data_freq = fftshift(fft(wave_data_time_pad));

figure;
plot(f,real(wave_data_freq),'b-',f,imag(wave_data_freq),'r-');

Vous aimerez peut-être aussi