MATLAB中的反频谱图A La Aphex Twin [英] Reverse Spectrogram A La Aphex Twin in MATLAB

查看:130
本文介绍了MATLAB中的反频谱图A La Aphex Twin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过将其视为频谱图 Aphex Twin在 Windowlicker 上的歌曲.不幸的是,我无法获得结果.

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.

这是我目前的状态:

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的图像处理工具箱读取图像.目的是要使

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!

编辑:谢谢Dave!我知道了!我结束了:

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

推荐答案

这里有一些小的误解.

我将按照出现的顺序而不是严重性来解决这些问题:

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

1)SpectrogramWindow(图像)的计算中出现了一次错误

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

第一个数组项应该是0Hz的分量,下一个是N Hz.数组的最后一个元素应该是-N Hz的分量.但是,您已经计算出0Hz.

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.

我不确定matlab的语法,但是如果您按原样翻转图像,然后在将其附加到原始图像之前先去除顶部和底部的线条,则应该进行设置.

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.

或者,您可以考虑不将图像附加到自身上,并且从图像中提取spectrogramWindow之后,应用一些函数使其成为厄米对称的.

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)采取IFT的腹肌.不需要.不要那样做.

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

如果iFFT得到正确的输入,您从iFFT中学到的就是完全真实的.

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

您会看到复杂的值,因为如上所述,输入实际上不是Hermitian对称的.切勿使用Abs().如果必须作弊,请提取实部",该实部不会从虚构部分折叠成垃圾.

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)您正在丢弃信号的后半部分.

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

一旦您从iFFT获得输出,它便代表了您所要求的信号.不要以频率来考虑它,它现在是一个音频时间序列.保留整个东西.

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.

这是我的看法:

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

这篇关于MATLAB中的反频谱图A La Aphex Twin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆