Note that there are some explanatory texts on larger screens.

plurals
  1. POInterpolating signal from 4 sec to 1 sec
    primarykey
    data
    text
    <p>I have a signal that cycles twice from 0 to 4 seconds and I would like to interpolate the signal to cycle twice when it goes from 0 to 1 second. I know it's an issue with my <code>xi</code> variable; I'm just not sure how to fix it.</p> <p>The example is just a simple sine wave equation but I'll be importing an audio wav file in the real one; that's why I chose to use interpolate. Unfortunately it can't just be a simple plot change due to the fact it will be an audio file that will be imported, some calculations done on it, then exported back out as another audio file.</p> <pre><code>%Interpolation test clear all, clc,clf,tic x= linspace(0,2*pi,400); %from 0 to 4 sec fs_rate=100 freq=2; y=sin(freq*(x)); xo=linspace(0,length(y)/fs_rate,length(y)); %go from 0 to x sec xi=linspace(0,1,length(y)); %go from 0 to 1 sec new_y=interp1(xo,y,xi,'linear'); subplot(2,2,1),plot(xo,y),title('Orginal signal over 4 sec') subplot(2,2,3),plot(xi,new_y),title('Entire signal over 1 sec') </code></pre> <hr> <p>I went back and did what Sergei recommended and used resample and repmat, but I'm noticing that on some of the values the rows aren't the same as the sample rate (see image below).</p> <p>Notice the top image value for rows says 1000 and the bottom image says rows = 1008. This happens when I change the values of resample and repmat (freq_new) but only for certain values. How can I fix this? I could just delete everything after 1000 but I'm not sure if this is a bug or just the way resample/repmat works. </p> <p><img src="https://i.stack.imgur.com/do32o.png" alt="http://dl.dropbox.com/u/6576402/questions/rows_different.png"></p> <p>Here's the code I used to test this:</p> <pre><code>%resample_repmat signal clear all, clf Fs = 1000; % Sampling rate Ts = 1/Fs; %sampling interval t=0:Ts:1-Ts; %sampling period freq_orig=1; y=sin(2*pi*t*freq_orig)'; %gives a short wave freq_new=9; y2=resample(y,1,freq_new); %resample matrix y3=repmat (y2,freq_new,1); %replicate matrix [r_orig,c_orig] = size(y) %get orig number of rows and cols [r_new,c_new] = size(y3) %get new number of rows and cols subplot(2,1,1),plot(y),title('Orginal signal') title(['rows=',num2str(r_orig),' cols=',num2str(c_orig)]) subplot(2,1,2),plot(y3),title('New signal') title(['rows=',num2str(r_new),' cols=',num2str(c_new)]) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload