【问题标题】:Why is the Octave conv() giving result different from manual convolution of two signals?为什么 Octave conv() 给出的结果与两个信号的手动卷积不同?
【发布时间】:2019-09-02 06:25:16
【问题描述】:

我正在尝试在 Octave 中编写自己的代码,以对两个离散信号进行卷积。但是当我将输出与内置的conv() 函数进行比较时,结果就不同了。我究竟做错了什么?这是我的代码:

clc; clear; close all;
[h, fs] = audioread('sound_h.wav');
h = h(1:10000,1);
[x, fs] = audioread('sound_x.wav');
x = x(1:50000,1);
subplot(4, 1, 1)
plot(x);
title("x[n]");
subplot(4, 1, 2)
plot(h);
title("h[n]");
flip_h = fliplr(h);
len_h = length(h);
len_x = length(x);
padded_x = [zeros(len_h-1,1);x;zeros(len_h-1,1)];
y = zeros(len_x+len_h-1,1);
for i = 1:length(y)
  y(i) = sum(padded_x(i:i+len_h-1).*flip_h);
endfor
subplot(4, 1, 3)
plot(y);
title("y[n]");
subplot(4, 1, 4)
plot(conv(h, x));
title("y[n] using conv()");

下面是图:

【问题讨论】:

  • 你为什么不用信号调试你的代码,输出是已知的。例如高斯和狄拉克
  • 顺便说一句,没有人可以运行你的代码,因为输入文件丢失了
  • @Andy 你可以使用任何文件。它的剧照给出不同的输出。我的代码是否正确
  • 您应该始终尝试生成一个 MCVE,这在您的情况下非常容易。因为你是在要求别人花费他们宝贵的时间,你的兴趣应该是让别人尽可能容易地帮助你。
  • 什么是 mcve?

标签: signal-processing octave convolution


【解决方案1】:

线

flip_h = fliplr(h);

什么都不做,因为

h = h(1:10000,1);

是一个列向量。在这种情况下,您需要使用flipud

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    相关资源
    最近更新 更多