フーリエ逆変換(if​ft)した時間領域の​データの時間範囲を変​える方法を教えてくだ​さい

조회 수: 9 (최근 30일)
K_S_
K_S_ 2024년 2월 8일
답변: COVAO 2024년 3월 7일
フーリエ変換・フーリエ逆変換 初心者です。
周波数領域で波形を作り,それをフーリエ逆変換(ifft)して時間領域のデータを得たいと考えています。
下記のコードを作成しましたが,フーリエ逆変換後の時間領域の範囲が0から1になります。
0から0.1や0から10のように変更するにはどうすればよいでしょうか?
% パラメータの設定
fs = 20e3; % サンプリング周波数 (Hz)
T = 1/fs; % サンプリング間隔
f_center = 10e3; % 中心周波数 (Hz)
f_width = 2e3; % 三角形の底辺の幅 (Hz)
desired_amplitude = 100; % 望ましいピークの振幅
% 周波数領域での振幅スペクトルの生成
frequencies = linspace(0, fs, fs); % 0からサンプリング周波数までの周波数を生成
amplitude_spectrum = zeros(1, fs);
% 二等辺三角形の周波数分布を生成
amplitude_spectrum(abs(frequencies - f_center) <= f_width/2) = desired_amplitude * (1 - 2 * abs((frequencies(abs(frequencies - f_center) <= f_width/2) - f_center) / f_width));
% 時間領域での波形を逆FFT変換
time_domain_signal = ifft(amplitude_spectrum);
% 逆FFT結果の実部をFFTしてプロット
fft_result = fft(real(time_domain_signal));
% 波形のプロット
figure;
subplot(3,1,1);
plot(frequencies, amplitude_spectrum);
title('Amplitude Spectrum');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(3,1,2);
t = 0:T:(length(time_domain_signal)-1)*T;
plot(t, real(time_domain_signal));
title('Time Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% 逆FFT結果の実部のFFTのプロット
subplot(3,1,3);
frequencies_fft = linspace(0, fs, length(fft_result));
plot(frequencies_fft, abs(fft_result));
title('FFT of Real Part of Time Domain Signal');
xlabel('Frequency (Hz)');
ylabel('Amplitude');

답변 (1개)

COVAO
COVAO 2024년 3월 7일
時間領域での波形が0から1の範囲になる原因は、tの計算方法にあります。
時間領域のデータの範囲を0から0.1や0から10のように変更するには、波形の長さ(サンプル数)とサンプリング間隔(サンプリング周波数)を適切に設定する必要があります。
時間範囲を0から0.1秒にしたい場合は、サンプリング周波数と時間範囲から必要なサンプル数を計算します。
n_samples = fs * time_range
例えば、0.1秒間に20kHzでサンプリングすると、0.1 * 20e3 = 2000サンプルが必要です。
以下、修正例です。(コードの修正に生成AIを用いています)
% Parameter settings
fs = 20e3; % Sampling frequency (Hz)
T = 1/fs; % Sampling interval
f_center = 10e3; % Center frequency (Hz)
f_width = 2e3; % Width of the base of the triangle (Hz)
desired_amplitude = 100; % Desired peak amplitude
% Setting the time range and number of samples
time_range = 0.1; % Setting the time range from 0 to 0.1 seconds
n_samples = fs * time_range; % Calculating the required number of samples
% Generating the amplitude spectrum in the frequency domain
frequencies = linspace(0, fs, n_samples); % Generating frequencies from 0 to the sampling frequency, adjusted for the number of samples
amplitude_spectrum = zeros(1, n_samples); % Adjusting the zero vector for the number of samples
% Generating a triangular frequency distribution
triangle_index = abs(frequencies - f_center) <= f_width/2;
amplitude_spectrum(triangle_index) = desired_amplitude * (1 - 2 * abs((frequencies(triangle_index) - f_center) / f_width));
% Inverse FFT to transform into the time domain
time_domain_signal = ifft(amplitude_spectrum, 'symmetric'); % Using 'symmetric' option to ensure the signal is real
% FFT of the real part of the time-domain signal
fft_result = fft(real(time_domain_signal));
% Plotting the waveforms
figure;
subplot(3,1,1);
plot(frequencies, amplitude_spectrum);
title('Amplitude Spectrum');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(3,1,2);
t = linspace(0, time_range, n_samples); % Adjusting the generation of the time vector
plot(t, real(time_domain_signal));
title('Time Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
frequencies_fft = linspace(0, fs, length(fft_result));
plot(frequencies_fft, abs(fft_result));
title('FFT of Real Part of Time Domain Signal');
xlabel('Frequency (Hz)');
ylabel('Amplitude');

카테고리

Help CenterFile Exchange에서 スペクトル測定에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!