[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I increase/decrease (frequency/pitch) and phase using fft/if
From: |
Sergei Steshenko |
Subject: |
Re: How can I increase/decrease (frequency/pitch) and phase using fft/ifft tia sal22 |
Date: |
Fri, 8 Apr 2011 00:15:48 -0700 (PDT) |
--- On Thu, 4/7/11, Rick T <address@hidden> wrote:
From: Rick T <address@hidden>
Subject: Re: How can I increase/decrease (frequency/pitch) and phase using
fft/ifft tia sal22
To: address@hidden
Date: Thursday, April 7, 2011, 7:43 AM
Greetings All
I went back and did what Sergei recommend 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 link below. 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
correctly? I could just delete everything after 1000 but I'm not sure if this
is a bug or just the way resample/repmat works. PS: I'm using octave 3.2.4
http://dl.dropbox.com/u/6576402/questions/rows_different.png
Here's the test code I used to test this
#yiv21956316 p, #yiv21956316 li {white-space:pre-wrap;}
%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)])
On Mon, Apr 4, 2011 at 1:17 PM, Sergei Steshenko <address@hidden> wrote:
--- On Mon, 4/4/11, Rick T <address@hidden> wrote:
From: Rick T <address@hidden>
Subject: Re: How can I increase/decrease (frequency/pitch) and phase using
fft/ifft tia sal22
To: "Sergei Steshenko" <address@hidden>
Cc: address@hidden
Date: Monday, April 4, 2011, 3:37 PM
I need fft/ifft due to the fact that I have to alter various cells in the array
the signal is stored in (in the frequency domain. The script is very long. In
my experience if you post hundreds of lines of code people will not look at it.
That's why I kept it simple and basic. And asked How can I increase/decrease
(frequency/pitch) and phase using fft/ifft.
PS: Unfortunately Sergei the nice solution you sent won't work, I'm dealing
with large arrays that are exported back out as audio files and fft/ifft seems
to be the fastest.
On Mon, Apr 4, 2011 at 11:33 AM, Sergei Steshenko <address@hidden> wrote:
--- On Mon, 4/4/11, Rick T <address@hidden> wrote:
From: Rick T <address@hidden>
Subject: How can I increase/decrease (frequency/pitch) and phase using fft/ifft
tia sal22
To: address@hidden
Date: Monday, April 4, 2011, 2:11 PM
How can I increase/decrease (frequency/pitch) and phase using fft/ifft
I think I have the basic code but I’m not sure what to do next
PS: Thanks for the help on the last question everyone I decided not to use the
FOR loop and sin/cos values and just use fft/ifft
to see if this will work.
Example I have a signal that repeats 1 time every second and I want to
have it repeat 3 times a second instead.
%Voiceprint raise lower freq phase conjugate signal
tic
clear all, clc,clf,tic
%% Sound /beep calculation complete
filerawbeepStr='calculations_complete.wav';
filerawbeeppathStr='/home/rat/Documents/octave/raw/';
filevoiceprepathStr='/home/rat/Documents/octave/eq_research/main/
transform/voice/';
filewavpathStr='/home/rat/Documents/octave/eq_research/main/transform/
wav/';
[ybeep, Fsbeep, nbitsbeep] =
wavread(strcat(filerawbeeppathStr,filerawbeepStr));
%addpath(”/home/rat/Documents/octave/eq_research/main/transform/”);
%add path to location of functions
%1a voice print import
[vp_sig_orig, fs_rate, nbitsraw] =
wavread(strcat(filevoiceprepathStr,'voice8000fs.wav'));
%vp_sig_orig=vp_sig_orig’;
vp_sig_len=length(vp_sig_orig);
%2a create frequency domain
ya_fft = fft(vp_sig_orig);
vp_sig_phase_orig = unwrap(angle(ya_fft));
%get Magnitude
ya_fft_mag = abs(ya_fft);
%3a frequency back to time domain
ya_ifft=real(ifft(ya_fft));
%adjust frequency/phase here? How?
vp_sig_new=real(ifft(ya_fft_mag.*exp(i*vp_sig_phase_orig)));
subplot(3,1,1), plot(vp_sig_orig),title('1 original time domain')
subplot(3,1,2), plot(ya_ifft),title('2 rebuild time domain')
subplot(3,1,3), plot(vp_sig_new),title('3 adjusted time')
-----Inline Attachment Follows-----
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave
So, regarding your
"
Example I have a signal that repeats 1 time every second and I want to
have it repeat 3 times a second instead.
"
- why do you need FFT in the first place ?
I.e. if 'x' is your signal, why not simply write
x = linspace(0, 1, 10); % or whatever other way to generate your signal
y = [x x x]; % repeat x 3 times
plot(y);
?
Regards,
Sergei.
--
Sorry, but this is mostly nonsense. FFT can't be faster than just moving
data in memory - the latter is my solution.
If your audio comes in frequency domain, then by just _one_ 'ifft' you
convert it into time domain, and then my solution works.
You have already been given a link to 'resample' function.
You appear not to understand fundamental things regarding pitch shift. If
your signal gets repeated a number of times, it is not pitch shift.
Pitch shift does not imply signal repetitions and does not imply change
of number of output samples.
AFAIK pitch shift is implemented through overlapping relatively (compared
to the length of the whole musical piece) short FFTs, and the spectrum is
shifted (rather, scaled - you typically need all spectral componenets to be
multiplied by the same factor) in order to achieve pitch shift - number of
samples, as I said, does _not_ change.
Start from http://en.wikipedia.org/wiki/Audio_timescale-pitch_modification ->
http://en.wikipedia.org/wiki/Audio_timescale-pitch_modification#Pitch_scaling .
Regards,
Sergei.
-----Inline Attachment Follows-----
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave
I do not know the exact cause, but this:
t=0:Ts:1-Ts; %sampling period
line is silently wrong. Start from _carefully_ reading
http://en.wikipedia.org/wiki/Floating_point
http://en.wikipedia.org/wiki/Radix
.
Pay attention to:
1) periodic vs non-periodic fractions ->
2) inevitable loss of precision due to periodic fractions anywhere in the
chain of your calculations.
Bear in mind that in modern computers working in _binary_ radix many
"typical" decimal fractions which are non-periodic in decimal become
periodic in binary.
...
I do not know why you want to implement pitch shift yourself. There are
already a number of FOSS implementations. For example, visit
sox.sf.net
, read the manual, pay special attention to 'bend' under
Supported Effects
.
SoX is a _very_ powerful tool, but requires careful reading of its
manpages.
IIRC, 'alsaplayer' has pitch shifting too. Maybe also a 'gstreamer'
plugin.
...
FWIW, 'octave' has 'wavwrite' and 'wavread' functions, and SoX, of course,
supports WAV files (as well as other already mentioned candidates). So
if you need pitch shift as a piece of otherwise 'octave'-based flow, there
is no problem using an external tool doing the pitch shift part of the
flow.
Regards,
Sergei.