# ValueError: highpass frequency \[-0.5 0.4975 ...\] must be greater than zero

**URL:** <https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012>\
**Category:** Support & Discussions\
**Tags:** time-frequency, preprocessing, eeg, visualization\
**Created:** [November 23, 2021, 2:51pm UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012 "2021-11-23T14:51:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PauloKanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/paulokanda/32/642_2.png) [@PauloKanda](https://mne.discourse.group/u/PauloKanda)\
**Post date:** [November 23, 2021, 2:51pm UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012/1 "2021-11-23T14:51:53Z")

</div>

Dear Colleagues

I’m trying to plot a “normal” rest EEG edf file:

```python
raw.filter(l_freq=0.5, h_freq=None)
raw.filter(0.5, 50)
notches = np.arange(60)
raw.notch_filter(notches, phase='zero-double', fir_design='firwin2')

```

The problem is the last line. With it I have the above error, without it, the plot is all right. Any hint? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 23, 2021, 3:10pm UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012/2 "2021-11-23T15:10:33Z")

</div>

`np.arange(60)` is not valid for notches. It returns the frequencies:

```python
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
       51, 52, 53, 54, 55, 56, 57, 58, 59])

```

And the first one, 0 is raising.

What you usually want to do is filter at 60 Hz (+ eventually 120, 180 Hz). For 60 only, you could use:

```python
np.arange(60, 61, 60)
Out[68]: array([60])

```

For 60 and 120, you could use:

```python
np.arange(60, 121, 60)

```

The syntax is `np.arange(start, stop (excluded! which is why +1), step)`.

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [November 23, 2021, 4:45pm UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012/3 "2021-11-23T16:45:14Z")

</div>

A useful idiom I often use is

```python
notches = np.arange(1, 4) * 60

```

where `60` is your local AC line frequency (50 in parts of Europe I think?). The args `(1, 4)` will yield three notches, so here 60, 120, 180. Same result as @mscheltienne but might be easier to understand if you’re less familiar with `arange`'s `step` parameter.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 23, 2021, 6:28pm UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012/4 "2021-11-23T18:28:56Z")

</div>

Looks simpler!  
Yes, 50 Hz powerline in Europe.

---

<div class="post-metadata">

**Author:** ![PauloKanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/paulokanda/32/642_2.png) [@PauloKanda](https://mne.discourse.group/u/PauloKanda)\
**Post date:** [November 24, 2021, 1:49am UTC](https://mne.discourse.group/t/valueerror-highpass-frequency-0-5-0-4975-must-be-greater-than-zero/4012/5 "2021-11-24T01:49:04Z")

</div>

Thank you. Perfect!!

[https://mne.tools/0.21/auto\_examples/time\_frequency/plot\_compute\_raw\_data\_spectrum.html](https://mne.tools/0.21/auto_examples/time_frequency/plot_compute_raw_data_spectrum.html)

```python
Just for EEG raw:

# In []:

# Pick MEG magnetometers in the Left-temporal region
# selection = read_selection('Left-temporal')
picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=False,
                       stim=False, exclude='bads') #, selection=selection)

# Let's just look at the first few channels for demonstration purposes
picks = picks[0:19]

plt.figure()
ax = plt.axes()
raw.plot_psd(tmin=tmin, tmax=tmax, fmin=fmin, fmax=fmax, n_fft=n_fft,
             n_jobs=1, proj=False, ax=ax, color=(0, 0, 1), picks=picks,
             show=False, average=True)

raw.plot_psd(tmin=tmin, tmax=tmax, fmin=fmin, fmax=fmax, n_fft=n_fft,
             n_jobs=1, proj=True, ax=ax, color=(0, 1, 0), picks=picks,
             show=False, average=True)

# And now do the same with SSP + notch filtering
# Pick all channels for notch since the SSP projection mixes channels together
raw.notch_filter(np.arange(60, 61, 60), n_jobs=1, fir_design='firwin')
raw.plot_psd(tmin=tmin, tmax=tmax, fmin=fmin, fmax=fmax, n_fft=n_fft,
             n_jobs=1, proj=True, ax=ax, color=(1, 0, 0), picks=picks,
             show=False, average=True)

ax.set_title('Twenty Channels EEG Raw')
plt.legend(ax.lines[::3], ['Without SSP', 'With SSP', 'SSP + Notch'])

![image|617x500](upload://xFhFuy0u61d6SwN4jpqTdqvI4RW.png)
```
