How to calculate the value of (x) on xaxis in MATLAB ?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have this code in Matlab.
% Clear workspace.
clear
% Clear command window.
clc
% Close all windows.
close all
% Define the parameters.
pt1 = 2 ;
pt2 = 3.954 ;
h = 0.4 ; % wave length
dx = 1 ;
z = 30 ;
N = 10 ; % No.of samples
% Imaginary part.
j = sqrt( -1 ) ;
% Initialize the vector to store the values.
c = zeros(1, 20);
% Make for loop.
for L = 1: N
a1 = exp( j*( 2*pi/h ) * ( (L-1)*dx ) *( pt1/z ) ) ;
a2 = exp( j*( 2*pi /h ) *( (L-1)*dx ) *( pt2/z ) ) ;
c(L) = a1 + a2 ;
end
% Compute FFT.
Y = fft(c,256);
% Compute Magnitude FFT
Y1 = abs(Y);
We can see in the attached picture the value of (x=44) and so on......
My question is: What is the relationship or mathematical formula that I can use to calculate the value of (x) ?
I don't care, I just need to know the mathematical formula or equation used to calculate the value of (x)?
댓글 수: 0
답변 (2개)
the cyclist
2024년 1월 30일
How, specifically, do you want to define that point? It is not the highest peak, which is at index=85 (as shown in the last line of code I added, at the end of yours).
% Define the parameters.
pt1 = 2 ;
pt2 = 3.954 ;
h = 0.4 ; % wave length
dx = 1 ;
z = 30 ;
N = 10 ; % No.of samples
% Imaginary part.
j = sqrt( -1 ) ;
% Initialize the vector to store the values.
X = zeros(1, 20);
% Make for loop.
for L = 1: N
x1 = exp( j*( 2*pi/h ) * ( (L-1)*dx ) *( pt1/z ) ) ;
x2 = exp( j*( 2*pi /h ) *( (L-1)*dx ) *( pt2/z ) ) ;
X(L) = x1 + x2 ;
end
% Compute FFT.
Y = fft(X,256);
% Compute Magnitude FFT
Y1 = abs(Y);
% Plot it
plot(Y1)
% Max value of Y1, and its index
[maxY1,indexOfMaxY1] = max(Y1)
댓글 수: 6
the cyclist
2024년 1월 30일
It is not a mathematical formula. MATLAB is telling you that are hovering over the 44th value of Y1.
Look at this code, and my screenshot of the figure when I run it locally:
plot([5 5 8 5 5 5])
When I hover over that top data point, MATLAB reports (3,8).
There is no mathematical formula. Rather, when I use the shorthand
plot([5 5 8 5 5 5])
MATLAB is implicitly plotting
plot([1 2 3 4 5 6],[5 5 8 5 5 5 ])
So, when I hover over the point that has y=8, it tells me (x,y) = (3,8). It is using that implicit value of x. There is no mathematical formula.
Steven Lord
2024년 1월 30일
@the cyclist is correct. From the part of the Description section on the plot documentation page where it explains the plot(Y) syntax: "If Y is a vector, the x-coordinates range from 1 to length(Y)."
If you have X data associated with the Y data, call plot with two input arguments. If you do, the scale of the X axis (and the data tips) will reflect the X data you specified in your plot call. Compare:
x = [0 1.5 2 6 9];
y = x.^2;
figure
plot(y, 'o-')
% Horizontal lines at the values in x WILL NOT line up with the points
xline(x, 'r')
title('Y data alone -- X coordinates are 1:length(Y)')
figure
plot(x, y, 'o-')
% Horizontal lines at the values in x WILL line up with the points
xline(x, 'r')
title('X and Y data -- X coordinates are from the variable x')
Walter Roberson
2024년 1월 30일
Q = @(v) sym(v);
pt1 = Q(2) ;
pt2 = Q(3.954) ;
h = Q(0.4) ; % wave length
dx = Q(1) ;
z = Q(30) ;
syms L
x1 = exp( j*( 2*pi/h ) * ( (L-1)*dx ) *( pt1/z ) ) ;
x2 = exp( j*( 2*pi /h ) *( (L-1)*dx ) *( pt2/z ) ) ;
x = x1 + x2;
Y = fourier(x)
Y1 = abs(Y)
This has two instanteneous peaks, one at pi/3 and the other at 659pi/1000
참고 항목
카테고리
Help Center 및 File Exchange에서 Analog Devices ADALM1000 Support from Data Acquisition Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!