Clear Filters
Clear Filters

change signal frequency by known freq step

4 views (last 30 days)
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!

Accepted Answer

Mathieu NOE
Mathieu NOE on 1 Feb 2023
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);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!