change signal frequency by known freq step

조회 수: 5 (최근 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 CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by