MATLAB 中的反向谱图 A La Aphex Twin

发布于 2024-07-30 16:43:25 字数 1633 浏览 2 评论 0原文

我试图在 MATLAB 中将图像转换为音频信号,将其视为频谱图如 Aphex Twin 的歌曲中那样在Windowlicker上。 不幸的是,我很难得到结果。

这就是我现在所拥有的:

function signal = imagetosignal(path, format)

    % Read in the image and make it symmetric.
    image = imread(path, format);
    image = [image; flipud(image)];
    [row, column] = size(image);
    signal = [];

    % Take the ifft of each column of pixels and piece together the real-valued results.
    for i = 1 : column

        spectrogramWindow = image(:, i);
        R = abs(ifft(spectrogramWindow));
        % Take only the results for the positive frequencies.
        signalWindow = R(1 : row / 2.0);
        signal = [signal; signalWindow];

    end

end

所以,我对图像的列进行傅里叶逆变换,然后将它们组合在一起形成信号。 此外,此函数使用 MATLAB 图像处理工具箱来读取图像。 目标是

spectrogram(imagetosignal('image', 'bmp'));

在看起来像原始图像的结果中产生一些变化。 我将非常感谢任何帮助! 我刚刚学习信号处理,所以如果有明显的误解,请不要感到惊讶。 谢谢!


编辑:谢谢戴夫! 我成功了! 我最终得到了这个:

function signal = imagetosignal(path, format)

    % Read in the image and make it symmetric.
    image = imread(path, format);
    image = [image; flipud(image)];
    [row, column] = size(image);
    signal = [];

    % Take the ifft of each column of pixels and piece together the results.
    for i = 1 : column

        spectrogramWindow = image(:, i);
        signalWindow = real(ifft(spectrogramWindow));
        signal = [signal; signalWindow];

    end

end

alt text

I'm trying to convert an image into an audio signal in MATLAB by treating it as a spectrogram as in Aphex Twin's song on Windowlicker. Unfortunately, I'm having trouble getting a result.

Here it what I have at the moment:

function signal = imagetosignal(path, format)

    % Read in the image and make it symmetric.
    image = imread(path, format);
    image = [image; flipud(image)];
    [row, column] = size(image);
    signal = [];

    % Take the ifft of each column of pixels and piece together the real-valued results.
    for i = 1 : column

        spectrogramWindow = image(:, i);
        R = abs(ifft(spectrogramWindow));
        % Take only the results for the positive frequencies.
        signalWindow = R(1 : row / 2.0);
        signal = [signal; signalWindow];

    end

end

So, I'm taking Inverse Fourier Transforms on columns of my image and then putting them together to form a signal. Also, this function uses the Image Processing Toolbox for MATLAB to read in images. The goal is to have some variation of

spectrogram(imagetosignal('image', 'bmp'));

result in something that looks like the original image. I would very much appreciate any help! I'm just learning signal processing, so don't be surprised if there's an obvious misconception. Thanks!


Edit: Thanks Dave! I got it working! I ended up with this:

function signal = imagetosignal(path, format)

    % Read in the image and make it symmetric.
    image = imread(path, format);
    image = [image; flipud(image)];
    [row, column] = size(image);
    signal = [];

    % Take the ifft of each column of pixels and piece together the results.
    for i = 1 : column

        spectrogramWindow = image(:, i);
        signalWindow = real(ifft(spectrogramWindow));
        signal = [signal; signalWindow];

    end

end

alt text alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨轻弹 2024-08-06 16:57:14

只是研究完全相同的事情并发现了这个 perl 脚本。 我想你可能会喜欢这个链接。

http://devrand.org/show_item.html?item=64&page=项目

Just researching the exact same thing and found this perl script. Thought you might like the link.

http://devrand.org/show_item.html?item=64&page=Project

小情绪 2024-08-06 16:54:34

这里有一些小误解。

我将按照发生的顺序而不是严重程度来解决问题:

1)spectrogramWindow(图像)计算中的逐一错误

第一个数组条目应该是 0Hz 的分量,下一个是 N Hz。 数组的最后一个元素应该是 -N Hz 的分量。 但是,您计算出的是 0Hz。

我不确定 matlab 语法,但如果您按现有方式翻转图像,然后在将其附加到原始图像之前去除顶线和底线,则应该设置好。

或者,您可以考虑不将图像附加到其自身,并在从图像中提取spectrogramWindow之后,应用一些函数使其成为埃尔米特对称。

2) 取IFT的abs。 不需要。 不要那样做。

如果 iFFT 获得正确的输入,那么从 iFFT 中得到的结果是完全真实的。

您看到的是复数值,因为输入实际上不是厄米对称的,如上所述。 切勿使用 Abs()。 如果你必须作弊,请提取实部,它不会从虚部中折叠成垃圾。

3)你丢弃了信号的后半部分。

一旦你从 iFFT 获得输出,它就代表你所要求的信号。 不要从频率的角度来思考它,它现在是一个音频时间序列。 保留整个东西。

我的看法是这样的:

spectrogramWindow = image(:, i);
spectrogramWindow = [spectrogramWindow;reverse(spectrogramWindow(skip first and last))]
signalWindow = ifft(spectrogramWindow);
signal = [signal; signalWindow];

There are some small misconceptions here.

I'll go through the problems in order of occurrence, not severity:

1) Off-by-one error in the calculation of spectrogramWindow (image)

The first array entry ought to be the component of 0Hz, the next is N Hz. The final element of the array should be the component of -N Hz. However, you've calculated 0Hz.

I'm not sure the matlab syntax, but if you flip the image as you have, and then strip the top and bottom lines before appending it to the original, you should be set.

Alternatively, you could consider NOT appending the image to itself, and after extracting spectrogramWindow from image, applying some function to make it Hermitian symmetric.

2) Taking the abs of the IFT. No need. Don't do that.

What you get out of the iFFT, if the iFFT gets the right input, is completely real.

You're seeing complex values out because the input isn't ACTUALLY Hermitian symmetric, as described above. Never use Abs(). If you must cheat, extract the Real part, which won't fold in garbage from the imaginary component.

3) You're throwing away the second half of the signal.

Once you get output from the iFFT, that represents the signal you've asked for. Don't think of it in terms of frequencies, it's now an audio time-series. Keep the whole thing.

Here's how I see it going:

spectrogramWindow = image(:, i);
spectrogramWindow = [spectrogramWindow;reverse(spectrogramWindow(skip first and last))]
signalWindow = ifft(spectrogramWindow);
signal = [signal; signalWindow];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文