I just started learning msp, I wanted to see what does the cycle~ output, so I patch it to the number~ and print out all those momentary values. they are all float numbers jumping between -1 and 1. The help doc says it is signal value, but what signal value exactly? like the amplitude?
The values of the number~ outputs:
A signal consists of 44100 values per second, and number~ outputs only 10 of these values per second.
So the values you are seeing are snapshots of the output of cycle~, which produces a sine wave, but a very fast one, 301 periods per second in your example. So the values you see will not seem to form a pattern.
More info can be found in the docs.
Tip: if you change the frequency of cycle~ in your example to say 1 instead of 301, you will notice the sine pattern in the printed output.
Related
I am using Apple's Accelerate Framework, vDSP biquad function https://developer.apple.com/documentation/accelerate/1450838-vdsp_biquad?language=objc#parameters in order to emulate pythons sosfilt function. I have done all the filtering but notice I have transient signals that I am trying to remove. In python, this is done with finding the initial conditions from sosfilt_zi https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.sosfilt_zi.html#scipy.signal.sosfilt_zi and multiplying by the first element in the data that is being filtered. I followed this amazing example Matlab filtfilt() function implementation in Java.
When I print out the initial conditions in python using sosfilt_zi, I am getting two values for each section (I'm using a second-order cascade) so I have four values in total.
However in the single channel biquad function for iOS, they are asking for (2*M)+2 for the Delay. I was assuming that the initial conditions are related to the Delay and that this is what I would need to change in order to adjust my signal and remove the transient.
The function definition for the Delay Parameter for the biquad function in iOS is " An array of single-precision values initialized with direct-form 1 “past” state data for each section of the biquad. The length of the array should be (2 * M) + 2, where M is the number of sections. For each section m, Delay[2m:2m+1] represent the two delayed input values for section m and Delay[2M:2M+1] represent the two delayed output values of the filter. After this function executes, this array contains the final state data of the filters."
If I have 2 sections, then my delay array should look like :
[0:1] - input delay value for section 0
[2:3] - input delay value for section 1
[4:5] - output delay value
I initially had the Delay set to an array of 6 zeros. If the output of sosfilt_zi would be the proper values for the two input sections of the Delay, then how could I find the delayed output values of the filter?
Is anyone familiar with vDSP and able to remove transient signals or can explain how to adjust the Delay values for a cascaded second-order sections? Is adjusting the Delay values the correct move and how could I get these values in python?
I was thinking that my delay array would look like (using values shown in second link below):
[0.72095219 -0.28358224] - section 0
[-0.80004591 0.80004591] - section 1
However, I don't know what that output would be if this is even correct. I'd appreciate any help! I've found really little documentation or examples on the iOS biquad function. Thank you!
Butterworth Bandpass filter - Initial Conditions is being applied
Output of sosfilt_zi - gives inital conditions
Result of Biquad Filter from iOS vDSP on top and result of sosfilt with initial conditions on bottom
Delays being initialized
Biquad Function
First of all, I am sorry if I am a dummy and cant understand this part of an article. I have a set of data with 200 channels in which every specific two channels are co-dependent. In the paper it is mentioned:
"
For each channel, we filtered both signals
between 0.5 and 2.5 Hz to preserve only the cardiac component and
normalized the resulting signals to balance any difference between
their amplitude.
"
Question1: this means I need to normalize both co-dependent channels to the average of the median? or just normalize each signal to its own median?
Here is the rest of the paragraph
"
Then, we computed the cross-correlation
extracted the value at a time lag of 0 to quantify the similarity
between the filtered signals. In-phase and counter-phase identical
waveforms yielded a zero-lag cross-correlation value of 1 and -1
respectively, whereas a null value derived from totally uncorrelated
signals. "
I wrote the code below: but I get -1 or plus one everywhere even for signals that are not codependent it gives me 1 or -1. I guess I am wrong in part of the code but rationally I don't know where. Here is the code
datafile='data_sess_03.nirs'
ch_num=1
[w,src,det,mlOrg,mlo,mlm,Data,datap,acc1,acc2]=readData(datafile);
fc=[0.5 2.5];
dataf=filterData(Data,fc);
[c,lags]=xcorr(dataf(1,:),dataf(5,:),0); % channel 1 and 5 are
codependent
%% c is -1 and plus one every when even in the noisy channels
plot(acor,'black')
[~,I] = max(abs(acor));
lagDiff = lag(I)/fs
Any help will be really appreciated. Thanks a lot to help me
I have a distance sensor (acoustic) that has temperature-dependent noise signal. I want to retain the peaks, but get rid of the temperature related noise.
I need a program that checks the absolute value of the difference between the current and previous measurement (e.g. abs(d1[i+1]-d1[i])). If the difference is less than or equal to a threshold (delta), then d2[i+1] = d1[i]. If the difference is greater than delta, then d2[i+1]=d1[i+1]. An example vector looks something like:
data vector d1 is 4,6,5,7,6,5,7,10,55,56,58,30,10
The desired, filtered data (d2) would look something like (in this case delta=1): 4,6,6,7,7,7,7,10,55,55,58,30,10
I looked at lowess() and sma(), but they were unsatisfactory, or my ability to apply them correctly is unsatisfactory. I have used lowess in previous attempts, but it was inconsistent in capturing peaks and valleys. It seems a combination of sapply() and an ifelse() function should be able to do this, but my skill level is too poor. Any help would be most appreciated.
I would like to ask the following: I have a row vector, let’s say v, which is actually a bit sequence which length 400 comprised of the concatenation of 40 sequences of length 10 where each one is eiter an all-ones sequence (i.e. 1111111111) or an all-zeros sequence (i.e. 0000000000). That is, this vector is something like [0000000000111111111111111111110000000000111111111100000000000000000000.........].
Now I want from this vector to geneate a Continuous-Time waveform, that is, as long as the value is 0, the value will be ketp to zero, when it goes to 1, the value of the waveform will also go to one and so on.
Any thought how I could do that?
It was actually easier than what I was originally thinking. I just multiplied the vecot by 1. This did the job!
In a spectrogram, I have a set of harmonic frequencies (peaks in the spectrum) for a given time frame:
5215
3008.1
2428.1
2214.9
1630.2
1315
997.01
881.39
779.04
667.47
554.21
445.77
336.39
237.69
124.6
If I do -diff(ans), I get the differences between the formants, which hint me to the fact that the fundamental frequency f_0 of this frame is around 110 Hz:
2206.9
580.06
213.11
584.72
315.24
317.97
115.62
102.35
111.57
113.26
108.44
109.38
98.705
113.08
It is clear that the last 9 values of the first list are harmonics of the same f_0, because the last 8 values of the second list are around the same value. Their mean is 109.05 (but I'm not sure if that is the correct f_0). How can I calculate f_0 in a neat function?
I found an answer myself: I calculate the difference between the two peaks with the lowest frequency values and with energy values above a certain threshold. Then, I check if that difference is (within a certain range) in the list of frequencies.