Changing the frequency of an array does not work always

1 回表示 (過去 30 日間)
farzad
farzad 2020 年 11 月 27 日
コメント済み: farzad 2020 年 11 月 28 日
Hi All
I have a time array , from which I first drop some elements, then change its frequency based on the input I give. the array is X in the code. what happens is that for some specific values , like reduction = 2 and freq = 1000 Hz if the original frequency of X was 512 Hz, the length of redt2 falls one element shorter than the original X array. how does this happen and what is the solution.
X is any time signal, 1D array with any length and frequency
reduction =2
X =X (1:reduction:numel(X));
redt1=[X];
rf= redt1(2)-redt1(1);
tend=redt1(numel(redt1));
freq= input(frequency)
dt= 1/freq
redt2= 0:dt:tend/rf/freq;
  8 件のコメント
farzad
farzad 2020 年 11 月 28 日
So, could you please help me out?
farzad
farzad 2020 年 11 月 28 日
Does it happen for you

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 11 月 28 日
In
freq= input(frequency)
what is frequency? Some string you defined to ask the user for the frequency? Please show how you defined it.
reduction = 2
X_Original = 1 : 1000;
whos X
samplingFreqOriginal = (X_Original(end) - X_Original(1)) / numel(X_Original)
X_Reduced = X_Original(1:reduction:numel(X_Original));
whos X
samplingFreqReduced = (X_Reduced(end) - X_Reduced(1)) / numel(X_Reduced) % Will be 2 times samplingFreqOriginal
% Not sure what anything after here is intended to do.
redt1 = X_Reduced;
rf = redt1(2) - redt1(1)
tend = redt1(numel(redt1))
frequency = 'Enter the frequency : ';
freq = input(frequency)
dt = 1 / freq
redt2 = 0:dt:tend/rf/freq;
  9 件のコメント
Image Analyst
Image Analyst 2020 年 11 月 28 日
Then simply do
% Sample values:
startingValue = 1
deltaX = 3
numElements = 9
% Create array:
x = startingValue : deltaX : (startingValue + (numElements - 1) * deltaX)
fprintf('x is %d elements long.\n', length(x));
farzad
farzad 2020 年 11 月 28 日
Thank you Very MUCH !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by