如何在 Matlab 中生成信号的低频版本?

发布于 2024-08-05 08:14:21 字数 684 浏览 2 评论 0原文

通过正弦输入,我尝试修改它的频率,切割频谱中的一些较低频率,将主频率移向零。由于信号没有进行 fftshifted,我尝试通过消除 fft 向量开头和结尾的一些样本来做到这一点:

interval = 1;
samplingFrequency = 44100;
signalFrequency = 440;
sampleDuration = 1 / samplingFrequency;
timespan = 1 : sampleDuration : (1 + interval);
original = sin(2 * pi * signalFrequency * timespan);
fourierTransform = fft(original);
frequencyCut = 10; %% Hertz
frequencyCut = floor(frequencyCut * (length(pattern) / samplingFrequency) / 4); %% Samples
maxFrequency = length(fourierTransform) - (2 * frequencyCut);
signal = ifft(fourierTransform(frequencyCut + 1:maxFrequency), 'symmetric');

但它没有按预期工作。我还尝试去除频谱的中心部分,但它也使用了更高频率的正弦波。

怎样做才正确呢?

With a sine input, I tried to modify it's frequency cutting some lower frequencies in the spectrum, shifting the main frequency towards zero. As the signal is not fftshifted I tried to do that by eliminating some samples at the begin and at the end of the fft vector:

interval = 1;
samplingFrequency = 44100;
signalFrequency = 440;
sampleDuration = 1 / samplingFrequency;
timespan = 1 : sampleDuration : (1 + interval);
original = sin(2 * pi * signalFrequency * timespan);
fourierTransform = fft(original);
frequencyCut = 10; %% Hertz
frequencyCut = floor(frequencyCut * (length(pattern) / samplingFrequency) / 4); %% Samples
maxFrequency = length(fourierTransform) - (2 * frequencyCut);
signal = ifft(fourierTransform(frequencyCut + 1:maxFrequency), 'symmetric');

But it didn't work as expected. I also tried to remove the center part of the spectrum, but it wielded a higher frequency sine wave too.

How to make it right?

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

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

发布评论

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

评论(2

吐个泡泡 2024-08-12 08:14:21

@las3rjock:

它更像是对信号本身进行下采样,而不是 FFT。
查看downsample

或者您可以创建一个 timeseries 对象,并使用它重新采样重新采样方法。

编辑:

类似的示例:)

% generate a signal
Fs = 200;
f = 5;
t = 0:1/Fs:1-1/Fs;
y = sin(2*pi * f * t) + sin(2*pi * 2*f * t) + 0.3*randn(size(t));

% downsample
n = 2;
yy = downsample([t' y'], n);

% plot
subplot(211), plot(t,y), axis([0 1 -2 2])
subplot(212), plot(yy(:,1), yy(:,2)), axis([0 1 -2 2])

screenshot

@las3rjock:

its more like downsampling the signal itself, not the FFT..
Take a look at downsample.

Or you could create a timeseries object, and resample it using the resample method.

EDIT:

a similar example :)

% generate a signal
Fs = 200;
f = 5;
t = 0:1/Fs:1-1/Fs;
y = sin(2*pi * f * t) + sin(2*pi * 2*f * t) + 0.3*randn(size(t));

% downsample
n = 2;
yy = downsample([t' y'], n);

% plot
subplot(211), plot(t,y), axis([0 1 -2 2])
subplot(212), plot(yy(:,1), yy(:,2)), axis([0 1 -2 2])

screenshot

黄昏下泛黄的笔记 2024-08-12 08:14:21

将频谱下采样 n 的一种粗略方法是,

% downsample by a factor of 2
n = 2; % downsampling factor
newSpectrum = fourierTransform(1:n:end);

为了使其成为原始时间轴上的低频信号,您需要将此向量补零至原始长度在正极和负极两端。使用 fftshift 可以使这变得更加简单:

pad = length(fourierTransform);
fourierTransform = [zeros(1,pad/4) fftshift(newSpectrum) zeros(1,pad/4)];

要恢复降档信号,请在应用逆变换之前将 fftshift 返回:

signal = ifft(fftshift(fourierTransform));

编辑:这是一个完整的脚本,它生成一个比较原始信号和降档信号的图:

% generate original signal
interval = 1;
samplingFrequency = 44100;
signalFrequency = 440;
sampleDuration = 1 / samplingFrequency;
timespan = 1 : sampleDuration : (1 + interval);
original = sin(2 * pi * signalFrequency * timespan);

% plot original signal
subplot(211)
plot(timespan(1:1000),original(1:1000))
title('Original signal')

fourierTransform = fft(original)/length(original);

% downsample spectrum by a factor of 2
n = 2; % downsampling factor
newSpectrum = fourierTransform(1:n:end);

% zero-pad the positive and negative ends of the spectrum
pad = floor(length(fourierTransform)/4);
fourierTransform = [zeros(1,pad) fftshift(newSpectrum) zeros(1,pad)];

% inverse transform
signal = ifft(length(original)*fftshift(fourierTransform),'symmetric');

% plot the downshifted signal
subplot(212)
plot(timespan(1:1000),signal(1:1000))
title('Shifted signal')

< a href="http://img5.imageshack.us/img5/5426/downshift.png" rel="nofollow noreferrer">原始信号和降档信号图 http://img5.imageshack.us/img5/5426/downshift .png

A crude way to downsample your spectrum by a factor of n would be

% downsample by a factor of 2
n = 2; % downsampling factor
newSpectrum = fourierTransform(1:n:end);

For this to be a lower-frequency signal on your original time axis, you will need to zero-pad this vector up to the original length on both the positive and negative ends. This will be made much simpler using fftshift:

pad = length(fourierTransform);
fourierTransform = [zeros(1,pad/4) fftshift(newSpectrum) zeros(1,pad/4)];

To recover the downshifted signal, you fftshift back before applying the inverse transform:

signal = ifft(fftshift(fourierTransform));

EDIT: Here is a complete script which generates a plot comparing the original and downshifted signal:

% generate original signal
interval = 1;
samplingFrequency = 44100;
signalFrequency = 440;
sampleDuration = 1 / samplingFrequency;
timespan = 1 : sampleDuration : (1 + interval);
original = sin(2 * pi * signalFrequency * timespan);

% plot original signal
subplot(211)
plot(timespan(1:1000),original(1:1000))
title('Original signal')

fourierTransform = fft(original)/length(original);

% downsample spectrum by a factor of 2
n = 2; % downsampling factor
newSpectrum = fourierTransform(1:n:end);

% zero-pad the positive and negative ends of the spectrum
pad = floor(length(fourierTransform)/4);
fourierTransform = [zeros(1,pad) fftshift(newSpectrum) zeros(1,pad)];

% inverse transform
signal = ifft(length(original)*fftshift(fourierTransform),'symmetric');

% plot the downshifted signal
subplot(212)
plot(timespan(1:1000),signal(1:1000))
title('Shifted signal')

Plot of original and downshifted signals http://img5.imageshack.us/img5/5426/downshift.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文