change signal frequency by known freq step

11 ビュー (過去 30 日間)
LO
LO 2023 年 2 月 1 日
コメント済み: Mathieu NOE 2023 年 2 月 1 日
Hi everyone, I would like to shift the frequency of raw sinewave data (around 600 Hz and recorded at sampling freq of 20kHz) of a given frequency step (say 50 Hz). I saw already this question somewhere else but somehow I haven't found a satisfactory answer. Is there a simple (perhaps recent) MATLAB function that could do that? it seems a pretty straightforward task to me but... I haven't been lucky so far.
Thank you for any tip!

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 2 月 1 日
hello
try this
I assumed you wanted the output signal also sampled at 20 kHz
% create some dummy data (as it if was a record)
Fs = 20e3;
dt = 1/Fs;
samples = 1e3;
f1 = 600;
% data you would get from a record at Fs = 20 kHz
t1 = dt*(0:samples-1);
y1 = sin(2*pi*f1*t1);
dt1 = mean(diff(t1));
Fs = 1/dt1;
% freq shift for output signal
f2 = f1+50;
f_ratio = f1/f2; % freqs ratio
dt2 = dt1*f_ratio;
tmp = dt2*(0:samples-1); % time compression (at iso samples signal length)
% resample the data at 20 kHz
t2 = (tmp(1):dt1:tmp(end));
y2 = interp1(tmp,y1,t2,'linear');
plot(t1,y1,t2,y2);
  2 件のコメント
LO
LO 2023 年 2 月 1 日
thanks! :)
Mathieu NOE
Mathieu NOE 2023 年 2 月 1 日
My pleasure !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by