```
import os
import scipy.io
import scipy.io.wavfile
import numpy as np
import matplotlib.pyplot as plt
dataset_path = os.path.join(os.environ['HOME'], 'shared', 'data', 'assignment_1')
wavedata = os.path.join(dataset_path, 'example.wav')
fs, audio_buffer = scipy.io.wavfile.read(wavedata)
a = np.array(audio_buffer)
frame_size = 2048
start_frame = 2*fs
T = 1/fs # sampling period
t = 2048/fs # seconds of sampling
frame = np.array(a[0:int(fs*t):]) # total points in signal
#because the starting point is 2*fs and the amount of frames is 2048
spectrum = np.fft.fft(a) [start_frame:start_frame+frame_size:]
abs_spec = abs(spectrum) [0:int(frame_size/2):]
plt.plot(abs_spec)
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
plt.show()
```

I needed to perform DFT of the .wav file.

But I am actually not sure what I got in my x and y axes.

I need it to be

```
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
```

Can you please tell me if I did it correctly?

Also have a question regarding

```
abs_spec = abs(spectrum) [0:int(frame_size/2):]
```

which was meant to be to use for cancelling imaginary numbers.

Or should I have done just the step 2:

```
abs_spec = abs(spectrum) [0:frame_size: 2]
```

Source: Python Questions