High-Pass Filter Pytorch

username: vin
cooked: <p>While trying to preprocess the signal, it shows this error <code>TypeError: torch.Size() takes an iterable of 'int' (item 0 is 'tuple')</code> . However, I’m using PyTorch for audio preprocessing, and want to apply the <code>High-Pass Filter</code> over the entire load signals. The below code is my current try with PyTorch. Hence, how can I use the <code>High-Pass filter</code> with PyTorch? my signals shape is <code>torch.Size([30, 100, 100])</code> , each signal shape is <code>torch.Size([1, 100, 100])</code> . Here is my code:</p>
<pre><code class="lang-auto">import torch
from load_data import AudioRead
from scipy import signal


SAMPLE_RATE = 48000
CARRIER_FREQUENCY = 18000
BOTTOM_FREQUENCY = 19000
TOP_FREQUENCY = 17000
CUT_OFF = 5
BANDWITH = BOTTOM_FREQUENCY - TOP_FREQUENCY


def high_pass_filter(signal_data, cut_off, sample_rate, carrier_frequency, bandwith):
    """
    Based DSP for audio signal processing
    :return:
    :rtype:
    """

    [b, a] = torch.FloatTensor(signal.butter(cut_off, (carrier_frequency - bandwith/2) / (sample_rate/2), 'high'))
    signal_size = torch.Size(signal_data)
    for ii in range(1, len(signal_size)):
        if signal_data != 0:
            signal_data[ii] = filter([b, a, signal_data[ii, :]])
        else:
            raise ValueError("Signals are not iterable. Null !!!!")
    return b, a


if __name__ == '__main__':
    path_dir = r"D:\ACG-Data\acg"
    ANNOTATION_FILE = r"D:\ACG-Data\acg\training_rate.csv"
    TRANSFORMATION = None
    SAMPLE_RATE = 48000
    REAL_SAMPLE_RATE = 48000

    if torch.cuda.is_available():
        DEVICE = 'cuda'
    else:
        DEVICE = 'cpu'

    data_load = AudioRead(ANNOTATION_FILE, path_dir, 
    TRANSFORMATION, SAMPLE_RATE, 
     REAL_SAMPLE_RATE, DEVICE)

    high_pass_filter(data_load, CUT_OFF, SAMPLE_RATE, CARRIER_FREQUENCY, BANDWITH)
</code></pre>
<p>Error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/a/5a96ffa941948b7ae56d17a6171857f3a8e42970.png" data-download-href="https://discuss.pytorch.org/uploads/default/5a96ffa941948b7ae56d17a6171857f3a8e42970" title="77"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a96ffa941948b7ae56d17a6171857f3a8e42970_2_690x95.png" alt="77" data-base62-sha1="cVou6jeL13qMZfgHDYtxHzVbzjO" width="690" height="95" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a96ffa941948b7ae56d17a6171857f3a8e42970_2_690x95.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a96ffa941948b7ae56d17a6171857f3a8e42970_2_1035x142.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a96ffa941948b7ae56d17a6171857f3a8e42970_2_1380x190.png 2x" data-dominant-color="312F33"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">77</span><span class="informations">1653×229 35.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: InnovArul
cooked: <aside class="quote no-group" data-username="vin" data-post="1" data-topic="150110">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/v/a87d85/48.png" class="avatar"> vin:</div>
<blockquote>
<p><code>torch.Size(signal_data)</code></p>
</blockquote>
</aside>
<p>The usage of <code>torch.Size()</code> is wrong.<br>
If you want to get the shape of a tensor, use <code>tensor.size()</code> or <code>tensor.shape</code>.</p>

username: vin
cooked: <p>Thanks Sr for your attention. I have change to:</p>
<pre><code class="lang-auto">[b, a] = torch.FloatTensor(signal.butter(cut_off, (carrier_frequency - bandwith/2) / (sample_rate/2), 'high'))
    signal_size = signal_data.size()
    for ii in range(1, len(signal_size)):
        if signal_data != 0:
            signal_data[ii] = filter([b, a, signal_data[ii, :]])
        else:
            raise ValueError("Signals are not iterable. Null !!!!")
    return b, a
</code></pre>
<p>but shows this error: <code>AttributeError: 'AudioRead' object has no attribute 'size'</code>. <code>AudioRead</code> is the Dataset converted in tensor after some examination. How can I make the HP match with my dataset. Or, should I first consider the the data in numpy shape before convert to tensor? delete the <code>torch.FloatTensor()</code>?</p>
<p>Error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/1/b14c7fff3cf23b420384c5a5d859f78f42d87eeb.png" data-download-href="https://discuss.pytorch.org/uploads/default/b14c7fff3cf23b420384c5a5d859f78f42d87eeb" title="88"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b14c7fff3cf23b420384c5a5d859f78f42d87eeb_2_690x99.png" alt="88" data-base62-sha1="pispAzbiY4yyH9pfdUjlMGqAnnZ" width="690" height="99" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b14c7fff3cf23b420384c5a5d859f78f42d87eeb_2_690x99.png, https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b14c7fff3cf23b420384c5a5d859f78f42d87eeb_2_1035x148.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b14c7fff3cf23b420384c5a5d859f78f42d87eeb_2_1380x198.png 2x" data-dominant-color="302F31"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">88</span><span class="informations">2132×308 53 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: InnovArul
cooked: <aside class="quote no-group" data-username="vin" data-post="1" data-topic="150110">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/v/a87d85/48.png" class="avatar"> vin:</div>
<blockquote>
<p><code>from load_data import AudioRead</code></p>
</blockquote>
</aside>
<p>As I understand, <code>AudioRead</code> is a class or function from the <code>load_data</code> module.<br>
You have to call <code>.size()</code> on tensor data.</p>

username: vin
cooked: <p>AudioRead is a class</p>

username: vin
cooked: <p>While my <code>AudioREad</code> dataset is a tensor, I’m getting an array shape with a tensor. I want to maintain the shape of my data into tensor format to interact with the neural network. How to transform into tensor only, already the <code>tensor.from_numpy() </code> doesn’t work in this case.</p>
<p>Here my code</p>
<pre><code class="lang-auto">def high_pass_filter(signal_data, cut_off, sample_rate, order=5):

 
    nyquist = 0.5 * sample_rate
    normal_cutoff = cut_off / nyquist
    [b, a] = (signal.butter(order, normal_cutoff, btype='high', analog=False))
    signal_data = (signal.freqs(b, a, signal_data))
    print("les donnes de w+", signal_data)
    return signal_data
</code></pre>
<p>Why this error : <code>ary = asanyarray(ary)</code></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/e/5e577d531d5c7168b5fcafae333be525b68833b9.png" data-download-href="https://discuss.pytorch.org/uploads/default/5e577d531d5c7168b5fcafae333be525b68833b9" title="99"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/e/5e577d531d5c7168b5fcafae333be525b68833b9_2_690x130.png" alt="99" data-base62-sha1="dsAkjKfCtxSWaZrQrEiGU8vB8V3" width="690" height="130" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/e/5e577d531d5c7168b5fcafae333be525b68833b9_2_690x130.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/e/5e577d531d5c7168b5fcafae333be525b68833b9_2_1035x195.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/e/5e577d531d5c7168b5fcafae333be525b68833b9.png 2x" data-dominant-color="2E3034"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">99</span><span class="informations">1250×237 27.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>