逆向频谱图在MATLAB中的La Aphex Twin
问题描述:
我正试图将图像转换为音频信号,将其视为谱图as in Aphex Twin's song on Windowlicker。不幸的是,我无法获得结果。逆向频谱图在MATLAB中的La Aphex Twin
这是我目前所面对的:
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
答
还有一些小的误解在这里。
我会经历的问题,以便发生的,而不是严重程度:
1)差一错误在spectrogramWindow(图像)的计算
第一阵列条目应该是0Hz的分量,下一个是N Hz。数组的最后一个元素应该是-NHz的组成部分。但是,你已经计算出0Hz。
我不确定matlab语法,但是如果您翻转图像,然后在将其添加到原始图像之前剥下顶部和底部线条,则应该进行设置。
或者,您可以考虑不将图像附加到自身,并从图像中提取spectrogramWindow后,应用一些函数使其成为厄米特对称。
2)取IFT的绝对值。没必要。不要这样做。
如果iFFT获得正确的输入,您从iFFT获得的东西是完全真实的。
您正在看到复杂的值,因为输入不是实际的厄米特对称,如上所述。永远不要使用Abs()。如果您必须作弊,请提取Real部分,该部分不会从虚构部分折叠成垃圾。
3)你扔掉信号的后半部分。
从iFFT获得输出后,代表您要求的信号。不要在频率上考虑它,现在它是一个音频时间序列。保持整个事情。
以下是我看到它:
spectrogramWindow = image(:, i);
spectrogramWindow = [spectrogramWindow;reverse(spectrogramWindow(skip first and last))]
signalWindow = ifft(spectrogramWindow);
signal = [signal; signalWindow];
那么,究竟是什么问题呢? – gnovice 2009-08-05 03:24:37
在回来的路上,图像的上半部分被有效地丢失了,并且可怕的东西仍然会留下污迹。 – 2009-08-05 03:33:53