필터 지우기
필터 지우기

How to plot frequency spectrum in log-log scale?

조회 수: 61 (최근 30일)
Rahul
Rahul 2023년 9월 14일
답변: Rahul 2023년 10월 30일
Hello,
I'm trying to plot a frequency spectrum for a given set of data with log scales in both axes which should scale as 10^0, 10^1,10^2........
I tried to write the code but its not generating the same.
Kindly let me know the corrections in the followint code. The data is as attached/uploaded herewith.
close all;
freq_sam = 100; % samples
period_ctrw = 0.005; % time period
freq_ctrw = 1/period_ctrw; % frequency
data_ctrw = data.variable.turbulence(:,100);
x_data = data.variable.turbulence(:,1);
y_data = data.variable.turbulence(:,100);
disp(x_data);
disp(y_data);
signal_ctrw = data_ctrw;
fft_ctrw = fft(signal_ctrw); % fourier transform
fft_ctrw = fftshift(fft_ctrw); % performing fft shift
f = freq_sam/2*linspace(-1,1,freq_sam);
figure;
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
plot(f, fft_ctrw,'.','MarkerSize',24);

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 9월 14일
If you change the scale of axes and plot the data afterwards, the scale will get modified according to the data. Better to change the scale after plotting.
Note the warnings.
load('data5a_chi1-15.mat')
freq_sam = 100; % samples
period_ctrw = 0.005; % time period
freq_ctrw = 1/period_ctrw; % frequency
data_ctrw = data.variable.turbulence(:,100);
x_data = data.variable.turbulence(:,1);
y_data = data.variable.turbulence(:,100);
%disp(x_data);
%disp(y_data);
signal_ctrw = data_ctrw;
fft_ctrw = fft(signal_ctrw); % fourier transform
fft_ctrw = fftshift(fft_ctrw); % performing fft shift
f = freq_sam/2*linspace(-1,1,freq_sam);
figure;
plot(f, fft_ctrw,'.','MarkerSize',24);
Warning: Imaginary parts of complex X and/or Y arguments ignored.
set(gca, 'XScale', 'log')
set(gca, 'YScale', 'log')
Warning: Negative data ignored

추가 답변 (1개)

Rahul
Rahul 2023년 10월 30일
Hi Dyuman Joshi,
Regarding the the above code for generating frequency spectrum, I'd like to know if it is possible to generate the profile which
looks like as attached? This type of profile is what I'm actually trying to generate. But not getting it. The data I'm using is attached herewith. Kindly let me know if possible.
Rgds

카테고리

Help CenterFile Exchange에서 Log Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by